Module: Berlin::AI::Map::Internal

Included in:
Berlin::AI::Map
Defined in:
lib/ai/map_internal.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize(options = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ai/map_internal.rb', line 46

def initialize(options={})
  @nodes_hash = {}

  options.each do |k,v|
    self.send("#{k}=", v)
  end
end

#update(state) ⇒ Object

Let’s update the current state with the latest provided info! With this step, we’ll now know who possess the node and how many soldiers there is. state contains an array of nodes, so we just have to loop on it. state => [=> STRING, :number_of_soldiers => INTEGER, :player_id => INTEGER, …]



58
59
60
61
62
63
64
# File 'lib/ai/map_internal.rb', line 58

def update(state)
  state.each do |n|
    node                    = @nodes_hash[n['node_id']]
    node.number_of_soldiers = n['number_of_soldiers']
    node.player_id          = n['player_id']
  end
end