-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
65 lines (59 loc) · 2.83 KB
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# creates player's hand
# creates dealer's hand
# plays out player's hand
# plays out dealer's hand
from hand import Hand
from deck import Deck
class PlayTheHands:
def __init__(self):
self.deck = Deck()
self.players_hand = Hand()
self.dealers_hand = Hand()
self.bet = 10
def opening(self):
Hand.initial_deal(self.players_hand)
Hand.initial_deal(self.dealers_hand)
print("-" * 40)
print("\nThe hand opens: \n")
print("Dealer showing one: {}".format(self.dealers_hand.cards_in_hand[0]))
print("Player showing: ", self.players_hand)
print("Player's cards tally: ", self.players_hand.value_the_cards())
def players_logic(self):
print("-" * 40)
while self.players_hand.value_the_cards() < 21:
hit = input("Hit or Stay? H/S ").lower()
if hit == 'h':
Hand.draw_a_card(self.players_hand)
print("Player holding: ", self.players_hand)
print("Player's cards tally: ", self.players_hand.value_the_cards())
if self.players_hand.value_the_cards() > 21:
print("Player's hand is a bust.")
else:
print("Player's cards tally: ", self.players_hand.value_the_cards())
break
return self.players_hand.value_the_cards()
def dealers_logic(self):
print("-" * 40)
print("Dealer showing both now: ", self.dealers_hand)
if self.players_hand.value_the_cards() > 21:
self.bet = -10
print("Dealer wins.")
elif self.dealers_hand.value_the_cards() > self.players_hand.value_the_cards():
self.bet = -10
print("Dealer wins with {}.".format(self.dealers_hand.value_the_cards()))
else:
while self.dealers_hand.value_the_cards() < 17:
Hand.draw_a_card(self.dealers_hand)
print("Dealer takes a card: ", self.dealers_hand)
if self.dealers_hand.value_the_cards() > 21:
print("Dealer's hand busted at {}. Player wins.".format(self.dealers_hand.value_the_cards()))
elif self.dealers_hand.value_the_cards() == self.players_hand.value_the_cards():
self.bet = -10
print("Dealer: {}. Player: {}. Dealer wins ties.".format(self.dealers_hand.value_the_cards(),
self.players_hand.value_the_cards()))
elif self.dealers_hand.value_the_cards() < self.players_hand.value_the_cards() < 22:
print("Dealer's tally: {}. Player wins.".format(self.dealers_hand.value_the_cards()))
else:
self.bet = -10
print("Dealer wins with {}.".format(self.dealers_hand.value_the_cards()))
return self.dealers_hand.value_the_cards()