Changeset 17

Show
Ignore:
Timestamp:
02/04/08 06:45:26 (11 months ago)
Author:
mike
Message:

Added antes and stuff

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • holdemtable.py

    r16 r17  
    1010 
    1111class player(object): 
    12     starting_money = 1000.0 
    13  
    14  
    15     def __init__(self, id, user_id, seat): 
     12    def __init__(self, id, user_id, seat, starting_money): 
    1613        self.__seat = seat 
    1714        self.__id = id 
    1815        self.__user_id = user_id 
    19         self.__money = self.starting_money 
     16        self.__money = starting_money 
    2017        self.__in_hand = True 
    2118        self.__cards = [] 
     
    6259        else: 
    6360            if value != None: self.__money -= value 
    64             if not self.__has_acted and action != "small_blinds" and action != "large_blinds": 
     61            if not self.__has_acted and not action in ["small_blinds","large_blinds","ante"]: 
    6562                self.__has_acted = True 
    6663            if action == "fold": self.__has_folded = True 
     
    8582 
    8683 
    87 PHASES = ["blinds", "flop", "turn", "river"] 
     84PHASES = ["blinds", "flop", "turn", "river", "showdown"] 
    8885class holdemround(object): 
    8986     
    9087 
    91     def __init__(self,players,blinds): 
     88    def __init__(self,players,format): 
    9289        self.__deck = deck.deck() 
    93         self.__blinds = blinds 
     90        self.__blinds = None 
     91        self.__round_length = format["round_length"] 
     92        self.__blind_structure = format["blinds"] 
    9493        #keep both of these on hand so we can quickly find a player 
    9594        self.__players = players 
     
    10099        self.__community_cards = None 
    101100        self.__possible_actions = None #to cache possible actions 
    102         self.__hand_count = 0 
     101        self.__hand_count = None 
     102 
    103103 
    104104    #hand over? 
     
    117117        self.__phase = None 
    118118        self.__community_cards = [] 
    119         self.__hand_count += 1 
     119        if self.__hand_count == None: 
     120            self.__hand_count = 0 
     121        else: self.__hand_count += 1 
     122        #Next phase of blinds 
     123        if self.__hand_count % self.__round_length == 0: 
     124            #Next blind phase 
     125            self.__blinds = self.__blind_structure[self.__hand_count/self.__round_length] 
    120126        print self.__player_array 
    121127        for p in self.__player_array: p.nextHand() 
     
    137143        pn = PHASES[self.__phase] 
    138144        if pn == "blinds": 
    139             self.__player_array[0].doAction("small_blinds",self.__blinds[0]) 
    140             self.__player_array[1].doAction("large_blinds",self.__blinds[1]) 
     145            self.__player_array[0].doAction("small_blinds", 
     146                    min(self.__player_array[0],self.__blinds[1])) 
     147 
     148            self.__player_array[1].doAction("large_blinds", 
     149                    min(self.__player_array[1],self.__blinds[2])) 
     150            #do antes for the rest 
     151            for p in self.__player_array[2:]: 
     152                p.doAction("ante",min(p.money,self.__blinds[0])) 
     153 
    141154            self.__action_on = 1 
    142155        elif pn == "flop": 
     
    194207        money_in_phase = me.money_in_phase 
    195208         
    196         min_bet = self.__blinds[1] 
     209        min_bet = self.__blinds[2] 
    197210        if PHASES[self.__phase] == "river": min_bet *= 2 
    198211 
     
    216229                 "action_on": self.current_player.seat, 
    217230                 "pot_before_phase": self.pot, 
    218                  "community_cards": self.__community_cards } 
     231                 "community_cards": self.__community_cards, 
     232                 "hand_number": self.__hand_count, 
     233                 "current_blinds": self.__blinds} 
    219234        p_actions = {} 
    220235 
     
    253268    pot = property( lambda self: sum([ p.money_in_pot for p in self.__player_array] )) 
    254269 
     270DEFAULT_FORMAT = {"max_players":3, 
     271                  "round_length":8, 
     272                  "starting_money":2000.0. 
     273                  "blinds":[(None,25,50), 
     274                            (None,50,100), 
     275                            (None,100,200), 
     276                            (25,100,200), 
     277                            (25,150,300), 
     278                            (50,200,400), 
     279                            (75,300,600), 
     280                            (100,500,1000), 
     281                            (200,500,1500), 
     282                            (300,1000,2000), 
     283                            (400,1500,3000), 
     284                            (500,2000,4000), 
     285                            (500,3000,6000), 
     286                            (1000,4000,8000), 
     287                            (1000,5000,10000), 
     288                            (2000,5000,15000), 
     289                            (3000,10000,20000), 
     290                            (4000,15000,30000), 
     291                            (5000,20000,40000)]} 
    255292 
    256293class holdemtable: 
    257     def __init__(self, name, max_players = 3, blinds = (5.0,10.0)): 
    258         self.__max_players = max_players 
     294    def __init__(self, name, format = DEFAULT_FORMAT): 
     295        self.__max_players = format["max_players"] 
    259296        self.__players={} 
    260297        self.__game_started = False 
     
    262299        self.__holdemgame = None 
    263300        self.__deferreds = [] 
    264         self.__blinds = blinds 
     301        self.__format = format 
    265302        self.__cached_response = None 
    266303 
     
    268305    def addPlayer(self, data, deferred ): 
    269306        p_id = data['client_id'] 
    270         self.__players[p_id]=player(p_id, data['user_id'], len(self.__players)) 
     307        self.__players[p_id]=player(p_id, 
     308                                    data['user_id'], 
     309                                    len(self.__players), 
     310                                    self.__format["starting_money"]) 
    271311        self.addDeferred( p_id, deferred ) 
    272312        self.stateChanged("Player Added") 
     
    275315    def checkStart(self): 
    276316        if self.isFull(): 
    277             self.__game_state = holdemround(self.__players,self.__blinds) 
     317            self.__game_state = holdemround(self.__players,self.__blinds,self.__format) 
    278318            self.__game_started = True 
    279319            self.__game_state.nextHand() 
     
    295335            table_info["game_in_progress"] = self.__game_started 
    296336            table_info["name"] = self.__name 
    297             table_info["blinds"] = self.__blinds 
     337            table_info["format"] = self.__format 
    298338 
    299339            players = {}