def test_no_errors_when_playing_and_printing_games():
    for i in range(100):
        player1 = RandomPlayer()
        player2 = RandomPlayer()
        observers = [GameStatePrinter(show_action_history=True)]
        game = TwoPlayerGame(State.empty(), player1, player2, observers)
        game.play()
def test_minimax_is_better_than_greedy():
    state = State.empty()
    player1 = GreedyPlayer('player 1')
    player2 = MiniMaxPlayer('player 2')

    game = TwoPlayerGame(state, player1, player2)
    game.play()

    assert Color.BROWN == game.current_state.winner
def test_greedy_is_better_than_random():
    state = State.empty()
    player1 = RandomPlayer('player 1')
    player2 = GreedyPlayer('player 2')

    game = TwoPlayerGame(state, player1, player2)
    game.play()

    assert Color.BROWN == game.current_state.winner
def play_random_opponenents_game_once(args):
    tournament_dir, model_dir, first_player_name_filter, first_player_kwargs_filter, second_player_name_filter, \
    second_player_kwargs_filter = args
    player1 = random_player(model_dir, first_player_name_filter,
                            first_player_kwargs_filter)
    player2 = random_player(model_dir, second_player_name_filter,
                            second_player_kwargs_filter)
    print(repr(player1), 'vs', repr(player2))
    state = State.empty()
    observers = [GameWinnerSerializer(tournament_dir)]
    game = TwoPlayerGame(state, player1, player2, observers)
    game.play()
def test_game():
    state = State.empty()
    player1 = RandomPlayer('player 1')
    player2 = RandomPlayer('player 2')

    game = TwoPlayerGame(state, player1, player2)

    game._turn()
    game._turn()

    number_of_stones = sum((stone is not Color.NONE
                            for stone in game.current_state.stones.values()))
    assert 2 == number_of_stones
Exemple #6
0
def simulate_once(model_path,
                  data_dir=None,
                  exploration=1.0,
                  temperature=1.0,
                  search_budget=1600,
                  verbose=False):
    state = State.empty()
    player_name = 'AlphaConnect (%s)' % model_path.split('/')[-1]
    player = AlphaConnectPlayer(model_path,
                                player_name,
                                exploration,
                                temperature,
                                search_budget=search_budget,
                                self_play=True)
    observers = []
    if data_dir is not None:
        observers.append(AlphaConnectSerializer(data_dir))
    if verbose:
        observers.append(AlphaConnectPrinter())
        observers.append(GameStatePrinter())
    game = TwoPlayerGame(state, player, player, observers)
    game.play()
    player.clear_session()
    return game
def _play_game(args):
    human_player = ConsolePlayer('You')
    computer_player = AlphaConnectPlayer(args.model_path,
                                         'Computer',
                                         time_budget=14500)
    observers = [
        AlphaConnectPrinter(),
        GameStatePrinter(show_action_history=True)
    ]

    if args.human_first:
        game = TwoPlayerGame(State.empty(), human_player, computer_player,
                             observers)
    else:
        game = TwoPlayerGame(State.empty(), computer_player, human_player,
                             observers)

    if args.actions is not None:
        for action_hex in args.actions:
            game.play_action(game.next_player(), Action.from_hex(action_hex))

    game.play()
def test_alpha_connect_player_saves_policy(test_model_path):
    player = AlphaConnectPlayer(test_model_path, 'alpha', time_budget=5)
    game = TwoPlayerGame(State.empty(), player, player)
    assert len(game.action_history) == len(player.history)