fry kernel locals math math.bitwise math.combinatorics
math.order math.statistics poker.arrays random sequences
sequences.product splitting grouping lexer strings ;
+FROM: sequences => change-nth ;
IN: poker
! The algorithm used is based on Cactus Kev's Poker Hand Evaluator with
" " split [ >ckf ] map ;
: flush? ( cards -- ? )
- HEX: F000 [ bitand ] reduce 0 = not ;
+ 0xF000 [ bitand ] reduce 0 = not ;
: rank-bits ( cards -- q )
0 [ bitor ] reduce -16 shift ;
[ 1 ] 2dip [ dip * ] curry [ swap ] prepose each ; inline
: prime-bits ( cards -- q )
- [ HEX: FF bitand ] map-product ;
+ [ 0xFF bitand ] map-product ;
: perfect-hash-find ( q -- value )
#! magic to convert a hand's unique identifying bits to the
#! proper index for fast lookup in a table of hand values
- HEX: E91AAA35 +
+ 0xE91AAA35 +
dup -16 shift bitxor
dup 8 shift w+
dup -4 shift bitxor
- [ -8 shift HEX: 1FF bitand adjustments-table nth ]
+ [ -8 shift 0x1FF bitand adjustments-table nth ]
[ dup 2 shift w+ -19 shift ] bi
bitxor values-table nth ;
] if ;
: >card-rank ( card -- string )
- -8 shift HEX: F bitand RANK_STR nth ;
+ -8 shift 0xF bitand RANK_STR nth ;
: >card-suit ( card -- string )
{
sampled 2 cut :> ( hole2 community2 )
hole1 community community2 3append :> hand1
hole2 community community2 3append :> hand2
- hand1 hand2 [ best-holdem-hand 2array ] bi@ <=> +lt+ =
+ hand1 hand2 [ best-holdem-hand 2array ] compare +lt+ =
] count ;
:: compare-holdem-hands ( holes deck n -- seq )
string>value value>hand-name ;
SYNTAX: HAND{
- "}" parse-tokens [ card> ] { } map-as suffix! ;
+ "}" [ card> ] map-tokens suffix! ;