Eliminate redundant unique5 lookup for poker hands

db4
Aaron Schaefer 2009-04-08 12:30:11 -04:00
parent ee9f509e82
commit 7c898bd553
1 changed files with 5 additions and 8 deletions

View File

@ -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 ;