]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/poker/poker.factor
use radix literals
[factor.git] / extra / poker / poker.factor
index 9c68aaaa975679c2ae196a4fefffa047c03dcc8f..4a192f8e77ee8aa99c4c0585a681f5f926adc7d6 100644 (file)
@@ -1,11 +1,11 @@
-! Copyright (c) 2009 Aaron Schaefer. All rights reserved.
-! Copyright (c) 2009 Doug Coleman.
+! Copyright (c) 2009 Aaron Schaefer, Doug Coleman. All rights reserved.
 ! The contents of this file are licensed under the Simplified BSD License
 ! A copy of the license is available at http://factorcode.org/license.txt
 USING: accessors arrays ascii assocs binary-search combinators
 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
@@ -120,7 +120,7 @@ M: integer >ckf ;
     " " 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 ;
@@ -132,16 +132,16 @@ M: integer >ckf ;
     [ 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 ;
 
@@ -153,7 +153,7 @@ M: integer >ckf ;
     ] if ;
 
 : >card-rank ( card -- string )
-    -8 shift HEX: F bitand RANK_STR nth ;
+    -8 shift 0xF bitand RANK_STR nth ;
 
 : >card-suit ( card -- string )
     {
@@ -215,7 +215,7 @@ ERROR: no-card card deck ;
         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 )
@@ -260,5 +260,8 @@ ERROR: bad-suit-symbol ch ;
 : value>hand-name ( value -- string )
     value>rank VALUE_STR nth ;
 
+: string>hand-name ( string -- string' )
+    string>value value>hand-name ;
+
 SYNTAX: HAND{
-    "}" parse-tokens [ card> ] { } map-as suffix! ;
+    "}" [ card> ] map-tokens suffix! ;