def test_simulation_loop_starts_with_new_board():
    loop = SimulationLoop(
        player_one=ExampleRandomPlayerStrategy(),
        player_two=ExampleRandomPlayerStrategy(),
    )
    assert len(loop.boards) == 1
    assert loop.boards[0] == get_new_board()
def test_simulation_loop_sets_up_starting_player_if_not_provided():
    loop = SimulationLoop(
        player_one=ExampleRandomPlayerStrategy(),
        player_two=ExampleRandomPlayerStrategy(),
    )
    assert loop.starting_player is not None
    assert loop.starting_player in {Player.ONE, Player.TWO}
def test_simulation_loop_starts_off_with_no_run_and_winning_player():
    loop = SimulationLoop(
        player_one=ExampleRandomPlayerStrategy(),
        player_two=ExampleRandomPlayerStrategy(),
    )
    assert loop.has_run is False
    assert loop.winning_player is None
def test_simulation_loop_provides_option_to_choose_starting_player(player):
    loop = SimulationLoop(
        player_one=ExampleRandomPlayerStrategy(),
        player_two=ExampleRandomPlayerStrategy(),
        starting_player=player,
    )
    assert loop.starting_player == player
def test_simulation_loops_provides_player_strategies_in_dict_format():
    player_one = ExampleRandomPlayerStrategy()
    player_two = ExampleRandomPlayerStrategy()
    loop = SimulationLoop(player_one=player_one, player_two=player_two)
    assert {Player.ONE, Player.TWO} == loop.player_strategies.keys()
    assert player_one == loop.player_strategies[Player.ONE]
    assert player_two == loop.player_strategies[Player.TWO]
Beispiel #6
0
def test_example_random_player_strategy_chooses_valid_bins():
    random_strategy = ExampleRandomPlayerStrategy()

    for i in range(6):
        one_nonempty_bin_row = PlayerRow(
            bins=[1 if i == j else 0 for j in range(6)], goal=20)
        assert random_strategy.choose_bin(one_nonempty_bin_row) == i

    semi_empty_bin_row = PlayerRow(bins=[1, 0, 1, 0, 1, 0], goal=15)
    assert random_strategy.choose_bin(semi_empty_bin_row) in [0, 2, 4]
Beispiel #7
0
def _get_all_strategies() -> List[PlayerStrategy]:
    return [
        AlwaysMaximumPlayerStrategy(),
        AlwaysMinimumPlayerStrategy(),
        EvenGoalOrPiecesOnOtherSideStrategy(),
        EvenGoalStealAndPiecesOnOtherSideStrategy(),
        ExampleRandomPlayerStrategy(),
    ]
def test_simulation_loop_starts_with_no_turns():
    loop = SimulationLoop(
        player_one=ExampleRandomPlayerStrategy(),
        player_two=ExampleRandomPlayerStrategy(),
    )
    assert len(loop.turns) == 0
def test_simulation_loop_provides_player_strategy_properties():
    player_one = ExampleRandomPlayerStrategy()
    player_two = ExampleRandomPlayerStrategy()
    loop = SimulationLoop(player_one=player_one, player_two=player_two)
    assert loop.player_one_strategy == player_one
    assert loop.player_two_strategy == player_two