Class: Berlin::AI::Node

Inherits:
Object
  • Object
show all
Includes:
Internal
Defined in:
lib/ai/node.rb,
lib/ai/node_internal.rb

Overview

Node will help us to keep track of possible moves. We’ll be able to use it in order to know if two nodes are adjacent, how much points worth a node, etc.

Defined Under Namespace

Modules: Internal

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Internal

#==, included, #initialize, #link_to, #reset!, #to_i, #to_s

Instance Attribute Details

#available_soldiersObject

Returns the value of attribute available_soldiers.



9
10
11
# File 'lib/ai/node.rb', line 9

def available_soldiers
  @available_soldiers
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/ai/node.rb', line 9

def id
  @id
end

#incoming_soldiersObject

Returns the value of attribute incoming_soldiers.



9
10
11
# File 'lib/ai/node.rb', line 9

def incoming_soldiers
  @incoming_soldiers
end

#mapObject

Returns the value of attribute map.



9
10
11
# File 'lib/ai/node.rb', line 9

def map
  @map
end

#number_of_soldiersObject

Returns the value of attribute number_of_soldiers.



9
10
11
# File 'lib/ai/node.rb', line 9

def number_of_soldiers
  @number_of_soldiers
end

#player_idObject

Returns the value of attribute player_id.



9
10
11
# File 'lib/ai/node.rb', line 9

def player_id
  @player_id
end

#pointsObject

Returns the value of attribute points.



9
10
11
# File 'lib/ai/node.rb', line 9

def points
  @points
end

#soldiers_per_turnObject

Returns the value of attribute soldiers_per_turn.



9
10
11
# File 'lib/ai/node.rb', line 9

def soldiers_per_turn
  @soldiers_per_turn
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/ai/node.rb', line 9

def type
  @type
end

Instance Method Details

#adjacent?(other_node) ⇒ Boolean

Returns true if other_node is adjacent to self

Returns:

  • (Boolean)


13
14
15
# File 'lib/ai/node.rb', line 13

def adjacent?(other_node)
  @links.include?(other_node)
end

#adjacent_nodesObject

Returns a list of all adjacent nodes



48
49
50
# File 'lib/ai/node.rb', line 48

def adjacent_nodes
  @links.dup
end

#adjacent_nodes_and_selfObject

Returns a list of all adjacent nodes, plus self



53
54
55
# File 'lib/ai/node.rb', line 53

def adjacent_nodes_and_self
  adjacent_nodes.push(self)
end

#enemy?Boolean

Returns true if owned by somebody else than you

Returns:

  • (Boolean)


33
34
35
# File 'lib/ai/node.rb', line 33

def enemy?
  owned? && !mine?
end

#free?Boolean

Returns true if no one on the node

Returns:

  • (Boolean)


38
39
40
# File 'lib/ai/node.rb', line 38

def free?
  !owned?
end

#mine?Boolean

Returns true if yours

Returns:

  • (Boolean)


28
29
30
# File 'lib/ai/node.rb', line 28

def mine?
  owned_by?(@map.player_id)
end

#occupied?Boolean

Returns true if self has more than zero soldier

Returns:

  • (Boolean)


18
19
20
# File 'lib/ai/node.rb', line 18

def occupied?
  @number_of_soldiers > 0
end

#owned?Boolean

Returns true if owned by any player

Returns:

  • (Boolean)


23
24
25
# File 'lib/ai/node.rb', line 23

def owned?
  !!@player_id
end

#owned_by?(player_id) ⇒ Boolean

Returns true if node owned by provided player id

Returns:

  • (Boolean)


43
44
45
# File 'lib/ai/node.rb', line 43

def owned_by?(player_id)
  @player_id == player_id
end