def main(): # create a player P1 = Player('P1', 200) # start w 200 P1_bank = P1.bank deck = Deck() dealer = Player('dealer') value = Value() # show beginning bank # test count print(len(deck.show_deck())) print(c(deck.show_deck())) # win round P1.add_bet(20) P1_bank = P1.win() print(P1_bank) # check if a card in deck is discarded print('deck before drawing: %s' % (len(deck._deck))) print() print('you drew a %s' % (deck.deal_card())) print() print('deck after drawing: %s' % (len(deck._deck))) # checking hand P1.hand.append(deck.deal_card()) P1.hand.append(deck.deal_card()) print('current hand:') print(P1.show_hand()) P1_hand_value = value.hand_value(P1.hand) + value.ace_present(P1.hand) print(P1_hand_value) while P1_hand_value < 21 and value.hand_value(P1.hand) != 0: P1.hand.append(deck.deal_card()) print('you drew %s' % (P1.hand[-1])) print('hand value is now %s' % (P1_hand_value)) if value.hand_value(P1.hand) == 0: print('You busted')
class deck_dealCardTest(unittest.TestCase): def setUp(self): """Call before every test case.""" self.deck = Deck() def testDealCard(self): test_card = self.deck.cards[len(self.deck.cards)-1] assert self.deck.deal_card() == test_card, 'Deck.deal_card() does not provide the right return value'
def test_deal_hands(): deck = Deck() assert isinstance(deck.deal_card(), Card) deck = Deck() deck.shuffle() card1, card2 = deck.deal_hand() assert isinstance(card1, Card) assert isinstance(card2, Card) assert card1.value != card2.value or card1.suit != card2.suit
def test_deal_hand(): deck = Deck() assert isinstance(deck.deal_card(), Card) card1, card2 = deck.deal_hand() assert isinstance(card1, Card) assert isinstance(card2, Card) assert card1 != card2 deck = Deck() deck.shuffle() card1, card2 = deck.deal_hand() assert card1 != card2 card1, card2 = deck.deal_card(), deck.deal_card() assert card1 != card2
class TestDeck(unittest.TestCase): expected_deck_size = 52 def setUp(self): self.myTestDeck = Deck() self.myTestDeck.generate_deck_cards() def tearDown(self): del self.myTestDeck; def test_deck_Randomness(self): tempDeckCards = self.myTestDeck.cards().copy(); self.myTestDeck.shuffle_cards(); self.assertNotEqual(tempDeckCards, self.myTestDeck.cards(), "Deck has not been shuffled.") def test_deck_size(self): self.assertEqual(len(self.myTestDeck.cards()), self.expected_deck_size, "Deck is not the correct size!!") def test_deal_card(self): tempCard = self.myTestDeck.deal_card() self.expected_deck_size -= 1 self.assertEqual(len(self.myTestDeck.cards()), self.expected_deck_size, "ERROR deck size is not correct") self.assertTrue(isinstance(tempCard, Card))
def main(): # name variables deck, value = Deck(), Value() shuffled_deck = deck.shuffle_deck() spacer = '--------------------------' print (spacer) print ("BLACKJACK!!!") print (spacer) bank = eval(input('how much do you want to play with: ')) print (spacer) P1 = Player('P1', bank) dealer = Player('dealer') print ('You now have %s to bet' %(P1.bank)) print (spacer) answer = ['Y', 'y', 'n', 'N'] # input bank keep_playing = True a = 'Y' # does user want to play again while keep_playing == True: if a not in answer: # did not select Y/N print ('that answer is not an option...') a = input('do you want to keep playing? (Y/N) ') # ask once more continue else: if a == 'N' or a == 'n': keep_playing = False break # cut to game # start game if P1.bank == 0: P1.bank = int(input('you ran out of money, enter more money: ')) bet = int(input('enter your bet: ')) print (P1.add_bet(bet)) print () # pass cards to dealer & player(s) P1.hand.append(deck.deal_card()) dealer.hand.append(deck.deal_card()) P1.hand.append(deck.deal_card()) dealer.hand.append(deck.deal_card()) # show your hand & dealer's last hand print ('your current hand:') print (spacer) print (P1.show_hand()) print ('value of the hand is: %s' % (value.actual_value(P1.hand))) print (spacer) print ('dealer\'s hand: %s'% (dealer.hand[-1])) print (spacer) print ('card count: %s' % (c(deck.history))) bj = False if value.actual_value(P1.hand) != 21: choose = input('Do you want to hit or stand? (H/S): ') else: bj = True # plauer's turn while ((choose == 'H') and not bj) or ((choose == 'h') and not bj): P1.hand.append(deck.deal_card()) print (spacer) print ('you drew a %s. Hand value: %s' % (P1.hand[-1], value.actual_value(P1.hand))) print (spacer) print ('Current Hand:') print (P1.show_hand()) if value.actual_value(P1.hand) == 0: print ('You busted') break print ('card count: %s' % (c(deck.history))) choose = input('Do you want to hit or stand? (H/S): ') # Dealer's turn print ('Dealer\'s turn') print (spacer) print ('dealer\'s hand: ') print (dealer.show_hand()) print ('dealer\'s current value is: %s' % (value.actual_value(dealer.hand) )) while value.actual_value(dealer.hand) < 17 and value.actual_value(P1.hand) != 0: # soft 17 dealer.hand.append(deck.deal_card()) print ('dealer drew a %s' % (dealer.hand[-1])) print (spacer) # did dealer break? if value.hand_value(dealer.hand) != 0: print ('dealer value: %s' % (value.actual_value(dealer.hand))) if value.hand_value(dealer.hand) == 0: print ('dealer busted') break # reveal winner and give earnings print ('Your hand value: %s || Dealer\'s hand value: %s' % (value.actual_value(P1.hand), value.actual_value(dealer.hand))) if value.actual_value(P1.hand) > value.actual_value(dealer.hand): P1.win() # add winnings to bank if value.hand_value(dealer.hand) == 0: print ('Dealer busted') print ('You win!') print ('you now have %s dollars total' %(P1.bank)) elif value.hand_value(P1.hand) == value.hand_value(dealer.hand): print ('Tie.') else: P1.lose() # subtract bet from P1 bank print ('Dealer wins') print ('you now have %s dollars total' %(P1.bank)) print ('end of the round') print () # clear old hands dealer.new_hand() P1.new_hand() a = input('do you want to keep playing? (Y/N) ') bj = False if len(deck.history) < 26: deck._deck = deck.shuffle_deck()