Beispiel #1
0
    def test_play_reversed(self):
        """
        Tests for a game which reverses the order into negative numbers.
        """
        pa = player.RandomAiPlayer("Player A")
        pb = player.RandomAiPlayer("Player B")
        pc = player.RandomAiPlayer("Player C")

        u = uno.Uno([pa, pb, pc])
        pa.hand = [
            unocard.UnoCard(1, 7),
            unocard.UnoCard(1, 7),
            unocard.UnoCard(1, 7)
        ]  # 7 of Diamonds
        pb.hand = [unocard.ReverseActionCard(1),
                   unocard.ReverseActionCard(1)]  # 10 of Diamonds
        pc.hand = [unocard.UnoCard(1, 9),
                   unocard.UnoCard(1, 9)]  # 9 of Diamonds
        u.play()

        # This game should have resulted in 5 cards played, in order:
        self.assertEqual(5, len(u.pile))
        self.assertEqual(7, u.pile[0].rank)
        self.assertEqual(10, u.pile[1].rank)
        self.assertEqual(7, u.pile[2].rank)
        self.assertEqual(9, u.pile[3].rank)
        self.assertEqual(10, u.pile[4].rank)
Beispiel #2
0
    def test_suggestACard(self):
        """
        Tests the suggestACard method of RankThenSuitAiPlayer.
        """
        p = player.RankThenSuitAiPlayer("Test Player")
        c_8ofDiamonds = unocard.UnoCard(1, 8)
        c_7ofHearts = unocard.UnoCard(2, 7)
        c_KofDiamonds = unocard.WildUnoCard(1)
        c_AofDiamonds = unocard.WildDrawFourActionCard(1)
        p.setStartingHand([c_8ofDiamonds, c_7ofHearts])

        # Tests than any card is suggested when there is none in the pile.
        card = p.suggestACard(None, 5)
        self.assertTrue(card != None)
        self.assertEqual(2, len(p.hand))  # Card should not have been removed.

        # This matches two cards, but should favor the matching rank.
        topCard = Card(alt="7D")  # 7 of Diamonds
        card = p.suggestACard(topCard, 5)
        self.assertEqual(c_7ofHearts, card)  # Should be 7 of Hearts
        self.assertEqual(2, len(p.hand))  # Card should not have been removed.

        # This matches three cards, but should favor one non-wild.
        p.setStartingHand(
            [c_KofDiamonds, c_AofDiamonds, c_8ofDiamonds, c_7ofHearts])
        topCard = Card(alt="5D")  # 5 of Diamonds
        card = p.suggestACard(topCard, 5)
        self.assertEqual(c_8ofDiamonds, card)  # Should be 8 of Diamonds
        self.assertEqual(4, len(p.hand))  # Card should not have been removed.

        # This matches only the wild card.
        p.setStartingHand([c_8ofDiamonds, c_KofDiamonds, c_7ofHearts])
        topCard = Card(alt="2C")  # 2 of Clubs
        card = p.suggestACard(topCard, 5)
        self.assertEqual(c_KofDiamonds, card)  # Should be K of Diamonds
        self.assertEqual(3, len(p.hand))  # Card should not have been removed.

        # This matches only the wild draw four card.
        p.setStartingHand([c_8ofDiamonds, c_AofDiamonds, c_7ofHearts])
        topCard = Card(alt="2C")  # 2 of Clubs
        card = p.suggestACard(topCard, 5)
        self.assertEqual(c_AofDiamonds, card)  # Should be A of Diamonds
        self.assertEqual(3, len(p.hand))  # Card should not have been removed.

        # This matches nothing, but some card should be suggested.
        p.setStartingHand([c_8ofDiamonds, c_7ofHearts])
        topCard = Card(alt="2C")  # 2 of Clubs
        card = p.suggestACard(topCard, 5)
        self.assertTrue(card != None)
        self.assertEqual(2, len(p.hand))  # Card should not have been removed.
Beispiel #3
0
    def test_play_drawExtraCards(self):
        """
        Tests for a game where a player has to draw extra cards.
        """
        pa = player.RandomAiPlayer("Player A")
        pb = player.RandomAiPlayer("Player B")
        pc = player.RandomAiPlayer("Player C")

        u = uno.Uno([pa, pb, pc])
        pa.hand = [unocard.UnoCard(1, 7)]  # 7 of Diamonds
        pb.hand = [unocard.DrawTwoActionCard(1),
                   unocard.DrawTwoActionCard(1)]  # Q of Diamonds
        pc.hand = [unocard.UnoCard(1, 9),
                   unocard.UnoCard(1, 9)]  # 9 of Diamonds

        # The deck will start with certain cards meant to be drawn by certain players.
        u.deck[0] = unocard.UnoCard(1, 7)
        u.deck[1] = unocard.UnoCard(1, 7)
        u.deck[2] = unocard.UnoCard(1, 7)
        u.deck[3] = unocard.UnoCard(1, 7)
        u.deck[4] = unocard.UnoCard(1, 9)
        u.deck[5] = unocard.UnoCard(1, 9)
        u.deck[6] = unocard.UnoCard(0, 2)  # 2 of Clubs should not be drawn

        u.gameState.numExtraCardDraw = 4  # Start with drawing 4 cards.
        u.play()

        # This game should have resulted in 5 cards played, in order:
        self.assertEqual(5, len(u.pile))
        self.assertEqual(7, u.pile[0].rank)
        self.assertEqual(12, u.pile[1].rank)
        self.assertEqual(9, u.pile[2].rank)
        self.assertEqual(7, u.pile[3].rank)
        self.assertEqual(12, u.pile[4].rank)

        # Top card of deck should be 2 of clubs.
        self.assertEqual(2, u.deck[0].rank)

        # Player A and C should both end with 3 cards.
        self.assertEqual(3, len(pa.hand))
        self.assertEqual(3, len(pc.hand))
Beispiel #4
0
    def test_play_normalRounds(self):
        """
        Tests for the play method in a normal game that last 4 rounds.
        """
        pa = player.RandomAiPlayer("Player A")
        pb = player.RandomAiPlayer("Player B")
        pc = player.RandomAiPlayer("Player C")

        u = uno.Uno([pa, pb, pc])
        pa.hand = [unocard.UnoCard(1, 7),
                   unocard.UnoCard(1, 7)]  # 7 of Diamonds
        pb.hand = [unocard.UnoCard(1, 8),
                   unocard.UnoCard(1, 8)]  # 8 of Diamonds
        pc.hand = [unocard.UnoCard(1, 9),
                   unocard.UnoCard(1, 9)]  # 9 of Diamonds
        u.play()

        # This game should have resulted in 4 cards played, in order:
        self.assertEqual(4, len(u.pile))
        self.assertEqual(7, u.pile[0].rank)
        self.assertEqual(8, u.pile[1].rank)
        self.assertEqual(9, u.pile[2].rank)
        self.assertEqual(7, u.pile[3].rank)