-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj-card-counting.py
More file actions
161 lines (128 loc) · 4.51 KB
/
bj-card-counting.py
File metadata and controls
161 lines (128 loc) · 4.51 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
#Created by PepeBigotes
from random import shuffle
from time import sleep
from random import randint
import os
# DEFINE CARD VALUES HERE:
VALUES = {
+2: [ #++++++++++++++++++++
],
+1.5: [
],
+1: [
" 2♠", " 2♥", " 2♦", " 2♣",
" 3♠", " 3♥", " 3♦", " 3♣",
" 4♠", " 4♥", " 4♦", " 4♣",
" 5♠", " 5♥", " 5♦", " 5♣",
" 6♠", " 6♥", " 6♦", " 6♣",
" 7♠", " 7♥", " 7♦", " 7♣",
" 8♠", " 8♥", " 8♦", " 8♣",
" 9♠", " 9♥", " 9♦", " 9♣",
],
+0.5: [
],
0: [ #+++++++++++++++++++++
], #--------------------
-0.5: [
],
-1: [
],
-1.5: [
],
-2: [
"10♠", "10♥", "10♦", "10♣",
" J♠", " J♥", " J♦", " J♣",
" Q♠", " Q♥", " Q♦", " Q♣",
" K♠", " K♥", " K♦", " K♣",
" A♠", " A♥", " A♦", " A♣",
], #-------------------
}
value = 0
def shuffled_deck():
deck = []
for i in VALUES: deck += VALUES[i]
deck = deck * 6
shuffle(deck)
return deck
def get_card_value(card: str):
for i in VALUES:
if card in VALUES[i]: value = i
return value
def deal_cards(cards: list):
cards_num = len(cards)
if not cards_num in (4, 6, 8, 10, 12, 14): raise Exception("Invalid number of cards to deal")
global value
for card in cards:
value += get_card_value(card)
print(f"DEALER: {cards[0]} {cards[1]}")
hand = []
for card in cards[2:]:
hand.append(card)
if len(hand) == 2:
print(f" HAND: {hand[0]} {hand[1]}")
hand = []
def show_card(card: str):
print(f"card: {card}")
def ask_card(card: str):
global value
def do_single_cards(): # Singular cards
global deck
try:
for card in deck:
x = eval(input(f"{card} value: "))
if x == get_card_value(card): print("Correct!")
else: print(f"Nope, it's {get_card_value(card)}")
print("Well, you finished the deck")
exit()
except SyntaxError: print('\nI did not understand that "number" of yours, bye'); exit(1)
except KeyboardInterrupt: print("\nKeyboardInterrupt"); exit()
def do_deals(): # Almost entire deals of cards (dealer + hands)
global deck
try:
hands_num = eval(input("\nHow many hands would you like to play at the same time? (1-6) "))
if not hands_num in range(1,6): print("Invalid hands number, minimun 1, maximum 6"); exit(1)
cards_per_deal = 2 + hands_num*2
print(f"Okay, dealing {hands_num} hands ({cards_per_deal} cards) at the same time...")
while True:
print(f" Cards left: {len(deck)}")
deal_cards(deck[:cards_per_deal])
deck = deck[cards_per_deal:]
input()
if randint(0,2) == 0:
ans = eval(input("What's the current value? "))
if ans == value: input("Correct!")
else: input(f"Nah, it's {value}")
print("----------------------------")
if len(deck) <= 30:
print("The deck has been shuffled")
deck = shuffled_deck
except SyntaxError: print('\nI did not understand that "number" of yours, bye'); exit(1)
except KeyboardInterrupt: print("\nKeyboardInterrupt"); exit()
os.system('cls' if os.name=='nt' else 'clear')
print(f"""{str.center("Welcome to PepeBigotes' BlackJack Card Counting Game", 80)}
-------------------------------------------------------------------------------
All cards have another "hidden" value other than their original blackjack value
and your goal is to keep count of that hidden value and answer correctly when
you get asked about it.
You can stop the script whenever you want by pressing CTRL+C.
Here is the "hidden" cards value (you can change them inside the script btw):
""")
for i in VALUES:
if len(VALUES[i]) > 0:
print(f"Cards worth {i if i <= 0 else f'+{i}'}: ", end='')
for card in VALUES[i]:
print(card, end=' ')
print()
deck = shuffled_deck()
print("""
Modes:
0. Only one card at a time
1. Entire deals (with extra hands if you want)
""")
try: mode = int(input("Select a mode:"))
except ValueError: print("Just put a mode number, like '0' or '1'"); exit(1)
if not mode in (0,1): print(f"Mode {mode} is not a valid mode, please put a number from 0 to 1"); exit(1)
print(f"Mode {mode} selected")
if mode == 0: do_single_cards()
if mode == 1: do_deals()