def get_colorboard(self): colorboard = self.colors[self.board] colorboard[self.exit.y][self.exit.x] = self.colors[ PacmanObjectType.EXIT] for food in self.current_state.foods: colorboard[food.y][food.x] = self.colors[PacmanObjectType.FOOD] for agent in self.current_state.agents: Debug.print(agent) colorboard[agent.pos.y][agent.pos.x] = self.colors[agent.type] return colorboard
def next(self): self.current_state, _ = self.act(self.current_state) if self.is_winning_state(self.current_state): Console.print("-1 -1") Debug.print("Player won.") return False elif self.is_losing_state(self.current_state): Console.print("-1 -1") Debug.print("Player lost.") return False return True
def act(self, state, action=None): nstate = state.copy() for idx, agent in enumerate(state.agents): if agent.type is PacmanAgentType.PLAYER: nstate.agents[idx], action = agent.move(state, action) newpos = nstate.agents[idx].pos if not self.is_valid_state(nstate): Debug.print("Agent [", agent.name, "] Forbidden move!") raise RuntimeError if newpos in nstate.foods: nstate.foods.remove(newpos) else: # hack. enemies see what move we're going to make. nstate.agents[idx], _ = agent.move(nstate) if not self.is_valid_state(nstate): Debug.print(agent.pos, nstate.agents[idx].pos) Debug.print("Agent [", agent.name, "] Forbidden move!") raise RuntimeError return nstate, self.reward(state.get_player_agent(), state, action, nstate)