class Violence::Town

Constants

POPULATION

Attributes

agents[RW]

Public Class Methods

new() click to toggle source
# File lib/violence/town.rb, line 9
def initialize
  @agents = Set.new

  POPULATION.times do
    @agents << Violence::Agent.new
  end
end

Public Instance Methods

inspect() click to toggle source
# File lib/violence/town.rb, line 33
def inspect
  agentss = self.agents.sort_by {|agent| agent.greed}
  agentss.map do |agent|
    template = "Bank: %8.2f, Productivity: %2d, Greed: %4.2f, All ever owned: %6d"
    template % [agent.bank, agent.productivity, agent.greed, agent.allconsumed + agent.bank]
  end
end
tick() click to toggle source
# File lib/violence/town.rb, line 17
def tick
  @agents.each do |agent|

    investcost = 2 ** agent.productivity
    if agent.bank >= investcost
      agent.invest(investcost)
    else
      agent.produce
    end

  end

  self.inspect

end