Exemplo n.º 1
0
def test_countess_playPrinceOrKing_raises(current_player, other_card_type):
    give_card(current_player, cards.Countess(), replace=True)
    give_card(current_player, card := card_from_card_type(other_card_type))

    with assert_state_is_preserved(current_player.round) as mocked_round:
        with pytest.raises(valid8.ValidationError):
            autofill_move(mocked_round.current_player.play_card(card))
Exemplo n.º 2
0
def test_1_prince_victory():
    """
    player1 has a countess, player0 uses a prince to discard himself and get the
    princess and win.
    """
    game_round = start_round_from_player_cards(
        [cards.Prince(), cards.Handmaid(),
         cards.Guard()],
        [cards.Countess(), cards.Priest()],
        set_aside=cards.Princess(),
        first_player=0,
    )
    player0, player1 = game_round.players
    assert tuple(map(CardType,
                     player0.hand)) == (CardType.PRINCE, CardType.HANDMAID)
    assert tuple(map(CardType, player1.hand)) == (CardType.COUNTESS, )
    assert max(game_round.players, key=lambda p: p.hand.card.value) is player1

    (immunity, ) = play_with_choices(player0, CardType.HANDMAID)
    assert immunity.player is player0

    results = play_with_choices(player1, CardType.PRIEST,
                                mv.OpponentChoice.NO_TARGET)
    assert results == ()

    discarded, dealt = play_with_choices(player0, CardType.PRINCE, player0)
    assert CardType(discarded.discarded) == CardType.GUARD
    assert CardType(dealt.dealt) == CardType.PRINCESS

    end = game_round.state
    assert end.type == RoundState.Type.ROUND_END
    assert max(game_round.players, key=lambda p: p.hand.card.value) is player0
    assert end.winner is player0
Exemplo n.º 3
0
def test_countess_choosePrinceOrKing_raises(current_player, other_card_type):
    give_card(current_player, cards.Countess(), replace=True)
    give_card(current_player, other_card :=
              card_from_card_type(other_card_type))

    event = loveletter.round.ChooseCardToPlay(current_player)
    with pytest.raises(valid8.ValidationError):
        event.choice = other_card
Exemplo n.º 4
0
def test_5_baron_suicide():
    """
    player0 has Baron-Baron and everyone else has higher cards, so they die.
    """
    game_round = start_round_from_player_cards(
        [cards.Baron(), cards.Baron()],
        [cards.Countess(), cards.Handmaid(),
         cards.Guard()],
        [cards.Handmaid(), cards.Princess(),
         cards.Guard()],
        first_player=0,
    )
    player0, player1, player2 = game_round.players

    play_random_move(player0)
    assert not game_round.ended
    assert not player0.alive
    assert player1.alive
    assert player2.alive
Exemplo n.º 5
0
def test_countess_playNotPrinceOrKing_noOp(current_player: RoundPlayer,
                                           card_type):
    target = current_player.round.next_player(current_player)
    with assert_state_is_preserved(current_player.round,
                                   allow_mutation={current_player,
                                                   target}) as mocked_round:
        player, target = mocked_round.current_player, mocked_round.players[
            target.id]
        give_card(player, cards.Countess(), replace=True)
        move = play_card(player,
                         card := card_from_card_type(card_type),
                         autofill=False)
        step = None
        for _ in card.steps:
            step = move.send(step)
            if isinstance(step, mv.PlayerChoice):
                step.choice = target
            else:
                step = autofill_step(step)
        send_gracious(move, step)
Exemplo n.º 6
0
def test_4_princess_suicide():
    """
    player1 holds a Princess but has to eliminate themselves because they draw a Prince
    and the opponent is immune.
    """
    game_round = start_round_from_player_cards(
        [cards.Handmaid(), cards.Baron(),
         cards.Guard()],
        [cards.Princess(), cards.Prince(),
         cards.Countess()],
        first_player=0,
    )
    player0, player1 = game_round.players

    play_with_choices(player0, CardType.HANDMAID)
    play_random_move(player1)

    assert game_round.ended
    assert game_round.state.winner is player0
    assert CardType(
        game_round.deck.take()) == CardType.GUARD  # assert no card dealt
Exemplo n.º 7
0
def test_6_guard_win():
    """A chain of Guard eliminations that ends in player 3 winning"""
    game_round = start_round_from_player_cards(
        [cards.King()],
        [cards.Countess(), cards.Guard()],
        [cards.Princess(), cards.Guard()],
        [cards.Guard(), cards.Guard()],
        first_player=1,
    )
    player0, player1, player2, player3 = game_round.players

    play_with_choices(player1, CardType.GUARD, player0, CardType.KING)
    play_with_choices(player2, CardType.GUARD, player1, CardType.COUNTESS)
    play_with_choices(player3, CardType.GUARD, player2, CardType.PRINCESS)

    assert game_round.ended
    assert not player0.alive
    assert not player1.alive
    assert not player2.alive
    assert player3.alive
    assert game_round.state.winner is player3
Exemplo n.º 8
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