@@ -48,11 +48,18 @@ def new_game(
48
48
]
49
49
if card_info_lut :
50
50
# Don't reload massive files, it takes ages.
51
- state = ShortDeckPokerState (players = players , load_card_lut = False , ** kwargs )
51
+ state = ShortDeckPokerState (
52
+ players = players ,
53
+ load_card_lut = False ,
54
+ ** kwargs
55
+ )
52
56
state .card_info_lut = card_info_lut
53
57
else :
54
58
# Load massive files.
55
- state = ShortDeckPokerState (players = players , ** kwargs )
59
+ state = ShortDeckPokerState (
60
+ players = players ,
61
+ ** kwargs
62
+ )
56
63
return state
57
64
58
65
@@ -79,8 +86,9 @@ def __init__(
79
86
f"At least 2 players must be provided but only { n_players } "
80
87
f"were provided."
81
88
)
89
+ self ._pickle_dir = pickle_dir
82
90
if load_card_lut :
83
- self .card_info_lut = self .load_card_lut (lut_path , pickle_dir )
91
+ self .card_info_lut = self .load_card_lut (lut_path , self . _pickle_dir )
84
92
else :
85
93
self .card_info_lut = {}
86
94
# Get a reference of the pot from the first player.
@@ -227,7 +235,10 @@ def apply_action(self, action_str: Optional[str]) -> ShortDeckPokerState:
227
235
return new_state
228
236
229
237
@staticmethod
230
- def load_card_lut (lut_path : str = "." , pickle_dir : bool = False ) -> Dict [str , Dict [Tuple [int , ...], str ]]:
238
+ def load_card_lut (
239
+ lut_path : str = "." ,
240
+ pickle_dir : bool = False
241
+ ) -> Dict [str , Dict [Tuple [int , ...], str ]]:
231
242
"""
232
243
Load card information lookup table.
233
244
@@ -267,7 +278,7 @@ def load_card_lut(lut_path: str = ".", pickle_dir: bool = False) -> Dict[str, Di
267
278
card_info_lut [betting_stage ] = joblib .load (fp )
268
279
elif lut_path :
269
280
logger .info (f"Loading card from single file at path: { lut_path } " )
270
- card_info_lut = joblib .load (lut_path )
281
+ card_info_lut = joblib .load (lut_path + '/card_info_lut.joblib' )
271
282
else :
272
283
card_info_lut = {}
273
284
return card_info_lut
@@ -373,20 +384,29 @@ def betting_round(self) -> int:
373
384
@property
374
385
def info_set (self ) -> str :
375
386
"""Get the information set for the current player."""
387
+ if self ._pickle_dir :
388
+ key = operator .attrgetter ("eval_card" )
389
+ else :
390
+ key = None
376
391
cards = sorted (
377
392
self .current_player .cards ,
378
- key = operator . attrgetter ( "eval_card" ) ,
393
+ key = key ,
379
394
reverse = True ,
380
395
)
381
396
cards += sorted (
382
397
self ._table .community_cards ,
383
- key = operator . attrgetter ( "eval_card" ) ,
398
+ key = key ,
384
399
reverse = True ,
385
400
)
386
- eval_cards = tuple ([card .eval_card for card in cards ])
401
+ if self ._pickle_dir :
402
+ lookup_cards = tuple ([card .eval_card for card in cards ])
403
+ else :
404
+ lookup_cards = tuple (cards )
387
405
try :
388
- cards_cluster = self .card_info_lut [self ._betting_stage ][eval_cards ]
406
+ cards_cluster = self .card_info_lut [self ._betting_stage ][lookup_cards ]
389
407
except KeyError :
408
+ import ipdb ;
409
+ ipdb .set_trace ()
390
410
return "default info set, please ensure you load it correctly"
391
411
# Convert history from a dict of lists to a list of dicts as I'm
392
412
# paranoid about JSON's lack of care with insertion order.
0 commit comments