def test_straight_flush_to_straight_flush_comparison(self): player = Player("player", ManualActionCollector()) player2 = Player("Player2", ManualActionCollector()) suit = Suit.DIAMONDS suit1 = Suit.CLUBS hand1 = [ Card(Number.THREE, suit1), Card(Number.FOUR, suit1), Card(Number.FIVE, suit1), Card(Number.SIX, suit1), Card(Number.SEVEN, suit1) ] hand2 = [ Card(Number.TWO, suit), Card(Number.THREE, suit), Card(Number.FOUR, suit), Card(Number.FIVE, suit), Card(Number.SIX, suit) ] round_result = RoundResult( [HandResult(hand1, player), HandResult(hand2, player2)]) winning_hand_result = round_result.find_winning_hands()[0] winning_hand = winning_hand_result.cards self.assertTrue(set(hand1).issubset(winning_hand)) self.assertEqual(player, winning_hand_result.player, "Wrong Winning Player")
def test_hit(self): set_of_decks = SetOfDecks() dealer = Dealer('DealWithMe') player = Player('IWill') set_of_decks.decks.clear() set_of_decks.decks.append(Card('Spade', 'A')) dealer.hit(set_of_decks, player) self.assertEqual(player.get_my_cards()[0].get_face_val(), 'A') self.assertNotEqual(player.get_my_cards()[0].get_face_val(), 'B')
def test_is_busted(self): start = StartGame() player = Player('sushant') player.get_my_cards().append(Card('Spade', 'K')) player.get_my_cards().append(Card('Spade', 'K')) player.get_my_cards().append(Card('Spade', 'Q')) '''after calling this method if player's sum is greater than 21 it return True ''' self.assertEqual(start.isbusted(player), True) self.assertNotEqual(start.isbusted(player), False) player.get_my_cards().clear() player.get_my_cards().append(Card('Spade', 'K')) '''after calling this method if player's sum is less than 21 it return False ''' self.assertEqual(start.isbusted(player), False) self.assertNotEqual(start.isbusted(player), True)
def add_players(self): while True: print("Add a Player(y/n)") msg = input("\n") if msg.lower() == 'y': self.current_players.append( Player(input("add the name of player\n"))) continue elif msg.lower() == 'n': if len(self.current_players) == 0: print("Add at list one player") continue else: break
def test_quads_to_quads_comparison(self): player = Player("player", ManualActionCollector()) player2 = Player("Player2", ManualActionCollector()) suit = Suit.DIAMONDS suit1 = Suit.CLUBS hand1 = [ Card(Number.THREE, suit1), Card(Number.THREE, Suit.HEARTS), Card(Number.THREE, suit), Card(Number.THREE, Suit.SPADES), Card(Number.KING, suit1) ] hand2 = [ Card(Number.TWO, suit1), Card(Number.TWO, Suit.HEARTS), Card(Number.TWO, suit), Card(Number.TWO, Suit.SPADES), Card(Number.KING, suit) ] round_result = RoundResult( [HandResult(hand1, player), HandResult(hand2, player2)]) winning_hand = round_result.find_winning_hands()[0].cards self.assertTrue(set(hand1).issubset(winning_hand))
def test_straight_to_flush_comparison(self): player = Player("player", ManualActionCollector()) player2 = Player("Player2", ManualActionCollector()) suit = Suit.DIAMONDS suit1 = Suit.CLUBS hand1 = [ Card(Number.TWO, suit), Card(Number.NINE, suit), Card(Number.FOUR, suit), Card(Number.FIVE, suit), Card(Number.SIX, suit) ] hand2 = [ Card(Number.ACE, Suit.SPADES), Card(Number.KING, suit1), Card(Number.QUEEN, Suit.SPADES), Card(Number.JACK, Suit.HEARTS), Card(Number.TEN, suit1) ] round_result = RoundResult( [HandResult(hand1, player), HandResult(hand2, player2)]) winning_hand = round_result.find_winning_hands()[0].cards self.assertTrue(set(hand1).issubset(winning_hand))
def test_pair_two_pair_comparison(self): player = Player("player", ManualActionCollector()) player2 = Player("Player2", ManualActionCollector()) suit = Suit.DIAMONDS suit1 = Suit.CLUBS hand1 = [ Card(Number.TWO, suit), Card(Number.TWO, suit1), Card(Number.THREE, suit), Card(Number.THREE, suit1), Card(Number.FOUR, suit1) ] hand2 = [ Card(Number.ACE, suit), Card(Number.ACE, suit1), Card(Number.KING, Suit.CLUBS), Card(Number.QUEEN, suit), Card(Number.JACK, suit1) ] round_result = RoundResult( [HandResult(hand1, player), HandResult(hand2, player2)]) winning_hand = round_result.find_winning_hands()[0].cards self.assertTrue(set(hand1).issubset(winning_hand))
def test_get_my_cards(self): player = Player('Nikhil') card1 = Card('Spade', 'A') card2 = Card('Heart', 'K') player.get_my_cards().append(card1) player.get_my_cards().append(card2) self.assertEqual(player.get_my_cards(), [card1, card2]) self.assertNotEqual(player.get_my_cards(), [ card1, ])
def test_lose(self): start = StartGame() player = Player('sushant') start.current_players.append(player) player.get_my_cards().append(Card('Spade', 'K')) player.get_my_cards().append(Card('Spade', 'J')) player.get_my_cards().append(Card('Spade', 'Q')) start.busted_players.append(player) '''lose will return list of names of busted players''' self.assertEqual(start.lose()[0], player.get_name()) start.busted_players.clear() '''lose will return empty list if there are no players in busted_list''' self.assertEqual(start.lose(), [])
def test_distribute_card_first_time(self): current_players = [] player1 = Player('Nikhil') player2 = Player('Nishant') current_players.append(player1) current_players.append(player2) set_of_decks = SetOfDecks() set_of_decks.get_decks_list().clear() set_of_decks.get_decks_list().append(Card('Spade', 'K')) set_of_decks.get_decks_list().append(Card('Spade', 'Q')) set_of_decks.get_decks_list().append(Card('Spade', '2')) set_of_decks.get_decks_list().append(Card('Spade', '3')) set_of_decks.get_decks_list().append(Card('Spade', '4')) set_of_decks.get_decks_list().append(Card('Spade', '5')) dealer = Dealer("IamDealer") dealer.distribute_card_first_time(current_players, set_of_decks) temp_list = [] for card in player1.get_my_cards(): temp_list.append(card.get_face_val()) for card in player2.get_my_cards(): temp_list.append(card.get_face_val()) for card in dealer.get_my_cards(): temp_list.append(card.get_face_val()) self.assertEqual(temp_list, ['K', 'Q', '2', '3', '4', 0])
def test_win(self): start = StartGame() player = Player('sushant') start.current_players.append(player) player.get_my_cards().append(Card('Spade', 'Q')) player.get_my_cards().append(Card('Spade', 'K')) start.dealer.get_my_cards().append(Card('Spade', 'Q')) start.standed_players.append(player) '''playersum > dealersum and playersum <=21''' self.assertEqual(start.wins()[0], player.get_name()) player.get_my_cards().clear() player.get_my_cards().append(Card('Spade', 'K')) player.get_my_cards().append(Card('Spade', 'A')) start.dealer.get_my_cards().append(Card('Spade', '5')) start.dealer.get_my_cards().append(Card('Spade', '6')) '''BlackJack Condition for player wins''' self.assertEqual(start.wins()[0], player.get_name()) player.get_my_cards().clear() start.dealer.get_my_cards().clear() player.get_my_cards().append(Card('Spade', '5')) player.get_my_cards().append(Card('Spade', '6')) player.get_my_cards().append(Card('Spade', 'K')) start.dealer.get_my_cards().append(Card('Spade', 'A')) start.dealer.get_my_cards().append(Card('Spade', 'K')) '''BlackJack Condtion for Dealer wins''' self.assertEqual(start.wins()[0], start.dealer.get_name()) player.get_my_cards().clear() start.dealer.get_my_cards().clear() player.get_my_cards().append(Card('Spade', '5')) start.dealer.get_my_cards().append(Card('Spade', '5')) '''Draw condition response draw ''' self.assertEqual(start.wins()[0], 'draw') start.dealer.get_my_cards().append(Card('Spade', '6')) '''DealerSum > playerSum Dealer wins''' self.assertEqual(start.wins()[0], start.dealer.get_name())
def test_add_players(self): start = StartGame() player = Player('sushant') start.current_players.append(player) self.assertEqual(len(start.current_players), 1) self.assertNotEqual(len(start.current_players), 0)
def test_get_name(self): player = Player('Sushant') self.assertEqual(player.get_name(), 'Sushant') self.assertNotEqual(player.get_name(), 'Harish')
def test_get_sum(self): player = Player('Vaibhav') card1 = Card('Spade', 'A') player.get_my_cards().append(card1) self.assertEqual(player.get_sum(), 11) self.assertNotEqual(player.get_sum(), 1) card1 = Card('Spade', 'K') player.get_my_cards().append(card1) self.assertEqual(player.get_sum(), 21) self.assertNotEqual(player.get_sum(), 1) card1 = Card('Spade', '2') player.get_my_cards().append(card1) self.assertEqual(player.get_sum(), 13) self.assertNotEqual(player.get_sum(), 11) player.get_my_cards().remove(card1) player.get_my_cards().append(Card('Heart', 'K')) player.get_my_cards().append(Card('Heart', 'K')) self.assertEqual(player.get_sum(), 31) self.assertNotEqual(player.get_sum(), 12) player.get_my_cards().clear() player.get_my_cards().append(Card("Heart", 'A')) player.get_my_cards().append(Card("Heart", '2')) self.assertEqual(player.get_sum(), 13) self.assertNotEqual(player.get_sum(), 2)
def test_seat_too_many_players(self): table = Table(2) table.seat_player(Player("Player1")) table.seat_player(Player("Player2")) self.assertRaises(NoFreeSeatError, table.seat_player, Player("Player3"))
def test_seat_player(self): table = Table(2) table.seat_player(Player("Player1")) self.assertFalse(table.seats[0].is_free)
def __init__(self, name): Player.__init__(self, name)
''' Created on 5 Nov 2018 @author: mdunn ''' from people.dealer import Dealer from people.player import Player from action.manual_action_collector import ManualActionCollector from action.random_action_collector import RandomActionCollector dealer = Dealer() player1 = Player("Player1", RandomActionCollector()) player2 = Player("Player2", RandomActionCollector()) dealer.seat_player(player1) dealer.seat_player(player2) for i in range(1000): dealer.deal() dealer.process_actions() dealer.declare_winner()