andrewprock / pokerstove

poker evaluation and enumeration software
BSD 3-Clause "New" or "Revised" License
794 stars 349 forks source link

Understanding the Canonization functionality #8

Closed tarath closed 10 years ago

tarath commented 10 years ago

Hi Andrew,

I am using the pokerstove library in a number of ways in an application I am building. It is amazing, thanks for open sourcing it!

To better understand that functionality I made something that directly mimics the functionality of Pokerstove. However, I am not achieving the same level of performance that the desktop version of pokerstove gets. My code produces the exact same output but takes several times as long to do so.

I think the issue is likely that I am not understanding one to canonize suits. Can you give me some insight through two simple examples:

First, a situation involving a board:

Player 1 has AsKs, player 2 has AhQs and the board is 2h.

Pokerstove says it deals 178,365 hands in this case which is 47 choose 4. However, in theory it should be able to consider clubs and diamonds as the same in this situation and instead deal 34 choose 4. Is this correct? Is there a way to use the canonize options in general to ignore suits in situations where a flush in that suit is not possible and where there is no card removal to consider for that suit and is the desktop version of pokerstove doing that?

Second, preflop situations:

If we take the same two hands as above but remove the board card, pokerstove is about 10x faster even though it says it dealt 1,712,304 games (10 times as many).

How exactly are you using the suit canonization to make the preflop calculations so fast while still accounting for the fact that AhKs has more equity vs KhQs than against KcQd? I see the option to canonize one hand to another, but how are you achieving this performance boost in 3 way scenarios?

Any insight is greatly appreciated.

Thanks!

andrewprock commented 10 years ago

The desktop version uses some very hairy partial computations and pre-enumeration code to achieve it's performance. That code is specific to hold'em, and will be published further down the line. Essentially, there are dozens of custom evaluators which group cases together like:

int countFlush5RB (double* wins, double* ties, int nhands, uint64_t deadcards, uint64_t boardhash[BOARD_SIZE], int boardrank[BOARD_SIZE], flush_cache * fc, int nflushboard);

Which is a function that counts the number of flush situations on a five rank board. Each function takes some partial state - in this case a board with five ranks, along with information about the players hands, their suit makeup, number of players, It then traverses the space of all canonical ranks, and tabulates the number of situations which have flushes as the winning hand.

tarath commented 10 years ago

I was starting to suspect that the desktop version had to be doing some very complex stuff, thanks for the reply! I'll take a crack at some light optimization myself and will rely mainly on montecarlo for now.

Thanks for the reply! On Feb 4, 2014 1:37 AM, "Andrew Prock" notifications@github.com wrote:

The desktop version uses some very hairy partial computations and pre-enumeration code to achieve it's performance. That code is specific to hold'em, and will be published further down the line. Essentially, there are dozens of custom evaluators which group cases together like:

int countFlush5RB (double* wins, double* ties, int nhands, uint64_t deadcards, uint64_t boardhash[BOARD_SIZE], int boardrank[BOARD_SIZE], flush_cache * fc, int nflushboard);

Which is a function that counts the number of flush situations on a five rank board. Each function takes some partial state - in this case a board with five ranks, along with information about the players hands, their suit makeup, number of players, It then traverses the space of all canonical ranks, and tabulates the number of situations which have flushes as the winning hand.

Reply to this email directly or view it on GitHubhttps://github.com/andrewprock/pokerstove/issues/8#issuecomment-34034537 .