Eliminate redundant unique5 lookup for poker hands
parent
ee9f509e82
commit
7c898bd553
|
@ -117,9 +117,6 @@ CONSTANT: VALUE_STR { "" "Straight Flush" "Four of a Kind" "Full House" "Flush"
|
||||||
: lookup ( cards table -- value )
|
: lookup ( cards table -- value )
|
||||||
[ rank-bits ] dip nth ;
|
[ rank-bits ] dip nth ;
|
||||||
|
|
||||||
: unique5? ( cards -- ? )
|
|
||||||
unique5-table lookup 0 > ;
|
|
||||||
|
|
||||||
: map-product ( seq quot -- n )
|
: map-product ( seq quot -- n )
|
||||||
[ 1 ] 2dip [ dip * ] curry [ swap ] prepose each ; inline
|
[ 1 ] 2dip [ dip * ] curry [ swap ] prepose each ; inline
|
||||||
|
|
||||||
|
@ -138,11 +135,11 @@ CONSTANT: VALUE_STR { "" "Straight Flush" "Four of a Kind" "Full House" "Flush"
|
||||||
bitxor values-table nth ;
|
bitxor values-table nth ;
|
||||||
|
|
||||||
: hand-value ( cards -- value )
|
: hand-value ( cards -- value )
|
||||||
{
|
dup flush? [ flushes-table lookup ] [
|
||||||
{ [ dup flush? ] [ flushes-table lookup ] }
|
dup unique5-table lookup dup 0 > [ nip ] [
|
||||||
{ [ dup unique5? ] [ unique5-table lookup ] }
|
drop prime-bits perfect-hash-find
|
||||||
[ prime-bits perfect-hash-find ]
|
] if
|
||||||
} cond ;
|
] if ;
|
||||||
|
|
||||||
: >card-rank ( card -- str )
|
: >card-rank ( card -- str )
|
||||||
-8 shift HEX: F bitand RANK_STR nth ;
|
-8 shift HEX: F bitand RANK_STR nth ;
|
||||||
|
|
Loading…
Reference in New Issue