Beispiel #1
0
    def test_user_center_indices(monkeypatch: pytest.MonkeyPatch,
                                 large_game_roles: tuple[Role, ...]) -> None:
        """Generated indices should be random."""
        inputs = [1, 2, 0, 2]
        monkeypatch.setattr("builtins.input",
                            override_input([str(i) for i in inputs]))

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

        assert result == [13, 14, 12]
Beispiel #2
0
    def test_excludes_values(large_game_roles: tuple[str, ...]) -> None:
        """Generated indices should exclude specified values."""
        exclude = (12, 13)

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

        assert not set(result).intersection(exclude)
        assert result == [14] * 10
Beispiel #3
0
 def awake_init(cls, player_index: int, game_roles: list[Role]) -> Drunk:
     """Initializes Drunk - switches with a card in the center."""
     is_user = const.IS_USER[player_index]
     choice_ind = get_center(is_user)
     logger.debug(
         f"[Hidden] Drunk switches with Center Card {choice_ind - const.NUM_PLAYERS}"
         f" and unknowingly becomes a {game_roles[choice_ind]}.")
     if is_user:
         logger.info("You do not know your new role.", cache=True)
     swap_characters(game_roles, player_index, choice_ind)
     return cls(player_index, choice_ind)
Beispiel #4
0
    def test_user_excludes_values(monkeypatch: pytest.MonkeyPatch,
                                  large_game_roles: tuple[Role, ...]) -> None:
        """Generated indices should exclude specified values."""
        exclude = (12, 13)
        inputs = [2, 0, 4, 1, 2, 2]
        monkeypatch.setattr("builtins.input",
                            override_input([str(i) for i in inputs]))

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

        assert not set(result).intersection(exclude)
        assert result == [14] * 3
Beispiel #5
0
    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))
Beispiel #6
0
    def awake_init(cls, player_index: int, game_roles: list[Role]) -> Wolf:
        """
        Constructor: original_roles defaults to [] when a player becomes
        a Wolf and realizes it.
        Initializes Wolf - gets Wolf indices and a random center card, if applicable.
        """
        is_user = const.IS_USER[player_index]
        center_index, center_role = None, None
        wolf_indices = find_all_player_indices(game_roles, Role.WOLF)
        if len(wolf_indices) == 1 and const.NUM_CENTER > 0:
            center_index = get_center(is_user)
            center_role = game_roles[center_index]
            if is_user:
                logger.info(
                    f"You see Center {center_index - const.NUM_PLAYERS} "
                    f"is a {center_role}.",
                    cache=True,
                )
        logger.debug(f"[Hidden] Wolves are at indices: {list(wolf_indices)}")
        if is_user:
            logger.info(f"Wolves are at indices: {list(wolf_indices)}",
                        cache=True)

        return cls(player_index, wolf_indices, center_index, center_role)
Beispiel #7
0
    def test_generates_random_indices(
            large_game_roles: tuple[Role, ...]) -> None:
        """Generated indices should be random."""
        result = [get_center(is_user=False) for _ in range(10)]

        assert result == [13, 13, 12, 13, 14, 13, 13, 13, 13, 13]