-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblackjack_player.py
More file actions
37 lines (30 loc) · 816 Bytes
/
blackjack_player.py
File metadata and controls
37 lines (30 loc) · 816 Bytes
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
from blackjack import * # Note: aces are always 11, will fix later
import random
class DEALER_PLAYER(PLAYER):
def play(self, table_state):
if self.get_hand_value() < 16:
return 'hit'
else:
return 'stay'
class RANDOM_PLAYER(PLAYER):
def play(self, table_state):
return random.choice( ['hit','stay'] )
class AWESOME_PLAYER(PLAYER):
def play(self, table_state):
if self.get_hand_value() < 16:
return 'hit'
else:
return 'stay'
# create the dealer by passing a playertype and the size of the deck
deck = DECK(10)
dealer = DEALER_PLAYER('Dealer')
players = [ RANDOM_PLAYER('Jonathan'),
AWESOME_PLAYER('Kristen')
]
T = TABLE(deck, dealer, players)
while T.get_table_state()['cards_remaining'] > 20:
T.setup_game()
T.run_game()
T.score_game()
T.print_game()
T.print_summary()