-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstrategy.py
More file actions
55 lines (51 loc) · 1.65 KB
/
strategy.py
File metadata and controls
55 lines (51 loc) · 1.65 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
def basic_strategy(player_total, dealer_value, soft):
""" This is a simple implementation of Blackjack's
basic strategy. It is used to recommend actions
for the player. """
if 4 <= player_total <= 8:
return 'hit'
if player_total == 9:
if dealer_value in [1,2,7,8,9,10]:
return 'hit'
return 'double'
if player_total == 10:
if dealer_value in [1, 10]:
return 'hit'
return 'double'
if player_total == 11:
if dealer_value == 1:
return 'hit'
return 'double'
if soft:
#we only double soft 12 because there's no splitting
if player_total in [12, 13, 14]:
if dealer_value in [5, 6]:
return 'double'
return 'hit'
if player_total in [15, 16]:
if dealer_value in [4, 5, 6]:
return 'double'
return 'hit'
if player_total == 17:
if dealer_value in [3, 4, 5, 6]:
return 'double'
return 'hit'
if player_total == 18:
if dealer_value in [3, 4, 5, 6]:
return 'double'
if dealer_value in [2, 7, 8]:
return 'stand'
return 'hit'
if player_total >= 19:
return 'stand'
else:
if player_total == 12:
if dealer_value in [1, 2, 3, 7, 8, 9, 10]:
return 'hit'
return 'stand'
if player_total in [13, 14, 15, 16]:
if dealer_value in [2, 3, 4, 5, 6]:
return 'stand'
return 'hit'
if player_total >= 17:
return 'stand'