-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract_player.py
173 lines (137 loc) · 5.47 KB
/
abstract_player.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
class AbstractPlayer:
def __init__(self, name):
self.name = name
self.money = 0
# name as a string
# money as int
# STATUS:
self.status = 'normal'
# status - if is blind dealer etc.
# statuses = {'normal':3,'bigblind':2,'smallblind':1,'dealer':0, 'smallblind & dealer':1}
# HAND
self.hand = []
# hand is always a list!
# ALLIN
self.allin = False
# ===========================================================================
# #NAME
# ===========================================================================
def getName(self):
return self.name
# ===========================================================================
# #STATUS:
# ===========================================================================
def makeDealer(self):
self.status = 'dealer'
def makeSmallBlind(self):
self.status = 'smallblind'
def makeBigBlind(self):
self.status = 'bigblind'
def makeSmallDealer(self):
self.status = 'smallblind & dealer'
def getStatus(self):
return self.status
# ===========================================================================
# #HAND
# ===========================================================================
def addToHand(self, instanceofcard):
# instanceofcard needs to be a card
self.hand.append(instanceofcard)
self.hand.sort()
def getHand(self):
return self.hand
# ===========================================================================
# #MONEY:
# ===========================================================================
def addToMoney(self, value):
# value needs to be an int
self.money = self.money + value
def getMoney(self):
return self.money
def minusMoney(self, value):
old = self.getMoney()
self.money = old - value
# ===========================================================================
# #ALLIN:
# ===========================================================================
def getAllIn(self):
# returns boolean if betted allin
return self.allin
# ===========================================================================
# #ACTIONS
# ===========================================================================
def fold(self, gamestate):
gamestate.remove_players_from_round(self)
print '%s folds' % (self.getName())
def call(self, gamestate, value=None):
if value == None:
diff = gamestate.get_player_bet_difference(self)
if diff != 0:
self.minusMoney(diff)
gamestate.add_to_bets(self, diff)
print '%s calls %s chips' % (self.getName(), diff)
print '%s has %s chips left' % (self.getName(), self.getMoney())
else:
print '%s checks' % (self.getName())
gamestate.add_to_bets(self, diff)
else:
gamestate.add_to_bets(self, value)
self.minusMoney(value)
print '%s calls %s chips' % (self.getName(), value)
print '%s has %s chips left' % (self.getName(), self.getMoney())
def check(self, gamestate):
print '%s checks' % (self.getName())
gamestate.add_to_bets(self, 0)
def bet(self, gamestate, value):
self.minusMoney(value)
gamestate.add_to_bets(self, value)
print '%s bets %s chips' % (self.getName(), value)
print '%s has %s chips left' % (self.getName(), self.getMoney())
def Raise(self, gamestate, value):
self.minusMoney(value)
gamestate.add_to_bets(self, value)
print '%s raises %s chips' % (self.getName(), value)
print '%s has %s chips left' % (self.getName(), self.getMoney())
def allIn(self, gamestate):
value = self.getMoney()
gamestate.make_all_in_bet(self, value)
self.minusMoney(value)
self.allin = True
print '%s bets all in: %s chips' % (self.getName(), value)
# ===========================================================================
# #UPDATE:
# ===========================================================================
def update(self, gamestate):
raise NotImplementedError('Abstract method -has to be implemented')
# PURGE:
def purge(self):
# resets hand and resets status
self.hand = []
self.status = 'normal'
# COMPARE:
def __lt__(self, other):
statuses = {'normal': 4, 'bigblind': 2, 'smallblind': 1, 'dealer': 3, 'smallblind & dealer': 0}
if statuses[other.getStatus()] > statuses[self.getStatus()]:
return True
else:
return False
def __le__(self, other):
statuses = {'smallblind': 1, 'bigblind': 2, 'normal': 3, 'dealer': 4, 'smallblind & dealer': 0}
if self.getName() == other.getName():
return True
else:
return statuses[other.getStatus()] > statuses[self.getStatus()]
def __eq__(self, other):
if type(self) == type(other):
return self.getName() == other.getName()
else:
return False
def __hash__(self):
return hash(id(self))
def __str__(self):
return str(self.name)
def __repr__(self):
return self.__str__()
# DISPLAY:
def displayHand(self):
print '%s hand is : %s' % (self.getName(), self.getHand())