Changeset 14 for holdemtable.py
- Timestamp:
- 02/03/08 20:33:23 (4 years ago)
- Files:
-
- 1 modified
-
holdemtable.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
holdemtable.py
r13 r14 19 19 self.__money_in_pot = None #money in pot before previous round 20 20 self.__action_history = [] 21 self.__has_acted = False 22 self.__has_folded =False 21 23 self.status = "need implementing" 22 24 … … 24 26 self.__in_hand = True 25 27 self.__money_in_pot = 0.0 28 self.__has_folded = False 26 29 self.cards = [] 27 30 self.__action_history = [] … … 36 39 self.__action_history = [] 37 40 self.__money_in_pot += self.moneyInPhase() 41 self.__has_acted = False 38 42 39 43 … … 44 48 "seat" : self.seat} 45 49 def privateData(self): 46 dat = {"user_id" : self.user_id,47 "id" : self.id,48 "cards" : self.cards}50 dat = {"user_id" : self.user_id, 51 "id" : self.id, 52 "cards" : self.cards} 49 53 return dat 50 54 … … 61 65 raise InsufficientFundsException("Insufficient Funds") 62 66 else: 63 self.money -= value 67 if value != None: self.money -= value 68 if not self.__has_acted and action != "small_blinds" and action != "large_blinds": 69 self.__has_acted = True 70 if action == "fold": self.__has_folded = True 64 71 self.__action_history.append((action,value)) 65 72 73 def hasFolded(self): 74 return self.__has_folded 66 75 def inHand(self): 67 76 #TODO need to change this 68 77 return self.__in_hand 78 79 def hasActed(self): 80 return self.__has_acted 69 81 70 82 … … 83 95 self.community_cards = None 84 96 self.possible_actions = None #to cache possible actions 85 pass97 self.__hand_count = 0 86 98 87 99 def actionOn(self): … … 104 116 self.pot = 0.0 105 117 self.community_cards = [] 118 self.__hand_count += 1 106 119 print self.player_array 107 120 for p in self.player_array: p.nextHand() … … 119 132 if self.phase != None: self.phase += 1 120 133 else: self.phase = 0 121 134 print "PHASE: %d" % self.phase 135 for p in self.player_array: p.nextPhase() 122 136 pn = PHASES[self.phase] 123 137 if pn == "blinds": … … 127 141 elif pn == "flop": 128 142 for _ in range(3): 129 self.community_cards.append(self.deck.deal )143 self.community_cards.append(self.deck.deal()) 130 144 elif pn == "turn": 131 self.community_cards.append(self.deck.deal )145 self.community_cards.append(self.deck.deal()) 132 146 elif pn == "river": 133 self.community_cards.append(self.deck.deal )147 self.community_cards.append(self.deck.deal()) 134 148 135 149 … … 137 151 else: return self.nextAction() 138 152 153 #Are there any outstanding bets? 154 def outstandingBets(self): 155 max_money = max([p.moneyInPhase() for p in self.player_array]) 156 for p in self.player_array: 157 if not p.hasFolded() and p.moneyInPhase() < max_money: 158 return True 159 return False 139 160 140 161 #returns false if phase is over … … 151 172 while not self.player_array[self.__action_on].inHand(): 152 173 self.__action_on = ( self.__action_on + 1 ) % len(self.player_array) 153 else: self.action = 0 154 return True 174 else: self.__action_on = 0 175 if self.player_array[self.__action_on].hasActed()\ 176 and not self.outstandingBets(): 177 return False 178 else: return True 155 179 156 180 def requiredAction(self, player_id): … … 166 190 167 191 max_money = max([p.moneyInPhase() for p in self.player_array]) 168 192 169 193 money_in_phase = me.moneyInPhase() 194 195 min_bet = self.blinds[1] 196 if PHASES[self.phase] == "river": min_bet *= 2 197 170 198 if max_money == money_in_phase: self.possible_actions["check"] = (None,None) 171 if max_money > money_in_phase: self.possible_actions["call"] =\ 172 (max_money - money_in_phase, max_money - money_in_phase) 173 #TODO this needs to change if it's the river 174 if max_money == 0: self.possible_actions["bet"] = (self.blinds[1], me.money) 199 200 if max_money > money_in_phase: 201 call = min(me.money, max_money-money_in_phase) 202 self.possible_actions["call"] = (call,call) 203 bet_raise = min( me.money, min_bet + max_money - money_in_phase ) 204 if max_money == 0 and me.money != 0.0: 205 self.possible_actions["bet"] = (bet_raise, me.money) 175 206 #TODO this needs to change to reflect the last bet 176 else: self.possible_actions["raise"] = ( self.blinds[1] + max_money - money_in_phase, me.money)207 else: self.possible_actions["raise"] = (bet_raise, me.money) 177 208 178 209 return self.possible_actions … … 206 237 range = pa[action] 207 238 if not (range[0] <= value <= range[1]): 208 print range[0]209 print value210 print range[1]211 239 raise InvalidActionException("Value out of range") 212 240 self.player_array[self.__action_on].doAction(action,value) 213 self.nextAction() 214 215 216 217 218 241 if not self.nextAction(): 242 if not self.nextPhase(): 243 if not self.nextHand(): 244 #TODO add game end code handing hurr 245 pass 219 246 220 247 221 248 222 249 class holdemtable: 223 def __init__(self, name, max_players = 4):250 def __init__(self, name, max_players = 3, blinds = (5.0,10.0)): 224 251 self.max_players = max_players 225 252 self.players={} … … 228 255 self.holdemround = None 229 256 self.deferred = [] 230 self.blinds = (1.0,2.0)257 self.blinds = blinds 231 258 232 259
