Poker

cardpicture[{suit_,val_}]:=Framed[Column[{val,suit},Center,0,ItemSize->{3,2},ItemStyle->Directive[24,"Label",Bold,Switch[suit, ♡| ♢, Darker[Red, 0.2], ♣| ♠, Black]]]]

carddeck=Reverse[Flatten[Map[({{♡,#},{♣,#},{♢,#},{♠,#}})&,Join[Table[i,{i,2,10}],{J,Q,K,A}]],1]]

EvaluatePokerHand[a_List]:= With[{
dist = Sort/@Map[Length,Split/@Sort/@Transpose[a],{2}],
straight = MemberQ[Sort/@Take[Partition[Join[Table[i,{i,2,10}],{J,Q,K,A}],5,1,1],9],Sort[Last[Transpose[a]]]]
},
Text@If[straight,
If[ dist[[1]]=={5},
If[Sort[Last[Transpose[a]]]=={10,A,J,K,Q},
"royal flush","straight flush"], "straight"],
If[ dist[[1]]=={5},"flush",
Switch[dist[[2]],
{1,4},"four of a kind",
{2,3},"full house",
{1,1,3},"three of a kind",
{1,2,2},"two pair",
{1,1,1,2},"pair",
{1,1,1,1,1},"nothing"
]]]]

Manipulate[SeedRandom[seed];
Pane[
Column[Row[Flatten[{cardpicture/@# ,EvaluatePokerHand[#]}],"  "]&/@Partition[RandomSample[carddeck,5*5],5]],
{400,300}],
{{seed,1,"pick some hands"},1,1000000,1,Appearance-> "Labeled"},SaveDefinitions-> True]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Poker" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/Poker/

Contributed by: Ed Pegg Jr

A full-function Wolfram Mathematica 6 system is required to edit this notebook.
GET WOLFRAM MATHEMATICA 6 »

© The Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »