import ccm log=ccm.log() from ccm.lib import grid mymap=""" ################ # # # # # # ######### ###### # # # # # # # # ################ """ class MyCell(grid.Cell): def color(self): if self.wall: return 'black' else: return 'white' def load(self,char): if char=='#': self.wall=True world=grid.World(MyCell,map=mymap,directions=4) ccm.display(world) world.run()
self.action=None self.busy=False class MyAgent(ACTR): focus=Buffer() body=grid.Body() motor=MotorModule() def init(): focus.set('wander') def wandering_forward(focus='wander',motor='busy:False'): motor.go_forward() def wandering_left(focus='wander',motor='busy:False'): motor.go_left() def wandering_right(focus='wander',motor='busy:False'): motor.go_right() world=grid.World(MyCell,map=mymap) agent=MyAgent() world.add(agent,x=5,y=3) ccm.display(world) ccm.log_everything(agent) world.run()
self.cell = Cell.start_cell self.last_action = None else: self.go_in_direction(action) def calc_state(self): return self.cell.x, self.cell.y def calc_reward(self): here = self.cell if here.cliff: return cliff_reward elif here.goal: self.score += 1 return goal_reward else: return normal_reward world = grid.World(Cell, map=map, directions=directions) agent = Agent() world.add(agent, cell=Cell.start_cell) #ccm.display(world) world.run(limit=time_limit) log.score = agent.score agent.score = 0 world.run(limit=time_limit) log.score2 = agent.score