Ejemplo n.º 1
0
    def test_cards_can_be_compared_before_a_suit_is_led(self) -> None:
        players = [Player(), Player(), Player(), Player()]
        deal = Deal(players=players, bidder_index=0)
        trick = Trick(deal=deal, leading_player_index=0)

        # The queen should be consider higher, as we are assuming we are not
        # dealing with a trump suit, given that no trump suit was even specified yet.
        self.assertEqual(
            1,
            trick.compare_cards(Card(suit=Suit.HEARTS, rank=Rank.JACK),
                                Card(suit=Suit.HEARTS, rank=Rank.QUEEN)))

        # Unrelated cards cannot be compared properly without a trump suit or a led suit.
        self.assertEqual(
            0,
            trick.compare_cards(
                Card(suit=Suit.HEARTS, rank=Rank.JACK),
                Card(suit=Suit.SPADES, rank=Rank.ACE),
            ))

        deal.trump_suit = Suit.HEARTS

        # Now that we have a trump suit defined, the higher trump should rank higher.
        self.assertEqual(
            -1,
            trick.compare_cards(Card(suit=Suit.HEARTS, rank=Rank.JACK),
                                Card(suit=Suit.HEARTS, rank=Rank.QUEEN)))
Ejemplo n.º 2
0
    def test_cards_can_be_compared_after_trump_suit_is_led(self) -> None:
        players = [Player(), Player(), Player(), Player()]
        players[0].hand = {Card(suit=Suit.SPADES, rank=Rank.QUEEN)}
        deal = Deal(players=players, bidder_index=0, trump_suit=Suit.SPADES)
        trick = Trick(deal=deal, leading_player_index=0)

        # The trick starts with the trump suit.
        trick.play(Card(suit=Suit.SPADES, rank=Rank.QUEEN))

        # The Johnny scores higher than the ten, in contrast to the normal order.
        # Same thing for the Nerf (9).
        self.assertEqual(
            -1,
            trick.compare_cards(
                Card(suit=Suit.SPADES, rank=Rank.JACK),
                Card(suit=Suit.SPADES, rank=Rank.TEN),
            ))
        self.assertEqual(
            -1,
            trick.compare_cards(
                Card(suit=Suit.SPADES, rank=Rank.NINE),
                Card(suit=Suit.SPADES, rank=Rank.TEN),
            ))

        # Any trump card will rank higher than any non-trump card.
        for first_rank, second_rank, second_suit in product(Rank, Rank, Suit):
            # We are testing non-trump cards for the second card, so skip the trump cards.
            if second_suit == deal.trump_suit:
                continue

            self.assertEqual(
                -1,
                trick.compare_cards(
                    Card(suit=Suit.SPADES, rank=first_rank),
                    Card(suit=second_suit, rank=second_rank),
                ),
            )

        # Any two cards that both aren't trump will be incomparable.
        for first_rank, first_suit, second_rank, second_suit in product(
                Rank, Suit, Rank, Suit):
            # If the suits match or any equals trump, skip.
            if first_suit == deal.trump_suit or second_suit == deal.trump_suit or first_suit == second_suit:
                continue

            self.assertEqual(
                0,
                trick.compare_cards(Card(suit=first_suit, rank=first_rank),
                                    Card(suit=second_suit, rank=second_rank)))
Ejemplo n.º 3
0
    def test_cards_can_be_compared_if_non_trump_suit_is_led(self) -> None:
        players = [Player(), Player(), Player(), Player()]
        players[0].hand = {Card(suit=Suit.SPADES, rank=Rank.QUEEN)}
        deal = Deal(players=players, bidder_index=0, trump_suit=Suit.CLUBS)
        trick = Trick(deal=deal, leading_player_index=0)

        # The led suit will be Spades, but the trump suit is Clubs.
        trick.play(Card(suit=Suit.SPADES, rank=Rank.QUEEN))

        # Any trump card will rank higher than any non-trump card, regardless whether
        # that other card was in the led suit or not.
        for first_rank, second_rank, second_suit in product(Rank, Rank, Suit):
            # We are testing non-trump cards for the second card, so skip the trump cards.
            if second_suit == deal.trump_suit:
                continue

            assert deal.trump_suit is not None
            self.assertEqual(
                -1,
                trick.compare_cards(
                    Card(suit=deal.trump_suit, rank=first_rank),
                    Card(suit=second_suit, rank=second_rank),
                ),
            )

        # Any card in the led suit beats any other card that is not trump or in the led suit.
        for first_rank, second_rank, second_suit in product(Rank, Rank, Suit):
            # We are testing second cards that are non-trump and not the led suit, so skip those.
            if second_suit == deal.trump_suit or second_suit == trick.led_suit:
                continue

            assert trick.led_suit is not None
            self.assertEqual(
                -1,
                trick.compare_cards(
                    Card(suit=trick.led_suit, rank=first_rank),
                    Card(suit=second_suit, rank=second_rank),
                ),
            )

        # Two cards both in the led suit will obey the regular order.
        self.assertEqual(
            -1,
            trick.compare_cards(
                Card(suit=Suit.SPADES, rank=Rank.QUEEN),
                Card(suit=Suit.SPADES, rank=Rank.JACK),
            ))
        self.assertEqual(
            -1,
            trick.compare_cards(
                Card(suit=Suit.SPADES, rank=Rank.TEN),
                Card(suit=Suit.SPADES, rank=Rank.NINE),
            ))

        # Two cards that both are neither trump nor the led suit will be incomparable.
        for first_rank, first_suit, second_rank, second_suit in product(
                Rank, Suit, Rank, Suit):
            if first_suit in [
                    deal.trump_suit, trick.led_suit
            ] or second_suit in [deal.trump_suit, trick.led_suit]:
                continue

            self.assertEqual(
                0,
                trick.compare_cards(
                    Card(suit=first_suit, rank=first_rank),
                    Card(suit=second_suit, rank=second_rank),
                ),
            )