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



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

def adjacent_nodes
  @links.dup
end

#adjacent_nodes_and_selfObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

def foreign?
  !mine?
end

#free?Boolean

Returns true if no one on the node

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

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