Changeset 15

Show
Ignore:
Timestamp:
02/03/08 20:47:55 (4 years ago)
Author:
mike
Message:

Added a facility to cache the response

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • holdemtable.py

    r14 r15  
    256256        self.deferred = [] 
    257257        self.blinds = blinds 
     258        self.__cached_response = None 
    258259 
    259260 
     
    279280 
    280281    def genStatus(self, p_id): 
    281         root = {} 
    282         root["stat"] = "ok" 
    283         root["type"] = "game_state" 
     282        if self.__cached_response == None: 
     283            root = {} 
     284            root["stat"] = "ok" 
     285            root["type"] = "game_state" 
     286 
     287            table_info = {} 
     288            table_info["game_in_progress"] = self.game_started 
     289            table_info["name"] = self.name 
     290            table_info["blinds"] = self.blinds 
     291 
     292            players = {} 
     293            for (n,d) in self.players.items(): 
     294                players[n] = d.publicData() 
     295            table_info["players"] = players 
     296            root["table_info"] = table_info 
     297             
     298            if self.game_started: 
     299                root["game_state"] = self.game_state.getState() 
     300            self.__cached_response = root 
     301 
     302        copy = self.__cached_response.copy() 
    284303        you = self.players[p_id].privateData() 
    285304 
     
    291310        if req_action: you["possible_actions"] = self.game_state.possibleActions() 
    292311 
    293         root["you"] = you 
    294  
    295         table_info = {} 
    296         table_info["game_in_progress"] = self.game_started 
    297         table_info["name"] = self.name 
    298         table_info["blinds"] = self.blinds 
    299  
    300         players = {} 
    301         for (n,d) in self.players.items(): 
    302             players[n] = d.publicData() 
    303         table_info["players"] = players 
    304         root["table_info"] = table_info 
    305          
    306         if self.game_started: 
    307             root["game_state"] = self.game_state.getState() 
    308         return root 
     312        copy["you"] = you 
     313        return copy 
    309314 
    310315    def action(self, p_id, action, value): 
     
    319324        dl = self.deferred[:] 
    320325        self.deferred = [] 
     326        self.__cached_response = None 
    321327        for (p,d) in dl: 
    322328            stat = self.genStatus(p)