def test_custom_player(self):
        """ CustomPlayer successfully completes a game against itself """
        agents = (Agent(CustomPlayer,
                        "Player 1"), Agent(CustomPlayer, "Player 2"))
        initial_state = Isolation()
        winner, game_history, _ = play(
            (agents, initial_state, self.time_limit, 0))

        state = initial_state
        moves = deque(game_history)
        while moves:
            state = state.result(moves.popleft())

        if not state.terminal_test():
            print(
                "Your agent with id:{state.player()} was not able to make a move in state:"
            )
            print(state.player())
            debug_state = DebugState.from_state(state)
            print(debug_state)

            raise Exception("Your agent did not play until a terminal state.")

        debug_state = DebugState.from_state(state)
        print(debug_state)
        print("Winner is: " + str(winner) + "!")
Ejemplo n.º 2
0
def _run(args):
    player1, player2, match_id = args
    logger.info("Launching match {}".format(match_id))
    result = isolation.play(player1,
                            player2,
                            time_limit=MOVE_TIME_LIMIT_MILLIS,
                            move_timeout=MOVE_TIMEOUT)
    logger.info("Completed match {}".format(match_id))
    return match_id, result
    def test_custom_player(self):
        """ CustomPlayer successfully completes a game against itself """
        agents = (Agent(CustomPlayer, "Player 1"),
                  Agent(CustomPlayer, "Player 2"))
        initial_state = Isolation()
        winner, game_history, _ = play((agents, initial_state, self.time_limit, 0))

        state = initial_state
        moves = deque(game_history)
        while moves: state = state.result(moves.popleft())

        self.assertTrue(state.terminal_test(), "Your agent did not play until a terminal state.")