forked from MasterChenb0x/blackjack-trainer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblk_jak_functions.py
More file actions
executable file
·82 lines (63 loc) · 1.94 KB
/
blk_jak_functions.py
File metadata and controls
executable file
·82 lines (63 loc) · 1.94 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# We are an import and import company
import sys
# Variable Setup
count = 0 # initial card count
elevens = 0 # counter, for aces counting as 11 in hand
# Prints the player's current hand, the total value, and the running count
def gui(cards, total, count):
print(f"Player Hand: {cards}")
print(f"Current card value: {total}")
print(f"Current deck count: {count}")
# Convert face cards to their integer value, uses the current total to prevent aces from busting you
def faceSum(card, total, elevens):
card_sum = 0
if card in ['J', 'Q', 'K']:
card_sum = 10
elif card == 'A':
if total + 11 > 21:
card_sum = 1
else:
card_sum = 11
elevens += 1
else:
card_sum = int(card)
total += card_sum
return total, elevens
# Checks and modifies the running count, using the Hi-Lo System
def hilo_counter(card, count):
try:
thisCard = int(card)
if thisCard <= 6:
count += 1
elif thisCard <= 9:
count += 0
except:
if card in [10, 'J', 'Q', 'K', 'A']:
count += -1
return count
# If ph_total is over 21, check to see if any aces in hand are 11s, and if so, switches it to a 1
def ace_bust_check(ph_total, elevens):
if elevens > 0:
ph_total += -10
elevens += -1
return ph_total, elevens
# Asks if you want to hit or stand
def player_action(player_hand, ph_total, elevens):
while True:
q = input("(H)it/(S)tand/(Q)uit?: ")
q = q.lower()
if q == "h":
break
if q == "s":
player_hand = 0
ph_total = 0
elevens = 0
elif q == "q":
print("Exit through the gift shop")
sys.exit()
return player_hand, ph_total, elevens
# Message if run directly
if __name__ == "__main__":
print("This file contains basic blackjack functions")
sys.exit()