Class: Berlin::AI::Node
- Inherits:
-
Object
- Object
- Berlin::AI::Node
- 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
-
#available_soldiers ⇒ Object
Returns the value of attribute available_soldiers.
-
#id ⇒ Object
Returns the value of attribute id.
-
#incoming_soldiers ⇒ Object
Returns the value of attribute incoming_soldiers.
-
#map ⇒ Object
Returns the value of attribute map.
-
#number_of_soldiers ⇒ Object
Returns the value of attribute number_of_soldiers.
-
#player_id ⇒ Object
Returns the value of attribute player_id.
-
#points ⇒ Object
Returns the value of attribute points.
-
#soldiers_per_turn ⇒ Object
Returns the value of attribute soldiers_per_turn.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#adjacent?(other_node) ⇒ Boolean
Returns true if other_node is adjacent to self.
-
#adjacent_nodes ⇒ Object
Returns a list of all adjacent nodes.
-
#adjacent_nodes_and_self ⇒ Object
Returns a list of all adjacent nodes, plus self.
-
#enemy? ⇒ Boolean
Returns true if owned by somebody else than you.
-
#free? ⇒ Boolean
Returns true if no one on the node.
-
#mine? ⇒ Boolean
Returns true if yours.
-
#occupied? ⇒ Boolean
Returns true if self has more than zero soldier.
-
#owned? ⇒ Boolean
Returns true if owned by any player.
-
#owned_by?(player_id) ⇒ Boolean
Returns true if node owned by provided player id.
Methods included from Internal
#==, included, #initialize, #link_to, #reset!, #to_i, #to_s
Instance Attribute Details
#available_soldiers ⇒ Object
Returns the value of attribute available_soldiers.
9 10 11 |
# File 'lib/ai/node.rb', line 9 def available_soldiers @available_soldiers end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/ai/node.rb', line 9 def id @id end |
#incoming_soldiers ⇒ Object
Returns the value of attribute incoming_soldiers.
9 10 11 |
# File 'lib/ai/node.rb', line 9 def incoming_soldiers @incoming_soldiers end |
#map ⇒ Object
Returns the value of attribute map.
9 10 11 |
# File 'lib/ai/node.rb', line 9 def map @map end |
#number_of_soldiers ⇒ Object
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_id ⇒ Object
Returns the value of attribute player_id.
9 10 11 |
# File 'lib/ai/node.rb', line 9 def player_id @player_id end |
#points ⇒ Object
Returns the value of attribute points.
9 10 11 |
# File 'lib/ai/node.rb', line 9 def points @points end |
#soldiers_per_turn ⇒ Object
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 |
#type ⇒ Object
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
13 14 15 |
# File 'lib/ai/node.rb', line 13 def adjacent?(other_node) @links.include?(other_node) end |
#adjacent_nodes ⇒ Object
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_self ⇒ Object
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
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
38 39 40 |
# File 'lib/ai/node.rb', line 38 def free? !owned? end |
#mine? ⇒ Boolean
Returns true if yours
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
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
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
43 44 45 |
# File 'lib/ai/node.rb', line 43 def owned_by?(player_id) @player_id == player_id end |