}
{ $notes "Cards may be specified in any order. Hands are directly comparable to each other on the basis of their computed value. Two hands are considered equal when they would tie in a game (despite being composed of different cards)." } ;
+HELP: best-hand
+{ $values { "str" string } { "hand" "a new hand" } }
+{ $description "Creates a new poker hand containing the best possible combination of the cards specified in " { $snippet "str" } "." }
+{ $examples
+ { $example "USING: kernel poker prettyprint ;"
+ "\"AS KD JC KH 2D 2S KH\" best-hand >value ." "\"Full House\"" }
+} ;
+
HELP: >cards
{ $values { "hand" "a hand" } { "str" string } }
{ $description "Outputs a string representation of a hand's cards." }
"\"AC KC QC JC TC\" <hand> >value ." "\"Straight Flush\"" }
}
{ $notes "This should not be used as a basis for hand comparison." } ;
-
-HELP: best-hand
-{ $values { "str" string } { "hand" "a new hand" } }
-{ $description "Creates a new poker hand containing the best possible combination of the cards specified in " { $snippet "str" } "." }
-{ $examples
- { $example "USING: kernel poker prettyprint ;"
- "\"AS KD JC KH 2D 2S KH\" best-hand >value ." "\"Full House\"" }
-} ;
: <hand> ( str -- hand )
parse-cards dup hand-value hand boa ;
+: best-hand ( str -- hand )
+ parse-cards 5 all-combinations
+ [ dup hand-value hand boa ] map infimum ;
+
: >cards ( hand -- str )
cards>> [ card>string ] map " " join ;
: >value ( hand -- str )
hand-rank VALUE_STR nth ;
-: best-hand ( str -- hand )
- parse-cards 5 all-combinations
- [ dup hand-value hand boa ] map infimum ;
-
TUPLE: deck
{ cards sequence } ;