class Berlin::AI::Node

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.

Attributes

available_soldiers[RW]
id[RW]
incoming_soldiers[RW]
map[RW]
number_of_soldiers[RW]
player_id[RW]
points[RW]
soldiers_per_turn[RW]
type[RW]

Public Instance Methods

adjacent?(other_node) click to toggle source

Returns true if other_node is adjacent to self

# File lib/ai/node.rb, line 13
def adjacent?(other_node)
  @links.include?(other_node)
end
adjacent_nodes() click to toggle source

Returns a list of all adjacent nodes

# File lib/ai/node.rb, line 49
def adjacent_nodes
  @links.dup
end
adjacent_nodes_and_self() click to toggle source

Returns a list of all adjacent nodes, plus self

# File lib/ai/node.rb, line 54
def adjacent_nodes_and_self
  adjacent_nodes.push(self)
end
enemy?() click to toggle source

Returns true if owned by somebody else than you

# File lib/ai/node.rb, line 29
def enemy?
  !free? && !mine?
end
foreign?() click to toggle source

Returns true if owned by somebody else than you

# File lib/ai/node.rb, line 34
def foreign?
  !mine?
end
free?() click to toggle source

Returns true if no one on the node

# File lib/ai/node.rb, line 39
def free?
  @player_id.nil?
end
mine?() click to toggle source

Returns true if yours

# File lib/ai/node.rb, line 23
def mine?
  owned_by?(@map.player_id)
end
Also aliased as: owned?
occupied?() click to toggle source

Returns true if self has more than zero soldier

# File lib/ai/node.rb, line 18
def occupied?
  @number_of_soldiers > 0
end
owned?()
Alias for: mine?
owned_by?(player_id) click to toggle source

Returns true if node owned by provided player id

# File lib/ai/node.rb, line 44
def owned_by?(player_id)
  @player_id == player_id
end