Exemple #1
0
 def new_game(self, layout, pacman_agent, ghost_agents, display, quiet=False, catch_exceptions=False):
     agents = [pacman_agent] + ghost_agents[:layout.get_num_ghosts()]
     init_state = GameState()
     init_state.initialize(layout, len(ghost_agents))
     game = Game(agents, display, self, catch_exceptions=catch_exceptions)
     game.state = init_state
     self.initial_state = init_state.deep_copy()
     self.quiet = quiet
     return game
def replay_game(layout, actions, display):
    import pacman_agents, ghost_agents
    rules = ClassicGameRules()
    agents = [pacman_agents.GreedyAgent()] + [
        ghost_agents.RandomGhost(i + 1) for i in range(layout.get_num_ghosts())
    ]
    game = rules.new_game(layout, agents[0], agents[1:], display)
    state = game.state
    display.initialize(state.data)

    for action in actions:
        # Execute the action
        state = state.generate_successor(*action)
        # Change the display
        display.update(state.data)
        # Allow for game specific conditions (winning, losing, etc.)
        rules.process(state, game)

    display.finish()