Class: Berlin::AI::Map

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

Overview

Map keeps track of all the useful information needed to play, such as nodes, points, soldiers, etc. Game will then be able to pick any information it wants from map to decide what are the best moves to do.

Defined Under Namespace

Modules: Internal

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Internal

included, #initialize, #update

Instance Attribute Details

#directedObject

Returns the value of attribute directed.



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

def directed
  @directed
end

#nodes_hashObject

Returns the value of attribute nodes_hash.



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

def nodes_hash
  @nodes_hash
end

#player_idObject

Returns the value of attribute player_id.



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

def player_id
  @player_id
end

Instance Method Details

#controlled_nodesObject

We can now loop on our owned nodes in order to find our controlled nodes.



37
38
39
# File 'lib/ai/map.rb', line 37

def controlled_nodes
  owned_nodes.select{ |n| n.occupied? }
end

#directed?Boolean

Is the map directed?

Returns:

  • (Boolean)


42
43
44
# File 'lib/ai/map.rb', line 42

def directed?
  @directed
end

#enemy_nodesObject

Returns an array of all enemy nodes



22
23
24
# File 'lib/ai/map.rb', line 22

def enemy_nodes
  nodes.select{ |n| n.enemy? }
end

#foreign_nodesObject

Returns an array of all nodes that we don’t owned



32
33
34
# File 'lib/ai/map.rb', line 32

def foreign_nodes
  nodes.select{ |n| n.foreign? }
end

#free_nodesObject

Returns an array of all free nodes



27
28
29
# File 'lib/ai/map.rb', line 27

def free_nodes
  nodes.select{ |n| n.free? }
end

#nodesObject

Returns an array of all nodes of the map



12
13
14
# File 'lib/ai/map.rb', line 12

def nodes
  @nodes_hash.values
end

#owned_nodesObject

Returns an array of all owned nodes



17
18
19
# File 'lib/ai/map.rb', line 17

def owned_nodes
  nodes.select{ |n| n.mine? }
end