-
Notifications
You must be signed in to change notification settings - Fork 1
/
Agent.py
66 lines (53 loc) · 1.63 KB
/
Agent.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
class Agent:
'''
This class represents an Agent object and serves as the
parent class for Dealer and Player. Each agent has a particular
hand and can choose whether to hit or stand
'''
def __init__(self):
'''
Sets the hand
Attributes:
hand (list): the hand of the agent
'''
self.hand = []
def __str__(self):
'''
Returns the string representation fo the agent's hand
Returns:
(str): string of the number and suit for every card in hand
'''
hand_str = ''
for card in self.hand:
hand_str += str(card) + ", "
return "Hand: " + hand_str
def get_hand(self):
'''
Returns the hand of the agent
Returns:
number (list): the hand
'''
return self.hand
def set_hand(self, hand):
'''
Sets the hand of the agent
Parameter:
hand (list): the hand
'''
self.hand = hand
def hit(self, deck):
self.hand.append(deck.draw())
'''
Adds another card to the agent's hand
Parameter:
deck (Deck): the deck currently in use on the table
'''
def choose_action(self, is_hit, deck):
if is_hit:
self.hit(deck)
'''
Based on choice between taking a hit and standing, will call hit(deck) or do nothing
Parameters:
is_hit (boolean): Choice in which true indicates decision to take a hit and false indicates decision to stand
deck (Deck): the deck currently in use on the table
'''