def load(filename='Wireworld'): parsed = parser(filename) # Configuring Mineral, Vegetal & Animal classes = {'mineral': Mineral, 'animal': Animal, 'vegetal': Vegetal} states_classes = {} for block in parsed: if block[0][0] == 'world': # Creating the world world = World(*block[0][1:]) if block[0][0] in ('mineral', 'animal', 'vegetal'): state = create_state(block) # Parsing block classes[block[0][0]].add_state(block[0][1], state) states_classes[block[0][1]] = block[0][0] if block[0][0] == 'agent': # agent state (a1,b1) (a2,b2) ... ( for line in block: for i in range(len(line) - 2): world.add_agent(classes[states_classes[line[1]]]( line[1], *line[2 + i])) if block[0][0] == 'dist': # dist manhatan dists = {'manhattan': manhattan} Agent.dist = staticmethod(dists[block[0][1]]) return world
self.expected_salary += 1 def lower_salary(self): self.expected_salary = max(1, self.expected_salary - 1) def do_nothing(self): pass def balance(self): self.round_score = self.inventory['cakes'] + self.inventory['brownies'] + (self.cash * 0.2) self.inventory['cakes'] = 0 self.inventory['brownies'] = 0 Agents.SmartAgent.balance(self) return Agents.Consumer.balance(self) terra = World(10) market = Market.RetailStore(debug=False) terra.make_agents(Plebian, 1000) for item in ["flour", "milk", "eggs"]: for i in range(20): agent = Farm(item) terra.add_agent(agent) for item in ["cakes", "brownies"]: for i in range(20): agent = Factory(item) terra.add_agent(agent) terra.add_market(market) terra.run_sim(10)