Exemplo n.º 1
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
Exemplo n.º 2
0
def test_advanceTurn_onlyOnePlayerRemains_roundEnds(started_round):
    winner = started_round.players[-1]
    for player in started_round.players:
        if player is not winner:
            player.eliminate()
    state: loveletter.round.RoundEnd = force_next_turn(started_round)
    assert state.type == RoundState.Type.ROUND_END
    assert state.reason == loveletter.round.RoundEnd.Reason.ONE_PLAYER_STANDING
    assert started_round.ended
    assert state.winner is winner
Exemplo n.º 3
0
def test_roundEnd_totalTie_allContendersWin(started_round: Round, loser):
    losers = {loser} if loser is not None else set()
    winners = set(started_round.players) - losers

    started_round.deck.stack.clear()
    for player in winners:
        give_card(player, cards.Princess(), replace=True)
        player.discarded_cards = [cards.Guard()]
    for loser in losers:
        give_card(loser, cards.Guard(), replace=True)

    end: loveletter.round.RoundEnd = force_next_turn(started_round)
    assert end.type == RoundState.Type.ROUND_END
    assert end.tie_contenders == winners
    assert end.winners == winners
    if len(winners) > 1:
        with pytest.raises(valid8.ValidationError):
            # noinspection PyStatementEffect
            end.winner
Exemplo n.º 4
0
def test_advanceTurn_emptyDeck_roundEndsWithLargestCardWinner(
        started_round: Round, set_aside):
    started_round.deck = Deck([], set_aside=set_aside)
    increasing_cards = [
        cards.Guard(),
        cards.Priest(),
        cards.Baron(),
        cards.Princess()
    ]
    for player, card in zip(started_round.players, increasing_cards):
        give_card(player, card, replace=True)
    # noinspection PyUnboundLocalVariable
    winner = player

    state: loveletter.round.RoundEnd = force_next_turn(started_round)
    assert state.type == RoundState.Type.ROUND_END
    assert state.reason == loveletter.round.RoundEnd.Reason.EMPTY_DECK
    assert state.winners == frozenset({winner})
    assert state.winner is winner
Exemplo n.º 5
0
def test_roundEnd_cardTie_maxDiscardedValueWins(started_round: Round,
                                                from_player):
    discard_piles = (
        [cards.Priest(), cards.Prince()],  # total value: 7
        [cards.Guard(), cards.Countess()],  # total value: 8  -- best; offset=1
        [cards.Guard(), cards.Spy()],  # total value: 1
        [cards.Spy()],  # total value: 0
    )
    winner = started_round.get_player(from_player, offset=1)
    card_in_common = CardType.GUARD  # everyone will have this card in hand

    started_round.deck.stack.clear()
    for player, discard_pile in zip(
            cycle_from(started_round.players, from_item=from_player, times=1),
            discard_piles,
    ):
        give_card(player, card_from_card_type(card_in_common), replace=True)
        player.discarded_cards = discard_pile

    end: loveletter.round.RoundEnd = force_next_turn(started_round)
    assert end.type == RoundState.Type.ROUND_END
    assert end.winner is winner
    assert end.tie_contenders == frozenset(started_round.players)  # everyone
Exemplo n.º 6
0
def test_spy_noOnePlayed_noOneGetsPoint(started_round: Round):
    for player in started_round.players[1:]:
        player.eliminate()
    force_next_turn(started_round)
    assert cards.Spy.collect_extra_points(started_round) == {}
Exemplo n.º 7
0
def test_prevPlayer_deadPlayer_matchesTurnDirection(started_round: Round):
    before = started_round.current_player
    force_next_turn(started_round)
    after = started_round.current_player or started_round.state.winner
    after.eliminate()
    assert started_round.previous_player(after) is before
Exemplo n.º 8
0
def test_nextPlayer_deadPlayer_matchesTurnDirection(started_round: Round):
    before = started_round.current_player
    before.eliminate()
    force_next_turn(started_round)
    after = started_round.current_player or started_round.state.winner
    assert started_round.next_player(before) is after
Exemplo n.º 9
0
def test_nextPrevPlayer_matchesTurnDirection(started_round: Round):
    before = started_round.current_player
    force_next_turn(started_round)
    after = started_round.current_player
    assert started_round.next_player(before) is after
    assert started_round.previous_player(after) is before
Exemplo n.º 10
0
def test_advanceTurn_dealsCard(started_round: Round):
    next_player = started_round.next_player(started_round.current_player)
    with unittest.mock.patch.object(started_round, "deal_card") as mock:
        force_next_turn(started_round)
        mock.assert_called_once_with(next_player)