]> gitweb.factorcode.org Git - factor.git/commitdiff
Add >5 card evaluator word to poker vocab
authorAaron Schaefer <aaron@elasticdog.com>
Thu, 7 May 2009 14:19:23 +0000 (10:19 -0400)
committerAaron Schaefer <aaron@elasticdog.com>
Thu, 7 May 2009 14:19:23 +0000 (10:19 -0400)
extra/poker/poker.factor

index b4353dc92528cdeed175f779fb3a1e5c9c372dbd..df8d93d9fa352e627fa382244e6551b2b449930c 100644 (file)
@@ -2,8 +2,8 @@
 ! 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 binary-search combinators kernel locals math
-    math.bitwise math.order poker.arrays random sequences sequences.product
-    splitting ;
+    math.bitwise math.combinatorics math.order poker.arrays random sequences
+    sequences.product splitting ;
 IN: poker
 
 ! The algorithm used is based on Cactus Kev's Poker Hand Evaluator with
@@ -194,6 +194,9 @@ M: hand equal?
 : >value ( hand -- str )
     hand-rank VALUE_STR nth ;
 
+: best-hand ( str -- hand )
+    " " split 5 all-combinations [ " " join <hand> ] map infimum ;
+
 TUPLE: deck
     { cards sequence } ;