Flush lookup table doesn't contain prime
Closed this issue · 4 comments
When running simulations I find the following error. I don't understand the bit encoding/lookup tables yet - do you know what's going on? I can avoid flushes for now though. FYI, deuces has the exact same error and it is irrespective of suit.
from pluribus.game.card import Card
from pluribus.game.evaluation import Evaluator
evaluator = Evaluator()
player_cards = [Card(rank='ace', suit='spades'), Card(rank='8', suit='spades')]
table_cards = [
Card(rank='ace', suit='clubs'),
Card(rank='king', suit='diamonds'),
Card(rank='king', suit='spades'),
Card(rank='8', suit='spades'),
Card(rank='3', suit='spades')
]
player_hand_rank = evaluator.evaluate(
board=[c.eval_card for c in table_cards],
cards=[c.eval_card for c in player_cards],
)
hand_class_int = evaluator.get_rank_class(player_hand_rank)
hand_class_str = evaluator.class_to_string(hand_class_int).lower()
print(f"rank: {player_hand_rank}, hand: {hand_class_str}")
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-4-cdd0dd259205> in <module>
13 player_hand_rank = evaluator.evaluate(
14 board=[c.eval_card for c in table_cards],
---> 15 cards=[c.eval_card for c in player_cards],
16 )
17 hand_class_int = evaluator.get_rank_class(player_hand_rank)
~/Desktop/environments/poker/lib/python3.7/site-packages/pluribus/game/evaluation/evaluator.py in evaluate(self, cards, board)
29 """
30 all_cards = cards + board
---> 31 return self.hand_size_map[len(all_cards)](all_cards)
32
33 def _five(self, cards):
~/Desktop/environments/poker/lib/python3.7/site-packages/pluribus/game/evaluation/evaluator.py in _seven(self, cards)
78 for combo in all5cardcombobs:
79
---> 80 score = self._five(combo)
81 print(score, minimum)
82 if score < minimum:
~/Desktop/environments/poker/lib/python3.7/site-packages/pluribus/game/evaluation/evaluator.py in _five(self, cards)
43 handOR = (cards[0] | cards[1] | cards[2] | cards[3] | cards[4]) >> 16
44 prime = EvaluationCard.prime_product_from_rankbits(handOR)
---> 45 return self.table.flush_lookup[prime]
46
47 # otherwise
I am on my mobile on top of a welsh mountain atm, so unfortunately can’t test to confirm, but I think I see what it is: You have an 8 of spades in your table cards list and your player hand cards list, and this causes issues in the lookup table due to its illegality.
Oops, must have had a mistake in my game simulation allowing this. Going to leave this issue open for a little bit in case I can reproduce on a legal hand later
If you want to push your full script to a WIP PR I can give it a quick look if that helps
Closing issue, it is working as expected