def test_bare_model_player_from_model(): game = OthelloGame(6) some_net = OthelloNNet(game) player = BareModelPlayer(game, some_net) board = game.get_init_board() action = player.play(board) assert action
def test_alpha_zero_player_from_model(): game = OthelloGame(6) some_net = OthelloNNet(game) player = AlphaZeroPlayer(game, some_net) board = game.get_init_board() action = player.play(board) assert action
def test_human_player_valid_action(): action_valid = "1,2" game = OthelloGame(6) player = HumanPlayer(game) board = game.get_init_board() with patch("builtins.input", side_effect=[action_valid]): action = player.play(board) assert action == 8
def test_alpha_zero_player_reset(): game = OthelloGame(6) player = AlphaZeroPlayer(game, OthelloNNet, num_mcts_sims=4) assert not player.mcts.Qsa board = game.get_init_board() player.play(board) assert player.mcts.Qsa player.reset() assert not player.mcts.Qsa
def test_human_player_invalid_action(capsys): action_valid = "1,2" action_invalid = "0,0" game = OthelloGame(6) player = HumanPlayer(game) board = game.get_init_board() with patch("builtins.input", side_effect=[action_invalid, action_valid]): player.play(board) out, _err = capsys.readouterr() assert out == "Invalid action.\n"
def test_bare_model_player_from_checkpoint(): game = OthelloGame(6) some_net = OthelloNNet(game) folder, filename = "/tmp/", "checkpoint_bare_model_player" some_net.save_checkpoint(folder, filename) del some_net player = BareModelPlayer(game, OthelloNNet, folder=folder, filename=filename) board = game.get_init_board() action = player.play(board) assert action
def test_alpha_zero_player_from_checkpoint(): game = OthelloGame(6) some_net = OthelloNNet(game) folder, filename = "/tmp/", "checkpoint_alpha_zero_player" some_net.save_checkpoint(folder, filename) del some_net player = AlphaZeroPlayer(game, OthelloNNet, folder=folder, filename=filename, num_mcts_sims=4) board = game.get_init_board() action = player.play(board) assert action
def test_self_play(local_ray, tmpdir): game = OthelloGame(6) nnet = OthelloNNet(game) s = SharedStorage.remote(nnet.get_weights()) r = ReplayBuffer.remote(games_to_play=1, games_to_use=1, folder=tmpdir) assert ray.get(r.get_number_of_games_played.remote()) == 0 self_play = SelfPlay.remote(r, s, game, nnet.__class__, dict(args)) ray.get(self_play.start.remote()) assert ray.get(r.get_number_of_games_played.remote()) == 1 assert ray.get(r.played_enough.remote()) is True games = ray.get(ray.get(r.get_examples.remote())) assert len(games) == 1 examples = games[0] assert len(examples) > 2 board, policy, winner = examples[0] assert isinstance(board, type(game.get_init_board())) assert len(policy) == game.get_action_size() assert all(0 <= value <= 1 for value in policy) assert winner in [1, -1]
def test_bare_model_player(): game = OthelloGame(6) player = BareModelPlayer(game, OthelloNNet) board = game.get_init_board() action = player.play(board) assert action
def test_alpha_zero_player(): game = OthelloGame(6) player = AlphaZeroPlayer(game, OthelloNNet, num_mcts_sims=4) board = game.get_init_board() action = player.play(board) assert action
def test_random_player(): game = OthelloGame(6) player = RandomPlayer(game) board = game.get_init_board() action = player.play(board) assert action
def test_greedy_player(): game = OthelloGame(6) player = GreedyPlayer(game) board = game.get_init_board() action = player.play(board) assert action