-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicStrategy.py
180 lines (165 loc) · 7.44 KB
/
BasicStrategy.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
class BasicStrategy:
pair_card = [
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"],
[-1, "N", "Y/N", "Y/N", "Y", "Y", "Y", "Y", "N", "N", "N", "N"],
[-1, "N", "Y/N", "Y/N", "Y", "Y", "Y", "Y", "N", "N", "N", "N"],
[-1, "N", "N", "N", "N", "Y/N", "Y/N", "N", "N", "N", "N", "N"],
[-1, "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"],
[-1, "N", "Y/N", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "N"],
[-1, "N", "Y", "Y", "Y", "Y", "Y", "Y", "N", "N", "N", "N"],
[-1, "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"],
[-1, "N", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "N", "N"],
[-1, "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"],
[-1, "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"],
]
soft_card = [
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, "H", "H", "H", "H", "DH", "DH", "H", "H", "H", "H", "H"],
[-1, "H", "H", "H", "H", "DH", "DH", "H", "H", "H", "H", "H"],
[-1, "H", "H", "H", "DH", "DH", "DH", "H", "H", "H", "H", "H"],
[-1, "H", "H", "H", "DH", "DH", "DH", "H", "H", "H", "H", "H"],
[-1, "H", "H", "DH", "DH", "DH", "DH", "H", "H", "H", "H", "H"],
[-1, "S", "DS", "DS", "DS", "DS", "DS", "S", "S", "H", "H", "H"],
[-1, "S", "S", "S", "S", "S", "DS", "S", "S", "S", "S", "S"],
[-1, "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S"],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
]
hard_card = [
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"],
[-1, "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"],
[-1, "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"],
[-1, "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"],
[-1, "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"],
[-1, "H", "H", "DH", "DH", "DH", "DH", "H", "H", "H", "H", "H"],
[-1, "H", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "H", "H"],
[-1, "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH"],
[-1, "H", "H", "H", "S", "S", "S", "S", "H", "H", "H", "H"],
[-1, "H", "S", "S", "S", "S", "S", "S", "H", "H", "H", "H"],
[-1, "H", "S", "S", "S", "S", "S", "S", "H", "H", "H", "H"],
[-1, "H", "S", "S", "S", "S", "S", "S", "H", "H", "H", "H"],
[-1, "H", "S", "S", "S", "S", "S", "S", "H", "H", "H", "H"],
[-1, "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S"],
[-1, "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S"],
[-1, "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S"],
[-1, "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S"],
[-1, "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S"],
]
def choose_move(
self,
player_card,
dealer_card,
is_pair,
is_soft,
player_pair_value,
num_of_p_cards,
):
# print(player_card,dealer_card,is_pair,is_soft)
if is_pair:
return self.choose_from_pair_cards(
player_pair_value, dealer_card, player_card, num_of_p_cards
)
elif is_soft and player_card < 11:
return self.choose_from_soft_cards(player_card, dealer_card, num_of_p_cards)
else:
return self.choose_from_hard_cards(player_card, dealer_card, num_of_p_cards)
def choose_from_pair_cards(self, p_c, d_c, player_total_score, num_of_p_cards):
choice = self.pair_card[p_c][d_c]
if choice == "Y/N" or choice == "Y":
return "SP"
elif choice == "N":
return self.choose_from_hard_cards(player_total_score, d_c, num_of_p_cards)
def choose_from_soft_cards(self, p_c, d_c, num_of_p_cards):
while p_c > 11:
p_c -= 10
choice = self.soft_card[p_c][d_c]
if choice == "DH" or choice == "DS":
if num_of_p_cards == 2:
return "D"
else:
return choice[1]
else:
return choice
def choose_from_hard_cards(self, p_c, d_c, num_of_p_cards):
choice = self.hard_card[p_c][d_c]
if choice == "DH":
if num_of_p_cards == 2:
return "D"
else:
return choice[1]
else:
return choice
class BasicStrategy_with_PlayerDeviation(BasicStrategy):
pd_cards = [
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, "D 1", -1, -1, -1, -1, "D 3", -1, -1, -1, -1],
[-1, -1, -1, -1, -1, "SP 5", "SP 4", -1, -1, -1, "D 4", "D 4"],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "D 1"],
[-1, -1, "S 3", "S 2", "SH 0", "SH -2", "SH -1", -1, -1, -1, -1, -1],
[-1, -1, "SH -1", "SH -2", -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "S 4", -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, "S 5", "S 0", -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
]
def choose_move_with_player_deviation(
self,
player_card,
dealer_card,
is_pair,
is_soft,
player_pair_value,
num_of_p_cards,
true_count,
):
if is_pair and (2 * player_pair_value == player_card):
choice_pair = self.pd_cards[player_pair_value][dealer_card]
if choice_pair != -1:
choice_pair = choice_pair.split(" ")
if int(choice_pair[1]) <= true_count:
return choice_pair[0]
elif not is_soft:
choice = self.pd_cards[player_card][dealer_card]
if choice != -1:
choice = choice.split(" ")
if choice[0] == "SH":
if true_count >= int(choice[1]):
return "S"
else:
return "H"
elif choice == "D" and num_of_p_cards == 2:
return "D"
else:
if true_count >= int(choice[1]):
return choice[0]
return self.choose_move(
player_card,
dealer_card,
is_pair,
is_soft,
player_pair_value,
num_of_p_cards,
)
def take_insurance(self, true_count):
if true_count >= 3:
return "I"
else:
return "NI"