PyPokerEngine icon indicating copy to clipboard operation
PyPokerEngine copied to clipboard

Flush evaluation is wrong

Open double-free opened this issue 4 years ago • 0 comments

I know this repo is not maintained, I still post this issue here in case anyone being confused about its behavior.

Issue

Here's what I encountered:

player [SixPlayer] gets hole card ['D5', 'HA'], current stack 100
player [G7Player] gets hole card ['CQ', 'D7'], current stack 100

Street "river" started. (community card = ['DQ', 'DJ', 'D9', 'CK', 'D6'])
"['SixPlayer']" won the round 1 (stack = {'SixPlayer': 720, 'G9Player': 0, 'G5Player': 0, 'HonestPlayer': 100, 'OurPlayer': 0, 'MyPokerPlayer': 0, 'RitzPlayer': 0, 'G3Player': 80, 'G7Player': 0})

Apparently, G7 shall win the game, because it has FLUSH with "D7", but SixPlayer has FLUSH with "D5". The result is wrong.

Root cause

See here:

https://github.com/ishikota/PyPokerEngine/blob/a52a048a15da276005eca4acae96fb6eeb4dc034/pypokerengine/engine/hand_evaluator.py#L70

The flush can not be simply represented with only the max_rank_card. In fact, we need to compare these cards one by one.

In the issue we encountered, the flush was wrongly judged as the same for both G6 and G7, and then went to the 2nd bug (mentioned here), comparing the hole card, which results in G6 as the winner.

How to fix

We have to change how the "score" is represented for FLUSH. It shall contain 5 cards, instead of only 2.

# [Bit flg of hand][rank1(4bit)][rank2(4bit)]
# shall be:
# [Bit flg of hand][rank1(4bit)][rank2(4bit)][rank3(4bit)][rank4(4bit)][rank5(4bit)]

double-free avatar Jan 23 '22 16:01 double-free