module Berlin::AI::Map::Internal

Public Class Methods

included(base) click to toggle source
# File lib/ai/map_internal.rb, line 42
def self.included(base)
  base.extend(ClassMethods)
end
new(options={}) click to toggle source
# File lib/ai/map_internal.rb, line 46
def initialize(options={})
  @nodes_hash = {}

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

Public Instance Methods

update(state) click to toggle source

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 => [{:node_id => STRING, :number_of_soldiers => INTEGER, :player_id => INTEGER}, …]

# 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