示例#1
0
    def test_collect(self):
        player1 = Player("p1")
        player2 = Player("p2")

        player1_cards = [(2, "Spades"), (2, "Hearts")]
        player2_cards = [(4, "Hearts")]

        for card in player1_cards:
            player1.add_card(card)

        for card in player2_cards:
            player2.add_card(card)

        self.assertEqual(0, len(self.empty_deck.get_cards()))
        self.assertEqual(2, len(player1.get_cards()))
        self.assertEqual(1, len(player2.get_cards()))

        self.empty_deck.collect([player1, player2])

        self.assertEqual(3, len(self.empty_deck.get_cards()))

        for card in player1_cards:
            self.assertTrue(card in self.empty_deck.get_cards())

        for card in player2_cards:
            self.assertTrue(card in self.empty_deck.get_cards())
示例#2
0
    def test_give_pot(self):
        table_chips = 5000
        player1 = Player("p1")
        starting_chips = player1.get_chips()

        self.assertEqual(0, self.table.get_chips())
        self.table.add_chips(table_chips)

        self.table.give_pot(player1)
        self.assertEqual(table_chips + starting_chips, player1.get_chips())
示例#3
0
    def test_initializer(self):
        pid = "p1"
        new_player = Player(pid)
        self.assertEqual(0, len(new_player.get_cards()))
        self.assertEqual(pid, new_player.get_ID())

        new_player = Player(pid, self.player_cards)
        self.assertEqual(len(self.player_cards), len(new_player.get_cards()))
        self.assertEqual(pid, new_player.get_ID())
示例#4
0
    def test_deal(self):
        player1 = Player("p1")
        player2 = Player("p2")

        self.assertEqual(52, len(self.full_deck.get_cards()))
        self.assertEqual(0, len(player1.get_cards()))
        self.assertEqual(0, len(player2.get_cards()))

        self.full_deck.deal([player1, player2], 2)

        self.assertEqual(48, len(self.full_deck.get_cards()))
        self.assertEqual(2, len(player1.get_cards()))
        self.assertEqual(2, len(player2.get_cards()))
示例#5
0
    def __init__(self):
        self.state = None
        self.state_history = []
        self.width = 1300
        self.height = 700
        self.window = None
        self.clock = None  # used for fps
        self.game_over = False  # true when game is over
        self.title_image = None  # title image
        self.empty_table = None  # empty table image

        self.cards = Deck()
        self.cards.shuffle()  # O(n)
        self.table = Table()
        self.player = Player('p')
        self.bot = Bot()
示例#6
0
 def setUp(self):
     self.player1 = Player('p1')
     self.player2 = Player('p2')
     self.table = Table()
示例#7
0
class WinningHandTestCase(unittest.TestCase):
    @staticmethod
    def issue_cards(player, cards):
        for card in cards:
            player.add_card(card)

    def setUp(self):
        self.player1 = Player('p1')
        self.player2 = Player('p2')
        self.table = Table()

    def test_printable_dict_of_winners(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        expected_output = str({self.player1.get_ID(): "Three of a kind"})
        stdout_capture = StdoutCapture(
            lambda: winning_hand.printable_dict_of_winners(
                self.table, [self.player1]))
        _, output = stdout_capture.capture()

        self.assertEqual(expected_output, output.strip())

    def test_winner_player1(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Clubs'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.player2, [(4, 'Hearts'),
                                                       (8, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertEqual(
            self.player1,
            winning_hand.winner(self.table, [self.player1, self.player2],
                                printing=False))

    def test_winner_player2(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Clubs'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.player2, [(4, 'Hearts'),
                                                       (4, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        winner, _ = StdoutCapture(lambda: winning_hand.winner(
            self.table, [self.player1, self.player2], printing=True)).capture(
            )
        self.assertEqual(self.player2, winner)

    '''FAIL - Breaks ties by highest card in a player's hand.'''

    # def test_winner_player_high_card_tie(self):
    #     WinningHandTestCase.issue_cards(self.player1, [(2, 'Clubs'), (12, 'Hearts')])
    #     WinningHandTestCase.issue_cards(self.player2, [(2, 'Spades'), (9, 'Clubs')])
    #     WinningHandTestCase.issue_cards(
    #         self.table, [(2, 'Hearts'), (5, 'Diamonds'), (13, 'Spades'), (9, 'Diamonds'), (5, 'Clubs')])
    #
    #     self.assertEqual(self.player2, winning_hand.winner(self.table, [self.player1, self.player2], printing=False))

    def test_get_value_royal_flush(self):
        WinningHandTestCase.issue_cards(self.player1, [(14, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(10, 'Spades'),
                                                     (11, 'Spades'),
                                                     (12, 'Spades'),
                                                     (13, 'Spades'),
                                                     (4, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.ROYAL_FLUSH, self.player1.get_hand())

    def test_get_value_straight_flush(self):
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (7, 'Spades'),
                                                     (8, 'Spades'),
                                                     (4, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.STRAIGHT_FLUSH, self.player1.get_hand())

    def test_get_value_four_of_a_kind(self):
        WinningHandTestCase.issue_cards(self.player1, [(4, 'Hearts'),
                                                       (4, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table,
                                        [(4, 'Spades'), (4, 'Clubs'),
                                         (6, 'Spades'), (2, 'Diamonds'),
                                         (8, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.FOUR_OF_A_KIND, self.player1.get_hand())

    def test_get_value_full_house(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (4, 'Hearts')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (2, 'Clubs')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.FULL_HOUSE, self.player1.get_hand())

    def test_get_value_flush(self):
        WinningHandTestCase.issue_cards(self.player1, [(14, 'Spades'),
                                                       (12, 'Spades')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.FLUSH, self.player1.get_hand())

    def test_get_value_straight(self):
        WinningHandTestCase.issue_cards(self.player1, [(3, 'Clubs'),
                                                       (4, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.STRAIGHT, self.player1.get_hand())

    def test_get_value_three_of_a_kind(self):
        WinningHandTestCase.issue_cards(self.player1, [(6, 'Clubs'),
                                                       (6, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.THREE_OF_A_KIND, self.player1.get_hand())

    def test_get_value_two_pair(self):
        WinningHandTestCase.issue_cards(self.player1, [(4, 'Hearts'),
                                                       (5, 'Hearts')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.TWO_PAIR, self.player1.get_hand())

    def test_get_value_one_pair(self):
        WinningHandTestCase.issue_cards(self.player1, [(4, 'Hearts'),
                                                       (10, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.ONE_PAIR, self.player1.get_hand())

    def test_get_value_no_hand(self):
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Clubs'),
                                                       (10, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        winning_hand.get_value(self.table, self.player1)

        self.assertEqual(Hands.NO_HAND, self.player1.get_hand())

    def test_has_royal_flush(self):
        WinningHandTestCase.issue_cards(self.player1, [(14, 'Spades'),
                                                       (13, 'Spades')])
        WinningHandTestCase.issue_cards(self.table, [(10, 'Spades'),
                                                     (11, 'Spades'),
                                                     (12, 'Spades')])

        self.assertTrue(winning_hand.has_royal_flush(self.table, self.player1))

    def test_if_straight_flush1(self):
        straight = [5, 6, 7, 8, 9]
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Spades'),
                                                       (2, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (7, 'Spades'),
                                                     (8, 'Spades'),
                                                     (4, 'Hearts')])

        self.assertTrue(
            winning_hand.if_straight_is_flush(straight, self.table,
                                              self.player1))

    def test_if_straight_flush2(self):
        straight = [5, 6, 7, 8, 9]
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Diamonds'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(5, 'Diamonds'),
                                                     (6, 'Diamonds'),
                                                     (7, 'Diamonds'),
                                                     (8, 'Diamonds'),
                                                     (11, 'Clubs')])

        self.assertTrue(
            winning_hand.if_straight_is_flush(straight, self.table,
                                              self.player1))

    def test_if_straight_flush3(self):
        straight = [5, 6, 7, 8, 9]
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Hearts'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(5, 'Hearts'),
                                                     (6, 'Hearts'),
                                                     (7, 'Hearts'),
                                                     (8, 'Hearts'),
                                                     (11, 'Clubs')])

        self.assertTrue(
            winning_hand.if_straight_is_flush(straight, self.table,
                                              self.player1))

    def test_if_straight_flush4(self):
        straight = [5, 6, 7, 8, 9]
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Clubs'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table,
                                        [(5, 'Clubs'), (6, 'Clubs'),
                                         (7, 'Clubs'), (8, 'Hearts'),
                                         (11, 'Diamonds')])

        self.assertFalse(
            winning_hand.if_straight_is_flush(straight, self.table,
                                              self.player1))

    def test_if_straight_flush5(self):
        straight = [1, 2, 3, 4, 5]
        WinningHandTestCase.issue_cards(self.player1, [(5, 'Clubs'),
                                                       (14, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table,
                                        [(2, 'Clubs'), (3, 'Clubs'),
                                         (4, 'Clubs'), (8, 'Hearts'),
                                         (11, 'Diamonds')])

        self.assertTrue(
            winning_hand.if_straight_is_flush(straight, self.table,
                                              self.player1))

    def test_if_straight_flush6(self):
        straight = [1, 2, 3, 4, 5]
        WinningHandTestCase.issue_cards(self.player1, [(5, 'InvalidSuit'),
                                                       (14, 'InvalidSuit')])
        WinningHandTestCase.issue_cards(self.table, [(2, 'InvalidSuit'),
                                                     (3, 'InvalidSuit'),
                                                     (4, 'InvalidSuit'),
                                                     (8, 'InvalidSuit'),
                                                     (11, 'InvalidSuit')])

        self.assertFalse(
            winning_hand.if_straight_is_flush(straight, self.table,
                                              self.player1))

    def test_has_straight_flush1(self):
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (7, 'Spades'),
                                                     (8, 'Spades'),
                                                     (4, 'Hearts')])

        self.assertTrue(
            winning_hand.has_straight_flush(self.table, self.player1))

    def test_has_straight_flush2(self):
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Diamonds'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (7, 'Spades'),
                                                     (8, 'Spades'),
                                                     (4, 'Hearts')])

        self.assertFalse(
            winning_hand.has_straight_flush(self.table, self.player1))

    def test_has_straight_flush3(self):
        WinningHandTestCase.issue_cards(self.player1, [(9, 'Diamonds'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (7, 'Spades'),
                                                     (11, 'Spades'),
                                                     (4, 'Hearts')])

        self.assertFalse(
            winning_hand.has_straight_flush(self.table, self.player1))

    def test_has_four_of_a_kind1(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(2, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertTrue(
            winning_hand.has_four_of_a_kind(self.table, self.player1))

    def test_has_four_of_a_kind2(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(3, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertFalse(
            winning_hand.has_four_of_a_kind(self.table, self.player1))

    def test_has_full_house1(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (4, 'Hearts')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (2, 'Clubs')])

        self.assertTrue(winning_hand.has_full_house(self.table, self.player1))

    def test_has_full_house2(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (10, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (10, 'Diamonds'),
                                                     (10, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (2, 'Clubs')])

        self.assertTrue(winning_hand.has_full_house(self.table, self.player1))

    def test_has_full_house1(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (10, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (2, 'Clubs')])

        self.assertFalse(winning_hand.has_full_house(self.table, self.player1))

    def test_has_flush1(self):
        WinningHandTestCase.issue_cards(self.player1, [(14, 'Spades'),
                                                       (12, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Spades'),
                                                     (8, 'Hearts')])

        self.assertTrue(winning_hand.has_flush(self.table, self.player1))

    def test_has_flush2(self):
        WinningHandTestCase.issue_cards(self.player1, [(14, 'Hearts'),
                                                       (12, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Clubs'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertFalse(winning_hand.has_flush(self.table, self.player1))

    def test_has_flush3(self):
        WinningHandTestCase.issue_cards(self.player1, [(14, 'InvalidSuit'),
                                                       (12, 'InvalidSuit')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'InvalidSuit'),
                                                     (5, 'InvalidSuit'),
                                                     (6, 'InvalidSuit'),
                                                     (2, 'InvalidSuit'),
                                                     (8, 'InvalidSuit')])

        self.assertFalse(winning_hand.has_flush(self.table, self.player1))

    def test_has_straight1(self):

        WinningHandTestCase.issue_cards(self.player1, [(3, 'Clubs'),
                                                       (4, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertTrue(winning_hand.has_straight(self.table, self.player1))

    def test_has_straight2(self):
        WinningHandTestCase.issue_cards(self.player1, [(14, 'Clubs'),
                                                       (4, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertFalse(winning_hand.has_straight(self.table, self.player1))

    def test_has_three_of_a_kind1(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertTrue(
            winning_hand.has_three_of_a_kind(self.table, self.player1))

    def test_has_three_of_a_kind2(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (11, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertFalse(
            winning_hand.has_three_of_a_kind(self.table, self.player1))

    def test_has_two_pair1(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (4, 'Diamonds')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertTrue(winning_hand.has_two_pair(self.table, self.player1))

    def test_has_two_pair2(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (7, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds')])

        self.assertFalse(winning_hand.has_two_pair(self.table, self.player1))

    def test_has_one_pair1(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (7, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades'),
                                                     (2, 'Diamonds'),
                                                     (8, 'Hearts')])

        self.assertTrue(winning_hand.has_one_pair(self.table, self.player1))

    def test_has_one_pair2(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (7, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades')])

        self.assertFalse(winning_hand.has_one_pair(self.table, self.player1))

    def test_repeated_cards(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (2, 'Clubs')])
        WinningHandTestCase.issue_cards(self.table, [(4, 'Spades'),
                                                     (5, 'Spades'),
                                                     (6, 'Spades')])

        card_freq = {2: 2, 4: 1, 5: 1, 6: 1}
        repeated_cards = winning_hand.repeated_cards(self.table, self.player1)

        self.assertEqual(len(card_freq), len(repeated_cards))

        for card, freq in card_freq.items():
            self.assertTrue(card in repeated_cards)
            self.assertEqual(freq, repeated_cards[card])

    def test_highest_card(self):
        WinningHandTestCase.issue_cards(self.player1, [(2, 'Spades'),
                                                       (7, 'Clubs')])

        expected_players = [self.player1]
        actual_players = winning_hand.highest_card([self.player1])

        for expected, actual in zip(expected_players, actual_players):
            self.assertEqual(expected, actual)
示例#8
0
from card import Deck, Player

deck = Deck()
cardInPlay = None
players = []
currentPlayerIndex = 0
direction = 1
skipMod = 1

for n in range(4):
    players.append(Player(n))

for m in range(7):
    players[0].addToHand(deck.draw())
    players[1].addToHand(deck.draw())
    players[2].addToHand(deck.draw())
    players[3].addToHand(deck.draw())

cardInPlay = deck.draw()

winner = False

def nextPlayerHandler():
    global currentPlayerIndex, skipMod, direction

    num = currentPlayerIndex + direction * skipMod

    if num > 3:
        return num - 4
    elif num < 0:
        return num + 4
示例#9
0
 def setUp(self):
     self.player = Player("p1")
     self.player_cards = [(2, "Clubs"), (3, "Diamonds")]
示例#10
0
class PlayerTestCase(unittest.TestCase):
    @staticmethod
    def issue_cards(player, cards):
        for card in cards:
            player.add_card(card)

    def setUp(self):
        self.player = Player("p1")
        self.player_cards = [(2, "Clubs"), (3, "Diamonds")]

    def test_initializer(self):
        pid = "p1"
        new_player = Player(pid)
        self.assertEqual(0, len(new_player.get_cards()))
        self.assertEqual(pid, new_player.get_ID())

        new_player = Player(pid, self.player_cards)
        self.assertEqual(len(self.player_cards), len(new_player.get_cards()))
        self.assertEqual(pid, new_player.get_ID())

    def test_set_hand(self):
        self.player.set_hand(Hands.ONE_PAIR)
        self.assertEqual(Hands.ONE_PAIR, self.player.get_hand())

        self.player.set_hand(Hands.ROYAL_FLUSH)
        self.assertEqual(Hands.ROYAL_FLUSH, self.player.get_hand())

    def test_print_cards(self):
        PlayerTestCase.issue_cards(self.player, self.player_cards)

        expected_output = str(self.player_cards)
        stdout_capture = StdoutCapture(lambda: self.player.print_cards())
        _, output = stdout_capture.capture()

        self.assertTrue(expected_output in output.strip())

    def test_get_cards(self):
        PlayerTestCase.issue_cards(self.player, self.player_cards)

        cards = self.player.get_cards()
        self.assertEqual(len(self.player_cards), len(cards))

        self.player_cards.sort(key=lambda card_tup: (card_tup[1], card_tup[0]))
        cards.sort(key=lambda card_tup: (card_tup[1], card_tup[0]))

        for i, card in enumerate(self.player_cards):
            self.assertEqual(card, cards[i])

    def test_add_card(self):
        card = self.player_cards[0]

        self.assertEqual(0, len(self.player.get_cards()))
        self.assertFalse(card in self.player.get_cards())
        self.player.add_card(card)

        self.assertEqual(1, len(self.player.get_cards()))
        self.assertTrue(card in self.player.get_cards())

    def test_remove_card_exists(self):
        PlayerTestCase.issue_cards(self.player, self.player_cards)

        card = self.player_cards[0]
        self.assertTrue(card in self.player.get_cards())

        self.player.remove_card(card)

        self.assertFalse(card in self.player.get_cards())

    ''' FAILS - Remove method attempts to remove card even if it does not exist.'''

    # def test_remove_card_nonexistent(self):
    #     card = self.player_cards[0]
    #     self.assertFalse(card in self.player.get_cards())
    #
    #     StdoutCapture(lambda: self.player.remove_card(card)).capture()
    #
    #     self.assertFalse(card in self.player.get_cards())

    def test_pop_card_exists(self):
        PlayerTestCase.issue_cards(self.player, self.player_cards)

        card = self.player.pop_card()

        self.assertFalse(card in self.player.get_cards())

    def test_pop_card_nonexistent(self):

        card, output = StdoutCapture(lambda: self.player.pop_card()).capture()

        self.assertFalse(card in self.player.get_cards())

    def test_add_chips(self):
        chips = 15000
        self.player.remove_chips(self.player.get_chips())

        self.assertEqual(0, self.player.get_chips())

        self.player.add_chips(chips)

        self.assertEqual(chips, self.player.get_chips())

    '''FAIL - Player cannot have negative chips.'''
示例#11
0
 def __init__(self, player_count=None):
     if player_count is None:
         player_count = 2
     self.player_count = player_count
     self.player_one = Player(name="Eric", hand=[], bank=[], properties=[])
     self.player_two = Player(name="Rach", hand=[], bank=[], properties=[])
     """
     TESTING SETUP
     self.player_one = Player(
         name="Test John",
         hand=[
             PropertyWildCard(value=0, color=['light blue', 'brown', 'pink', 'orange', 'railroad', 'utility', 'red', 'yellow', 'green', 'dark blue']),
             RentCard(value=3,
                      colors=['light blue', 'brown', 'pink', 'orange', 'railroad', 'utility', 'red', 'yellow',
                              'green', 'dark blue']),
             ActionCard(value=3, action='house'),
             ActionCard(value=4, action='hotel'),
             ActionCard(value=2, action='birthday'),
         ],
         bank=[
             MoneyCard(value=2),
             MoneyCard(value=2),
             MoneyCard(value=3),
             MoneyCard(value=3),
             MoneyCard(value=3),
             MoneyCard(value=4),
         ],
         properties=[
             PropertySet(properties=[
                 PropertyCard(value=1, name='Mediterranean Ave', color='brown', count_full=2, rents=[1, 2]),
                 PropertyCard(value=1, name='Baltic Ave', color='brown', count_full=2, rents=[1, 2])],
                         wild_properties=[], house=False, hotel=False, color='brown', is_full=True, current_rent=2),
             PropertySet(properties=[
                 PropertyCard(value=1, name='Mediterranean Ave', color='brown', count_full=2, rents=[1, 2]),
                 PropertyCard(value=1, name='Baltic Ave', color='brown', count_full=2, rents=[1, 2])],
                     wild_properties=[], house=False, hotel=False, color='brown', is_full=True, current_rent=2),
             PropertySet(properties=[
                 PropertyCard(value=1, name='Baltic Ave', color='brown', count_full=2, rents=[1, 2])],
                     wild_properties=[], house=False, hotel=False, color='brown', is_full=False, current_rent=1)
         ]
     )
     self.player_two = Player(
         name="Test Jane",
         hand=[
             PropertyWildCard(value=0,
                              color=['light blue', 'brown', 'pink', 'orange', 'railroad', 'utility', 'red', 'yellow',
                                     'green', 'dark blue']),
             RentCard(value=3,
                      colors=['light blue', 'brown', 'pink', 'orange', 'railroad', 'utility', 'red', 'yellow',
                              'green', 'dark blue']),
             ActionCard(value=3, action='house'),
             ActionCard(value=4, action='hotel'),
             ActionCard(value=2, action='birthday'),
             PropertyCard(value=1, name='Mediterranean Ave', color='brown', count_full=2, rents=[1, 2]),
             PropertyCard(value=1, name='Baltic Ave', color='brown', count_full=2, rents=[1, 2]),
         ],
         bank=[
             MoneyCard(value=1),
         ],
         properties=[
             PropertySet(properties=[
                 PropertyCard(value=1, name='Mediterranean Ave', color='brown', count_full=2, rents=[1, 2]),
                 PropertyCard(value=1, name='Baltic Ave', color='brown', count_full=2, rents=[1, 2])],
                 wild_properties=[], house=False, hotel=False, color='brown', is_full=True, current_rent=2)
         ]
     )
     """
     self.players = [self.player_one, self.player_two]
     self.deck = Deck()
     self.discard = []
     self.player_active = self.player_one
     self.plays_left = 0