예제 #1
0
    def awake_init(cls, player_index: int, game_roles: list[Role]) -> Troublemaker:
        """Initializes Troublemaker - switches one player with another player."""
        is_user = const.IS_USER[player_index]
        if is_user:
            logger.info("Choose two players to switch places:")
        choice_1 = get_player(is_user, (player_index,))
        choice_2 = get_player(is_user, (player_index, choice_1))

        swap_characters(game_roles, choice_1, choice_2)
        logger.debug(
            f"[Hidden] Troublemaker switches Player {choice_1} and Player {choice_2}."
        )
        if is_user:
            logger.info(
                f"You switch Player {choice_1} with Player {choice_2}.", cache=True
            )

        return cls(player_index, choice_1, choice_2)
예제 #2
0
    def test_user_input_indices(monkeypatch: pytest.MonkeyPatch,
                                large_game_roles: tuple[Role, ...]) -> None:
        """Generated indices should be random."""
        inputs = [0, 2, 20, 1]
        monkeypatch.setattr("builtins.input",
                            override_input([str(i) for i in inputs]))

        result = [get_player(is_user=True) for _ in range(3)]

        assert result == [0, 2, 1]
예제 #3
0
    def test_random_excludes_values(
            large_game_roles: tuple[Role, ...]) -> None:
        """Generated indices should exclude specified values."""
        exclude = (6, 7, 8)

        result = [
            get_player(is_user=False, exclude=exclude) for _ in range(10)
        ]

        assert not set(result).intersection(exclude)
        assert result == [9, 9, 0, 4, 11, 10, 9, 4, 10, 5]
예제 #4
0
    def test_user_excludes_values(monkeypatch: pytest.MonkeyPatch,
                                  large_game_roles: tuple[Role, ...]) -> None:
        """Generated indices should exclude specified values."""
        exclude = (6, 7, 8)
        inputs = [0, 20, 4, 7, 5, 6]
        monkeypatch.setattr("builtins.input",
                            override_input([str(i) for i in inputs]))

        result = [get_player(is_user=True, exclude=exclude) for _ in range(3)]

        assert not set(result).intersection(exclude)
        assert result == [0, 4, 5]
예제 #5
0
파일: seer.py 프로젝트: TylerYep/wolfbot
    def awake_init(cls, player_index: int, game_roles: list[Role]) -> Seer:
        """Initializes Seer - either sees 2 center cards or 1 player card."""
        is_user = const.IS_USER[player_index]
        if const.NUM_CENTER > 1:
            if is_user:
                logger.info("Do you want to see 1 player card or 2 center cards?")
                choose_center = bool(get_numeric_input(1, 3) - 1)
            else:
                # Pick two center cards more often, because
                # that generally yields higher win rates.
                choose_center = weighted_coin_flip(const.CENTER_SEER_PROB)

            if choose_center:
                peek_ind1 = get_center(is_user)
                peek_ind2 = get_center(is_user, (peek_ind1,))
                peek_char1 = game_roles[peek_ind1]
                peek_char2 = game_roles[peek_ind2]
                logger.debug(
                    f"[Hidden] Seer sees that Center {peek_ind1 - const.NUM_PLAYERS} "
                    f"is a {peek_char1}, Center {peek_ind2 - const.NUM_PLAYERS} "
                    f"is a {peek_char2}."
                )
                if is_user:
                    logger.info(
                        f"You see that Center {peek_ind1 - const.NUM_PLAYERS} "
                        f"is a {peek_char1}, and "
                        f"Center {peek_ind2 - const.NUM_PLAYERS} is a {peek_char2}.",
                        cache=True,
                    )
                return cls(
                    player_index, (peek_ind1, peek_char1), (peek_ind2, peek_char2)
                )

        peek_ind = get_player(is_user, (player_index,))
        peek_char = game_roles[peek_ind]
        logger.debug(f"[Hidden] Seer sees that Player {peek_ind} is a {peek_char}.")
        if is_user:
            logger.info(f"You see that Player {peek_ind} is a {peek_char}.", cache=True)
        return cls(player_index, (peek_ind, peek_char))
예제 #6
0
def get_voting_result(
    player_objs: tuple[Player, ...], all_predictions: tuple[tuple[Role, ...], ...]
) -> tuple[tuple[Role, ...], tuple[int, ...], tuple[int, ...]]:
    """
    Creates confidence levels for each prediction and takes most common role guess
    array as the final guess for that index.

    - guess_histogram stores counts of prediction arrays.
    - wolf_votes stores individual votes for Wolves.
    """
    wolf_votes = [0] * const.NUM_PLAYERS
    if const.INTERACTIVE_MODE and const.INFLUENCE_PROB == 1:
        # Convince other players to vote with you.
        logger.info(
            "\nAll players trust you. Who should everyone vote for? "
            "(If you think there are no Wolves, vote for yourself.)"
        )
        vote_ind = get_player(is_user=True)
        if vote_ind == const.IS_USER.index(True):
            wolf_votes = [1] * const.NUM_PLAYERS
            player_votes = [
                (i + 1) % const.NUM_PLAYERS for i in range(const.NUM_PLAYERS)
            ]
        else:
            wolf_votes[vote_ind] += const.NUM_PLAYERS
            player_votes = [vote_ind] * const.NUM_PLAYERS
    else:
        player_votes = []
        for i, prediction in enumerate(all_predictions):
            vote_ind = player_objs[i].vote(prediction)
            wolf_votes[vote_ind] += 1
            player_votes.append(vote_ind)

    assert len(player_votes) == const.NUM_PLAYERS
    logger.info(f"\nVote Array: {wolf_votes}\n")
    [(avg_role_guesses, _)] = Counter(all_predictions).most_common(1)
    max_votes = max(wolf_votes)
    guessed_wolf_inds = [i for i, count in enumerate(wolf_votes) if count == max_votes]
    return avg_role_guesses, tuple(guessed_wolf_inds), tuple(player_votes)
예제 #7
0
    def awake_init(cls, player_index: int,
                   game_roles: list[Role]) -> Doppelganger:
        """Initializes Doppelganger - learns new role."""
        from wolfbot.roles import get_role_obj

        is_user = const.IS_USER[player_index]
        choice_ind = get_player(is_user, (player_index, ))
        choice_char = game_roles[choice_ind]
        logger.debug(f"[Hidden] Doppelganger copies Player {choice_ind} "
                     f"and becomes a {choice_char}.")
        if is_user:
            logger.info(
                f"You copied Player {choice_ind} and are now a {choice_char}!",
                cache=True,
            )
        # Temporarily set Doppelganger in game_roles to the new role
        # so she wakes up with the other characters.
        game_roles[player_index] = choice_char
        if choice_char in (Role.WOLF, Role.MASON):
            get_role_obj(choice_char).awake_init(player_index, game_roles)

        # else do switches later
        return cls(player_index, choice_ind, choice_char)
예제 #8
0
    def test_generates_random_indices(
            large_game_roles: tuple[Role, ...]) -> None:
        """Generated indices should be random."""
        result = [get_player(is_user=False) for _ in range(10)]

        assert result == [6, 6, 0, 4, 8, 7, 6, 4, 7, 5]