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.
-
#foreign? ⇒ Boolean
Returns true if owned by somebody else than you.
-
#free? ⇒ Boolean
Returns true if no one on the node.
-
#mine? ⇒ Boolean
(also: #owned?)
Returns true if yours.
-
#occupied? ⇒ Boolean
Returns true if self has more than zero soldier.
-
#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
49 50 51 |
# File 'lib/ai/node.rb', line 49 def adjacent_nodes @links.dup end |
#adjacent_nodes_and_self ⇒ Object
Returns a list of all adjacent nodes, plus self
54 55 56 |
# File 'lib/ai/node.rb', line 54 def adjacent_nodes_and_self adjacent_nodes.push(self) end |
#enemy? ⇒ Boolean
Returns true if owned by somebody else than you
29 30 31 |
# File 'lib/ai/node.rb', line 29 def enemy? !free? && !mine? end |
#foreign? ⇒ Boolean
Returns true if owned by somebody else than you
34 35 36 |
# File 'lib/ai/node.rb', line 34 def foreign? !mine? end |
#free? ⇒ Boolean
Returns true if no one on the node
39 40 41 |
# File 'lib/ai/node.rb', line 39 def free? @player_id.nil? end |
#mine? ⇒ Boolean Also known as: owned?
Returns true if yours
23 24 25 |
# File 'lib/ai/node.rb', line 23 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_by?(player_id) ⇒ Boolean
Returns true if node owned by provided player id
44 45 46 |
# File 'lib/ai/node.rb', line 44 def owned_by?(player_id) @player_id == player_id end |