Changeset 21
- Timestamp:
- 02/04/08 08:40:59 (4 years ago)
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
deck.py
r9 r21 5 5 6 6 def card_vals(cards): 7 return [deck.cards.index(card) for card in cards] 7 print cards 8 return [(CARDS.index(card),b) for card,b in cards] 8 9 9 10 class deck: -
hand.py
r9 r21 10 10 "four_of_a_kind", 11 11 "straight_flush" ] 12 13 #def format_hand(hand): 14 #input all 7 cards 15 def best_hand(cards): 16 all_poosible_hands = list(combNoReplace(cards,5)) 17 for h in all_poosible_hands: h.sort( cmp = lambda a,b: cmp(b,a) ) 18 pos_hands = [judge_hand(h) for h in all_poosible_hands] 19 return max(pos_hands) 20 12 21 13 22 #returns the best combination for the 5 cards … … 64 73 highest_n = current_n 65 74 highest_card = a 75 else: 76 last = a 77 current_n = 1 66 78 if highest_n == 1: return ("high_card",card_vals) 67 79 #check for full house -
holdemtable.py
r20 r21 1 1 import deck 2 2 import random 3 import hand 3 4 from twisted.internet import defer 4 5 … … 7 8 8 9 class InsufficientFundsException(Exception): 10 pass 11 12 class ImproperPhaseException(Exception): 9 13 pass 10 14 … … 42 46 43 47 def __publicData(self): 44 return{"owner" : self.user_id,48 dat = {"owner" : self.user_id, 45 49 "status": self.status, 46 50 "money" : self.money, 47 51 "seat" : self.seat} 52 if self.__cards_shown: 53 dat["cards"] = self.cards 54 return dat 48 55 49 56 def __privateData(self): … … 115 122 return False 116 123 124 #wrap up the hand. Who wins? Etc. 125 def finishHand(self): 126 if not self.hand_over: 127 raise ImproperPhaseException("Hand is not over") 128 #now, let's get a list of people who are still in. 129 still_in = [ p for p in self.__player_array if not p.has_folded ] 130 winner = None 131 if len(still_in) == 1: 132 winner = still_in[0] 133 else: 134 #create list of tuples of (id,hand) 135 hands = [ (p.id,hand.best_hand(deck.card_vals(p.cards + self.__community_cards))) 136 for p in still_in ] 137 #TODO add ties 138 hands.sort(cmp = lambda a,b: cmp(a[1],b[1])) 139 winner = hands.pop() 140 print "%s winds the hand with %s" % (winner[0], hand.HAND_ORDERS[winner[1][0]]) 141 142 143 144 117 145 #return false if game is over 118 146 def nextHand(self): … … 122 150 self.__phase = None 123 151 self.__community_cards = [] 152 self.__last_bet_raise = None 124 153 if self.__hand_count == None: 125 154 self.__hand_count = 0 … … 169 198 elif pn == "river": 170 199 self.__community_cards.append(self.__deck.deal()) 200 elif pn == "showdown": 201 #If somebody bet or raised, they have to show 202 if self.__last_bet_raise != None: 203 self.__player_array[self.__last_bet_raise].doAction("show",None) 204 self.__action_on = self.__last_bet_raise 205 else: 206 #Else we start fromt he button 207 self.__action_on = None 171 208 172 209 … … 265 302 raise InvalidActionException("Value out of range") 266 303 self.current_player.doAction(action,value) 304 if action == "bet" or action == "raise": 305 self.__last_bet_raise = self.__action_on 267 306 if not self.nextAction(): 268 307 if not self.nextPhase(): 308 self.finishHand() 269 309 if not self.nextHand(): 270 310 #TODO add game end code handing hurr … … 328 368 def checkStart(self): 329 369 if self.isFull(): 330 self.__game_state = holdemround(self.__players,self.__ blinds,self.__format)370 self.__game_state = holdemround(self.__players,self.__format) 331 371 self.__game_started = True 332 372 self.__game_state.nextHand()
