def test_start_emptyDeckUponStart_raises(new_round: Round): new_round.deck = Deck( [cards.Guard() for _ in range(new_round.num_players + 1)], set_aside=cards.Princess(), ) with pytest.raises(valid8.ValidationError): new_round.start()
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
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)
def __init__(self, num_players: int, deck: Deck = None): """ Initialise a new round. :param num_players: Number of players in the round. :param deck: Initial deck to start with. None means use the standard deck. """ players = [RoundPlayer(self, i) for i in range(num_players)] super().__init__(players) self.deck = deck if deck is not None else Deck.from_counts() self.discard_pile = DiscardPile([])
def test_prince_emptyDeck_dealsSetAsideCard(current_player: RoundPlayer, target: RoundPlayer, set_aside: cards.Card): current_player.round.deck = Deck([], set_aside=set_aside) give_card(target, CardMockCases().case_generic(), replace=True) move = play_card(current_player, cards.Prince()) target_step = next(move) target_step.choice = target send_gracious(move, target_step) assert target.hand.card is set_aside assert current_player.round.deck.set_aside is None assert not current_player.round.deck
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
def test_start_insufficientCardsInDeck_raises(new_round: Round): new_round.deck = Deck([cards.Guard() for _ in new_round.players], None) with pytest.raises(valid8.ValidationError): new_round.start()
def case_full_deck(self): return Deck.from_counts(STANDARD_DECK_COUNTS)
def case_random_deck(self, counts) -> Deck: return Deck.from_counts(counts)
def case_empty_deck(self): return Deck.from_counts(Counter())
def test_deck_containsSetAside(): deck = Deck([], set_aside=(set_aside := cards.Princess()))
def test_deckFromCounts_default_isStandardDeck(): deck = Deck.from_counts() assert Counter(map(CardType, deck)) == STANDARD_DECK_COUNTS