P
pt
I'm trying to figure out a fast, efficient way to represent a single,
52 card deck plus player & community card hands for a Texas holdem
poker simulation. I need to be able to detect hand classifications
(X-of-a-kind, flush, straight, etc) and winning hands. I was thinking
of using a string & RE. I was assuming (yea, I know...) that a "hand"
data structure based on hash or array would slow things down. Here's
my string-based hand idea:
Cards are represented by 2 chars: rank & suit. 2-9,T,J,Q,K,A and
DCHS. 5 of Diamonds would be "5D". Player's hand (as a string) would
be concatenated with community cards to form a searchable string :
"5DTH2C3S4H". Pair detection regex would be /(.)[DCHS].*\1/
This makes straight detection hard without sorting, and I'm trying to
make this fast.
Any suggestions would be appreciated. Thanks in advance.
52 card deck plus player & community card hands for a Texas holdem
poker simulation. I need to be able to detect hand classifications
(X-of-a-kind, flush, straight, etc) and winning hands. I was thinking
of using a string & RE. I was assuming (yea, I know...) that a "hand"
data structure based on hash or array would slow things down. Here's
my string-based hand idea:
Cards are represented by 2 chars: rank & suit. 2-9,T,J,Q,K,A and
DCHS. 5 of Diamonds would be "5D". Player's hand (as a string) would
be concatenated with community cards to form a searchable string :
"5DTH2C3S4H". Pair detection regex would be /(.)[DCHS].*\1/
This makes straight detection hard without sorting, and I'm trying to
make this fast.
Any suggestions would be appreciated. Thanks in advance.