def test_take_out_cards(self): cards = init_54_deck() remove_cards = [Card('S', 'A'), Card('BJ', '')] res = take_out_cards(cards, remove_cards) flag = False for card in res: if card.get_index() == 'SA' or card.get_index == 'BJ': flag = True self.assertFalse(flag) self.assertEqual(len(cards), len(init_54_deck()) - 2)
def test_judge_game(self): players = [Player(0), Player(1)] players[0].in_chips = 10 players[1].in_chips = 10 # Test hand is equal players[0].hand = Card('S', 'J') players[1].hand = Card('H', 'J') public_card = Card('S', 'Q') payoffs = Judger.judge_game(players, public_card) self.assertEqual(payoffs[0], 0) self.assertEqual(payoffs[1], 0) # Test one player get a pair players[0].hand = Card('S', 'J') players[1].hand = Card('S', 'Q') public_card = Card('H', 'J') payoffs = Judger.judge_game(players, public_card) self.assertEqual(payoffs[0], 10.0) self.assertEqual(payoffs[1], -10.0) # Other cases # Test one player get a pair players[0].hand = Card('S', 'J') players[1].hand = Card('S', 'Q') public_card = Card('H', 'K') payoffs = Judger.judge_game(players, public_card) self.assertEqual(payoffs[0], -10.0) self.assertEqual(payoffs[1], 10.0)
def init_54_deck(): ''' Initialize a standard deck of 52 cards, BJ and RJ Returns: (list): Alist of Card object ''' suit_list = ['S', 'H', 'D', 'C'] rank_list = [ 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K' ] res = [Card(suit, rank) for suit in suit_list for rank in rank_list] res.append(Card('BJ', '')) res.append(Card('RJ', '')) return res
def init_simple_doudizhu_deck(): ''' Initialize a deck of 24 cards for simple Doudizhu Returns: (list): A list of Card object ''' suit_list = ['S', 'H', 'D', 'C'] rank_list = ['8', '9', 'T', 'J', 'Q', 'K', 'A'] res = [Card(suit, rank) for suit in suit_list for rank in rank_list] return res
def __init__(self): ''' Initialize a leducholdem dealer class ''' self.deck = [ Card('S', 'J'), Card('H', 'J'), Card('S', 'Q'), Card('H', 'Q'), Card('S', 'K'), Card('H', 'K') ] self.shuffle() self.pot = 0
def test_is_in_cards(self): deck54 = init_54_deck() deck_standard = init_standard_deck() deck54_plus_BJ = init_54_deck() deck54_plus_BJ.append(Card('BJ', '')) self.assertTrue(is_in_cards(deck54, deck_standard)) self.assertTrue(is_in_cards(deck54, [Card('BJ', ''), Card('RJ', '')])) self.assertFalse(is_in_cards(deck54, [Card('BJ', ''), Card('BJ', '')])) self.assertFalse( is_in_cards(deck54, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')])) self.assertTrue( is_in_cards(deck54_plus_BJ, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')]))
def test_is_single(self): self.assertTrue(is_single([Card('S', 'A')])) self.assertFalse(is_single([Card('S', 'A'), Card('BJ', '')]))
def test_is_pair(self): self.assertTrue(is_pair([Card('S', 'A'), Card('D', 'A')])) self.assertFalse( is_pair([Card('BJ', ''), Card('S', 'A'), Card('D', 'A')]))