コード例 #1
0
    def test_Performance(self):
        p1 = ttt_players.RandomPlayer()
        p2 = ttt_players.RandomPlayer()
        simulation = TicTacToe([p1, p2])
        N = 15000

        start = datetime.now()
        simulation.run_simulations(N)
        print("Simulating %s random games took %s" %
              (N, datetime.now() - start))
コード例 #2
0
 def test_ExperiencedBlockVsRandom(self):
     player1 = ttt_players.ExperiencedPlayer(block_mid=True)
     player2 = ttt_players.RandomPlayer()
     simulation = TicTacToe([player1, player2])
     results, losses = simulation.run_simulations(self.TEST_EPISODES)
     print("Average Result Experienced(block) vs Random: %s" %
           np.mean(results))
コード例 #3
0
    def testRandomPlayer(self):
        player1 = ttt_players.RandomPlayer()
        player2 = ttt_players.RandomPlayer()
        simulation = TicTacToe([player1, player2])
        results, losses = simulation.run_simulations(self.TEST_EPISODES)
        self.assertTrue(len(results) == self.TEST_EPISODES)
        self.assertTrue(None not in results)

        for i in range(4):
            simulation.__run__(player1, player2)
            black_stones, white_stones = simulation.board.count_stones()
            self.assertIn(black_stones,
                          [white_stones - 1, white_stones, white_stones + 1])
            if not simulation.board.game_won():
                self.assertEqual(black_stones + white_stones,
                                 simulation.board.board_size**2)
        print("Average Result Random vs Random: %s" % np.mean(results))
コード例 #4
0
    def test_Evaluation(self):
        start = datetime.now()
        score, results, overview = evaluate_against_base_players(
            ttt_players.RandomPlayer())
        print("Evaluating RandomPlayer -> score: %s, took: %s" %
              (score, datetime.now() - start))

        start = datetime.now()
        score, results, overview = evaluate_against_base_players(
            ttt_players.ExperiencedPlayer())
        print("Evaluating ExpertPlayer -> score: %s, took: %s" %
              (score, datetime.now() - start))
コード例 #5
0
    def test_Board_Representation(self):
        random_player = ttt_players.RandomPlayer()
        boards = []
        inverses = []
        for i in range(100):
            board = TicTacToeBoard()
            inverse_board = TicTacToeBoard()
            for j in range(9):
                move = random_player.get_move(board)
                color = (config.BLACK, config.WHITE)
                color = random.choice(color)

                board.apply_move(move, color)
                boards.append(board.copy())

                inverse_board.apply_move(move, board.other_color(color))
                inverses.append((inverse_board.copy()))

        for i in range(len(boards)):
            rep = boards[i].get_representation(config.WHITE)
            self.assertTrue((rep == inverses[i].board).all(),
                            msg="Inverting board failed")
コード例 #6
0
    def test_evaluation(self):
        p1 = ttt_players.RandomPlayer()
        evaluate_against_base_players(p1, silent=False)

        p2 = FCReinforcePlayer(lr=1e-5)
        evaluate_against_base_players(p2, silent=False)