예제 #1
0
    def test_get_all_statements() -> None:
        """Should return possible statements from all possible initializations."""
        player_index = 2
        set_roles(Role.WOLF, Role.SEER, Role.MASON, Role.VILLAGER)
        const.NUM_PLAYERS = 3
        expected_statements = (
            Statement(
                "I am a Mason. The other Mason is not present.",
                (
                    (2, frozenset({Role.MASON})),
                    (0, frozenset({Role.WOLF, Role.SEER, Role.VILLAGER})),
                    (1, frozenset({Role.WOLF, Role.SEER, Role.VILLAGER})),
                ),
            ),
            Statement(
                "I am a Mason. The other Mason is Player 0.",
                ((2, frozenset({Role.MASON})), (0, frozenset({Role.MASON}))),
            ),
            Statement(
                "I am a Mason. The other Mason is Player 1.",
                ((2, frozenset({Role.MASON})), (1, frozenset({Role.MASON}))),
            ),
        )

        result = Mason.get_all_statements(player_index)

        assert result == expected_statements
예제 #2
0
    def test_hunter_wins(caplog: pytest.LogCaptureFixture,
                         large_game_roles: tuple[Role, ...]) -> None:
        """
        Should declare Village victory if no wolves are found,
        Hunter is killed, and Hunter voted for a true Wolf.
        """
        set_roles(*large_game_roles[::-1])
        guessed_wolf_inds = [0, 9]
        vote_inds = (7, 10, 0, 9, 7, 9, 7, 7, 7, 0, 0, 0)
        expected = (
            "Player 0 was chosen as a Wolf.",
            "Player 0 was a Hunter!\n",
            "(Player 0) Hunter died and killed Player 7 too!\n",
            "Player 9 was chosen as a Wolf.",
            "Player 9 was a Tanner!\n",
            "Player 7 was chosen as a Wolf.",
            "Player 7 was a Wolf!\n",
            "Village Team wins!",
        )

        result = one_night.eval_winning_team(const.ROLES, guessed_wolf_inds,
                                             vote_inds)

        assert result is Team.VILLAGE
        verify_output(caplog, expected)
예제 #3
0
    def test_get_all_statements() -> None:
        """Should return possible statements from all possible initializations."""
        player_index = 1
        set_roles(Role.WOLF, Role.ROBBER, Role.VILLAGER)
        const.NUM_PLAYERS = 2
        expected = (
            Statement(
                "I am a Robber and I swapped with Player 0. I am now a Villager.",
                ((1, frozenset({Role.ROBBER})),
                 (0, frozenset({Role.VILLAGER}))),
                ((SwitchPriority.ROBBER, 1, 0), ),
                Role.ROBBER,
            ),
            Statement(
                "I am a Robber and I swapped with Player 0. I am now a Wolf.",
                ((1, frozenset({Role.ROBBER})), (0, frozenset({Role.WOLF}))),
                ((SwitchPriority.ROBBER, 1, 0), ),
                Role.ROBBER,
            ),
            Statement(
                "I am a Robber and I swapped with Player 0. I am now a Robber.",
                ((1, frozenset({Role.ROBBER})), (0, frozenset({Role.ROBBER}))),
                ((SwitchPriority.ROBBER, 1, 0), ),
                Role.ROBBER,
            ),
        )

        result = Robber.get_all_statements(player_index)

        assert set(result) == set(expected)
예제 #4
0
    def test_perfect_villagers() -> None:
        """Correctly play one round of one night werewolf."""
        const.NUM_PLAYERS = 10
        const.NUM_CENTER = 3
        const.RANDOMIZE_ROLES = False
        set_roles(
            Role.INSOMNIAC,
            Role.VILLAGER,
            Role.ROBBER,
            Role.VILLAGER,
            Role.SEER,
            Role.MASON,
            Role.TROUBLEMAKER,
            Role.VILLAGER,
            Role.MASON,
            Role.HUNTER,
            Role.WOLF,
            Role.WOLF,
            Role.MINION,
        )
        random.seed()

        stat_tracker = one_night.simulate_game(num_games=10)

        stat_results = stat_tracker.get_metric_results()
        assert stat_results["villager_wins"] == 1
        assert stat_results["correctness_lenient_center"] == 1
        assert stat_results["wolf_predictions_one"] == 0
        assert stat_results["wolf_predictions_all"] == 1
예제 #5
0
    def test_expectimax_tanner() -> None:
        """Correctly play one round of one night werewolf."""
        const.NUM_PLAYERS = 9
        const.NUM_CENTER = 3
        const.EXPECTIMAX_TANNER = True
        const.RANDOMIZE_ROLES = False
        set_roles(
            Role.INSOMNIAC,
            Role.HUNTER,
            Role.MASON,
            Role.MASON,
            Role.ROBBER,
            Role.SEER,
            Role.TANNER,
            Role.TROUBLEMAKER,
            Role.VILLAGER,
            Role.VILLAGER,
            Role.VILLAGER,
            Role.WOLF,
        )

        stat_tracker = one_night.simulate_game(num_games=20)

        stat_results = stat_tracker.get_metric_results()
        write_results(stat_results, "standard/expectimax_tanner.csv")
        assert stat_results["tanner_wins"] > 0.8
예제 #6
0
    def test_awake_init_medium(medium_game_roles: tuple[Role, ...]) -> None:
        """
        Should initialize a Wolf. Note that the player_index of the Wolf is
        not necessarily the index where the true Wolf is located.
        """
        set_roles(Role.WOLF, *medium_game_roles[1:])
        player_index = 2

        wolf = Wolf.awake_init(player_index, list(const.ROLES))
        assert wolf.wolf_indices == (0, 2)
        assert wolf.center_index is None
        assert wolf.center_role is None
예제 #7
0
    def test_awake_init_center(large_game_roles: tuple[Role, ...]) -> None:
        """
        Should initialize a Center Wolf. Note that the player_index of the Wolf is
        not necessarily the index where the true Wolf is located.
        """
        set_roles(Role.VILLAGER, *large_game_roles[1:])
        player_index = 7

        wolf = Wolf.awake_init(player_index, list(const.ROLES))

        assert wolf.wolf_indices == (7, )
        assert wolf.center_index == 13
        assert wolf.center_role is Role.INSOMNIAC
예제 #8
0
    def test_get_role_counts() -> None:
        """
        Should return True if there is a a dict with counts of all certain roles.
        """
        set_roles(Role.WOLF, Role.SEER, Role.VILLAGER, Role.ROBBER, Role.VILLAGER)
        possible_roles_list = (
            frozenset({Role.VILLAGER}),
            frozenset({Role.SEER}),
            frozenset({Role.VILLAGER}),
        ) + (const.ROLE_SET,) * 2

        result = SolverState(possible_roles_list).get_role_counts()

        assert result == {Role.SEER: 0, Role.VILLAGER: 0, Role.WOLF: 1, Role.ROBBER: 1}
예제 #9
0
    def test_get_single_mason_statement() -> None:
        """Should give the proper statement when only one Mason is present."""
        player_index = 2
        set_roles(Role.WOLF, Role.SEER, Role.MASON, Role.VILLAGER)
        const.NUM_PLAYERS = 3
        result = Mason.get_mason_statements(player_index, (2, ))

        assert result == (Statement(
            "I am a Mason. The other Mason is not present.",
            (
                (2, frozenset({Role.MASON})),
                (0, frozenset({Role.WOLF, Role.SEER, Role.VILLAGER})),
                (1, frozenset({Role.WOLF, Role.SEER, Role.VILLAGER})),
            ),
        ), )
예제 #10
0
    def test_get_all_statements() -> None:
        """Should return possible statements from all possible initializations."""
        player_index = 2
        set_roles(
            Role.WOLF,
            Role.SEER,
            Role.TROUBLEMAKER,
            Role.VILLAGER,
            Role.ROBBER,
            Role.WOLF,
        )
        const.NUM_PLAYERS = 3
        const.NUM_CENTER = 3
        expected_statements = (Statement(
            "I am a Troublemaker and I swapped Player 0 and Player 1.",
            ((2, frozenset({Role.TROUBLEMAKER})), ),
            ((SwitchPriority.TROUBLEMAKER, 0, 1), ),
            Role.TROUBLEMAKER,
        ), )

        result = Troublemaker.get_all_statements(player_index)

        assert result == expected_statements
예제 #11
0
    def test_get_all_statements() -> None:
        """Should return possible statements from all possible initializations."""
        player_index = 2
        set_roles(Role.WOLF, Role.INSOMNIAC, Role.SEER)
        expected = (
            Statement(
                ("I am a Insomniac and when I woke up I was a Wolf. I don't know "
                 "who I switched with."),
                ((2, frozenset({Role.INSOMNIAC})), ),
            ),
            Statement(
                "I am a Insomniac and when I woke up I was a Insomniac.",
                ((2, frozenset({Role.INSOMNIAC})), ),
            ),
            Statement(
                ("I am a Insomniac and when I woke up I was a Seer. I don't know "
                 "who I switched with."),
                ((2, frozenset({Role.INSOMNIAC})), ),
            ),
        )

        result = Insomniac.get_all_statements(player_index)

        assert set(result) == set(expected)
예제 #12
0
    def test_get_all_statements() -> None:
        """Should return possible statements from all possible initializations."""
        player_index = 1
        set_roles(Role.WOLF, Role.SEER, Role.VILLAGER, Role.WOLF)
        const.NUM_PLAYERS = 2
        const.NUM_CENTER = 2
        expected = (
            Statement(
                "I am a Seer and I saw that Player 0 was a Villager.",
                ((1, frozenset({Role.SEER})), (0, frozenset({Role.VILLAGER}))),
            ),
            Statement(
                "I am a Seer and I saw that Player 1 was a Villager.",
                ((1, frozenset({Role.SEER})), (1, frozenset({Role.VILLAGER}))),
            ),
            Statement(
                "I am a Seer and I saw that Player 0 was a Wolf.",
                ((1, frozenset({Role.SEER})), (0, frozenset({Role.WOLF}))),
            ),
            Statement(
                "I am a Seer and I saw that Player 1 was a Wolf.",
                ((1, frozenset({Role.SEER})), (1, frozenset({Role.WOLF}))),
            ),
            Statement(
                "I am a Seer and I saw that Player 0 was a Seer.",
                ((1, frozenset({Role.SEER})), (0, frozenset({Role.SEER}))),
            ),
            Statement(
                "I am a Seer and I saw that Player 1 was a Seer.",
                ((1, frozenset({Role.SEER})), (1, frozenset({Role.SEER}))),
            ),
            Statement(
                ("I am a Seer and I saw that Center 0 was a Villager and "
                 "that Center 1 was a Wolf."),
                (
                    (1, frozenset({Role.SEER})),
                    (2, frozenset({Role.VILLAGER})),
                    (3, frozenset({Role.WOLF})),
                ),
            ),
            Statement(
                ("I am a Seer and I saw that Center 0 was a Wolf and "
                 "that Center 1 was a Villager."),
                (
                    (1, frozenset({Role.SEER})),
                    (2, frozenset({Role.WOLF})),
                    (3, frozenset({Role.VILLAGER})),
                ),
            ),
            Statement(
                ("I am a Seer and I saw that Center 0 was a Wolf "
                 "and that Center 1 was a Wolf."),
                (
                    (1, frozenset({Role.SEER})),
                    (2, frozenset({Role.WOLF})),
                    (3, frozenset({Role.WOLF})),
                ),
            ),
        )

        result = Seer.get_all_statements(player_index)

        assert set(result) == set(expected)