def test_all_cards_are_dealt(self): expected_cards = [ Card(rank, suit) for rank in ALL_RANKS for suit in ALL_SUITS ] player_hands = CardDeck().shuffle_and_deal_hands() actual_cards = [card for hand in player_hands for card in hand] assert set(actual_cards) == set(expected_cards)
def sorted_hand(hand: List[Card], game_mode: Optional[GameMode]): if game_mode is None: trumpcards = trump_cards(GameMode(PARTNER_MODE, BELLS)) else: trumpcards = trump_cards(game_mode) trumps_in_hand = [trump for trump in trumpcards if trump in hand] bells = [ Card(rank, BELLS) for rank in ALL_RANKS if (rank, BELLS) in hand and (rank, BELLS) not in trumpcards ] hearts = [ Card(rank, HEARTS) for rank in ALL_RANKS if (rank, HEARTS) in hand and (rank, HEARTS) not in trumpcards ] leaves = [ Card(rank, LEAVES) for rank in ALL_RANKS if (rank, LEAVES) in hand and (rank, LEAVES) not in trumpcards ] acorns = [ Card(rank, ACORNS) for rank in ALL_RANKS if (rank, ACORNS) in hand and (rank, ACORNS) not in trumpcards ] sorted_hand = trumps_in_hand + acorns + leaves + hearts + bells return sorted_hand
def __init__(self): self.cards = [Card(rank, suit) for rank in ALL_RANKS for suit in ALL_SUITS]
def trump_cards(game_mode: GameMode): if game_mode.game_type == PARTNER_MODE: return [ Card(OBER, ACORNS), Card(OBER, LEAVES), Card(OBER, HEARTS), Card(OBER, BELLS), Card(UNTER, ACORNS), Card(UNTER, LEAVES), Card(UNTER, HEARTS), Card(UNTER, LEAVES), Card(ACE, HEARTS), Card(TEN, HEARTS), Card(KING, HEARTS), Card(NINE, HEARTS), Card(EIGHT, HEARTS), Card(SEVEN, HEARTS) ] elif game_mode.game_type == WENZ: return [ Card(UNTER, ACORNS), Card(UNTER, LEAVES), Card(UNTER, HEARTS), Card(UNTER, LEAVES) ] elif game_mode.game_type == SOLO: return [ Card(OBER, ACORNS), Card(OBER, LEAVES), Card(OBER, HEARTS), Card(OBER, BELLS), Card(UNTER, ACORNS), Card(UNTER, LEAVES), Card(UNTER, HEARTS), Card(UNTER, LEAVES), Card(ACE, game_mode.suit), Card(TEN, game_mode.suit), Card(KING, game_mode.suit), Card(NINE, game_mode.suit), Card(EIGHT, game_mode.suit), Card(SEVEN, game_mode.suit) ]
def test_card_points_are_points_of_rank(self): suit = random.choice(ALL_SUITS) for rank in ALL_RANKS: assert Card(rank, suit).points() == rank.points()
def test_str_method(self): assert str(Card(OBER, ACORNS)) == "Ober, Acorns" assert str(Card(UNTER, BELLS)) == "Unter, Bells" assert str(Card(SEVEN, HEARTS)) == "Seven, Hearts" assert str(Card(TEN, LEAVES)) == "Ten, Leaves"
def test_trick_points(self): trick = Trick(cards=[Card(OBER, ACORNS), Card(ACE, BELLS), None, None]) assert trick.points() == 14 trick = Trick(cards=[None, None, None, None]) assert trick.points() == 0 trick = Trick(cards=[Card(SEVEN, HEARTS), Card(EIGHT, HEARTS), Card(NINE, HEARTS), Card(SEVEN, LEAVES)]) assert trick.points() == 0 trick = Trick(cards=[Card(SEVEN, HEARTS), Card(KING, ACORNS), Card(ACE, HEARTS), Card(TEN, LEAVES)]) assert trick.points() == 25 trick = Trick(cards=[None, Card(EIGHT, HEARTS), Card(UNTER, HEARTS), Card(UNTER, ACORNS)]) assert trick.points() == 4 cards = [Card(rank=random.choice(ALL_RANKS), suit=random.choice(ALL_SUITS)) for _ in range(4)] trick = Trick(cards=cards) assert trick.points() == sum([card.points() for card in cards])