Example #1
0
def test_spy_onePlayed_getsPoint(started_round: Round):
    first = started_round.current_player
    play_card(first, cards.Spy())
    for player in started_round.players:
        if player is not first:
            player.eliminate()
    started_round.advance_turn()
    assert cards.Spy.collect_extra_points(started_round) == {first: 1}
Example #2
0
def test_handmaid_immunityLastsOneFullRotation(started_round: Round):
    immune_player = started_round.current_player
    play_card(immune_player, cards.Handmaid())
    started_round.advance_turn()
    while (current := started_round.current_player) is not immune_player:
        assert immune_player.immune
        play_mock_move(current)
        started_round.advance_turn()
Example #3
0
def test_spy_onePlayed_doesNotGetPointIfDead(started_round: Round):
    first = started_round.current_player
    second = started_round.next_player(first)
    play_card(first, cards.Spy())
    for player in started_round.players:
        if player is not second:
            player.eliminate()
    started_round.advance_turn()
    assert cards.Spy.collect_extra_points(started_round) == {}
Example #4
0
def test_spy_twoPlayed_noOneGetsPoint(started_round: Round):
    first = started_round.current_player
    second = started_round.next_player(first)
    play_card(first, cards.Spy())
    started_round.advance_turn()
    play_card(second, cards.Spy())
    for player in started_round.players[1:]:
        player.eliminate()
    started_round.advance_turn()
    assert cards.Spy.collect_extra_points(started_round) == {}
Example #5
0
def test_targetCard_againstImmunePlayer_raises(started_round: Round, card):
    immune_player = started_round.current_player
    play_card(immune_player, cards.Handmaid())
    # should be immune now
    started_round.advance_turn()
    opponent = started_round.current_player
    with play_card_with_cleanup(opponent, card) as move:
        target_step = next(move)
        with pytest.raises(valid8.ValidationError):
            target_step.choice = immune_player
            move.send(target_step)
Example #6
0
def test_handmaid_immunityLastsOneFullRotation_withDeaths(
        started_round: Round):
    immune_player = started_round.current_player
    play_card(immune_player, cards.Handmaid())
    started_round.advance_turn()
    killer = started_round.current_player
    for player in set(started_round.players) - {immune_player, killer}:
        assert immune_player.immune
        player.eliminate()
    assert immune_player.immune
    force_next_turn(started_round)
    assert not immune_player.immune
Example #7
0
def make_round_mock():
    round_ = Round(2)
    round_.start()
    player = round_.current_player
    round_mock = MagicMock(wraps=round_)
    round_mock.current_player = round_mock.state.current_player = player
    type(round_mock).living_players = PropertyMock(
        side_effect=lambda: round_.living_players)
    round_mock.players = round_.players
    for p in round_mock.players:
        p.round = round_mock
    return round_mock
Example #8
0
def start_round_from_player_cards(*player_cards: Sequence[cards.Card],
                                  first_player: int,
                                  set_aside=None):
    """
    Create a round that will deal to each player the specified sequence of cards.

    The deck is built in a way so that player i starts with player_cards[i][0] and
    is dealt the cards in player_cards[i][1:] in order at each successive turn.
    This assumes that no player is eliminated before the last card in player_cards[i]
    is dealt to them.

    :param player_cards: A varargs sequence of card sequences that each player
                         will receive during the round. The first list corresponds
                         to player 0, then player 1, and so on.
    :param first_player: ID (index) of the first player to play in the round. This is
                         (also) needed to build the deck so that player_cards[i] always
                         corresponds to player i (*not* the i-th player to play).
    :param set_aside: Which card to set aside in the deck. Default is a new instance of
                      :class:`cards.Princess`.
    :return: A round with the number of players and deck deduced from ``player_cards``.
    """
    player_cards = player_cards[first_player:] + player_cards[:first_player]
    stack = list(mitt.roundrobin(*player_cards))[::-1]
    deck = Deck(stack, set_aside=set_aside or cards.Princess())
    round = Round(len(player_cards), deck=deck)
    round.start(first_player=round.players[first_player])
    return round
Example #9
0
def test_priest_validOpponent_showsCard(started_round: Round):
    player = started_round.current_player
    opponent = started_round.next_player(player)
    move = play_card(player, cards.Priest())
    target_step = next(move)
    target_step.choice = opponent
    result, *_ = send_gracious(move, target_step)
    assert len(_) == 0
    assert isinstance(result, mv.ShowOpponentCard)
    move.close()
    assert result.opponent is opponent
Example #10
0
def test_chancellor_oneCardInDeck_onlyUsesOneCard(started_round: Round):
    deck_card, set_aside = cards.Spy(), cards.Princess()
    started_round.deck = Deck([deck_card], set_aside=set_aside)
    player = started_round.current_player
    move = play_card(player, cards.Chancellor())
    card_choice = next(move)
    assert len(card_choice.options) == 2
    assert set(card_choice.options) == {player.hand.card, deck_card}
    assert started_round.deck.set_aside is set_aside

    # cleanup to avoid exception when .close() is called
    autofill_move(move, start_step=card_choice)
Example #11
0
def test_baron_equalOpponent_noneEliminated(started_round: Round, card):
    player = started_round.current_player
    opponent = started_round.next_player(player)
    give_card(player, card, replace=True)
    give_card(opponent, card, replace=True)

    move = play_card(player, cards.Baron())
    target_step = next(move)
    target_step.choice = opponent
    comparison, *_ = send_gracious(move, target_step)
    move.close()
    assert len(_) == 0
    assert isinstance(comparison, mv.CardComparison)

    assert player.alive
    assert opponent.alive
Example #12
0
def test_baron_strongerOpponent_selfEliminated(started_round: Round, card1,
                                               card2):
    player = started_round.current_player
    opponent = started_round.next_player(player)
    give_card(player, card1, replace=True)
    give_card(opponent, card2, replace=True)

    move = play_card(player, cards.Baron())
    target_step = next(move)
    target_step.choice = opponent
    comparison, elimination, *_ = send_gracious(move, target_step)
    move.close()
    assert len(_) == 0
    assert isinstance(comparison, mv.CardComparison)
    assert isinstance(elimination, mv.PlayerEliminated)
    assert comparison.opponent is opponent
    assert elimination.eliminated is player

    assert not player.alive
    assert opponent.alive
Example #13
0
def test_prince_againstPrincess_kills(started_round: Round):
    player = started_round.current_player
    victim = started_round.next_player(player)
    give_card(victim, cards.Princess(), replace=True)
    victim_card = victim.hand.card

    deck_before = list(started_round.deck)
    move = play_card(player, cards.Prince())
    target_step = next(move)
    target_step.choice = victim
    results = send_gracious(move, target_step)
    assert tuple(map(type, results)) == (
        mv.CardDiscarded,
        mv.PlayerEliminated,
    )
    assert results[0].target is victim
    assert results[0].discarded is victim_card
    assert results[1].eliminated is victim
    assert not victim.alive
    assert CardType(victim.discarded_cards[-1]) == CardType.PRINCESS
    assert list(started_round.deck) == deck_before
Example #14
0
def force_end_round(game_round: Round):
    game_round.state = EndState(frozenset(game_round.players))
Example #15
0
def autoplay_round(game_round: Round):
    if not game_round.started:
        game_round.start()
    while not game_round.ended:
        play_random_move(game_round.current_player)
Example #16
0
def new_round(num_players) -> Round:
    return Round(num_players)
Example #17
0
def started_round(new_round: Round):
    new_round.start()
    return new_round
Example #18
0
def force_next_turn(game_round: Round):
    turn: Turn = game_round.state
    assert turn.type == RoundState.Type.TURN
    turn._set_stage(Turn.Stage.COMPLETED)
    return game_round.advance_turn()