Exemplo n.º 1
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.
Exemplo n.º 2
0
                return

            # If the card was not playable, we notify the player, and try again.
            else:
                player.notifyNotAcceptableCard(card)

        # We got here because either the player ran out of attempts or chose to draw
        # explicitly. Draw a card, so long as the deck has more cards.
        if len(self.deck) > 0:
            player.addCardToHand(self.deck.pop(0))


"""
This sets up and starts a game of Uno.
"""
if __name__ == '__main__':
    p = []
    p.append(a5_player.HumanConsolePlayer())
    p.append(a5_player.RandomAiPlayer("HAL 9000"))
    p.append(a5_player.RandomAiPlayer("WOPR"))
    p.append(a5_player.RandomAiPlayer("Skynet"))
    p.append(a5_player.RankThenSuitAiPlayer("IBM WATSON"))

    # TODO: Students, after you implement the RankThenSuitAiPlayer, add a 5th
    # player to the game using your new RankThenSuitAiPlayer implementation.  This
    # should result in one human player, three random AI players and one "smarter"
    # rank-then-suit AI player.

    u = Uno(p)
    u.play()
Exemplo n.º 3
0
                return

            # If the card was not playable, we notify the player, and try again.
            else:
                player.notifyNotAcceptableCard(card)

        # We got here because either the player ran out of attempts or chose to draw
        # explicitly. Draw a card, so long as the deck has more cards.
        if len(self.deck) > 0:
            player.addCardToHand(self.deck.pop(0))


"""
This sets up and starts a game of Uno.
"""
if __name__ == '__main__':
    p = []
    p.append(a5_player.HumanConsolePlayer())
    p.append(a5_player.RandomAiPlayer("HAL 9000"))
    p.append(a5_player.RandomAiPlayer("WOPR"))
    p.append(a5_player.RandomAiPlayer("Skynet"))
    p.append(a5_player.RankThenSuitAiPlayer("lil pump"))

    # TODO: Students, after you implement the RankThenSuitAiPlayer, add a 5th
    # player to the game using your new RankThenSuitAiPlayer implementation.  This
    # should result in one human player, three random AI players and one "smarter"
    # rank-then-suit AI player.

    u = Uno(p)
    u.play()
Exemplo n.º 4
0
            # If the card was not playable, we notify the player, and try again.
            else:
                player.notifyNotAcceptableCard(card)
        
        # We got here because either the player ran out of attempts or chose to draw
        # explicitly. Draw a card, so long as the deck has more cards.
        if len(self.deck) > 0:
            player.addCardToHand(self.deck.pop(0))




"""
This sets up and starts a game of Uno.
"""
if __name__ == '__main__': 
    p = []
    p.append(a5_player.HumanConsolePlayer())
    p.append(a5_player.RandomAiPlayer("HAL 9000"))
    p.append(a5_player.RandomAiPlayer("WOPR"))
    p.append(a5_player.RandomAiPlayer("Skynet"))
    
    # TODO: Students, after you implement the RankThenSuitAiPlayer, add a 5th
    # player to the game using your new RankThenSuitAiPlayer implementation.  This
    # should result in one human player, three random AI players and one "smarter"
    # rank-then-suit AI player.
    p.append(a5_player.RankThenSuitAiPlayer("Smartypants"))
    
    u = Uno(p)
    u.play()
Exemplo n.º 5
0
                # Perform any action that the card has on the game state.
                card.performAction(self.gameState)

                # Return so that the player does not draw a card.
                return

            # If the card was not playable, we notify the player, and try again.
            else:
                player.notifyNotAcceptableCard(card)

        # We got here because either the player ran out of attempts or chose to draw
        # explicitly. Draw a card, so long as the deck has more cards.
        if len(self.deck) > 0:
            player.addCardToHand(self.deck.pop(0))


"""
This sets up and starts a game of Uno.
"""
if __name__ == '__main__':
    p = []
    p.append(a5_player.HumanConsolePlayer())
    p.append(a5_player.RandomAiPlayer("HAL 9000"))
    p.append(a5_player.RandomAiPlayer("WOPR"))
    p.append(a5_player.RandomAiPlayer("Skynet"))
    p.append(a5_player.RankThenSuitAiPlayer("SmartAIPlayer"))

    u = Uno(p)
    u.play()