#!/usr/bin/perl -w $count= $ARGV[0] || 100; srand(time()); sub deal{ my ( $card ,$hand) =@_; unless( defined $hand){ $hand=$card; $card=int rand(scalar @$hand) } $debug=0; # print"<$card> ", $#$hand ; my($ret); $ret= $$hand[$card]; printf"(%s)",$card if( $debug) ; if($card == $#$hand){ pop @$hand; }else{ $$hand[$card]=pop@$hand; } return($ret); } %value= ( "Straight Flush \n" => 25, "Flush \n" => 4, "Straight \n" => 3, "full house \n" => 7, "2 pair \n" => 1, "3 of a kind \n" => 2 , "4 of a kind \n" => 24, "2 of a kind (royal) \n" =>0, "nothing\n" => -1 ); @cards= qw ( 2 3 4 5 6 7 8 9 T J Q K A ); foreach $suitname ( qw( H C D S ) ){ my @suitname; foreach $card ( @cards ){ push @suitname, " $card$suitname"; } push @fulldeck,@suitname; }; # printf "<%s>\n",join(" ",@fulldeck); my ( @sdeck ,@suit,@suit2, $pick,$pick2,$pick1); @sdeck=@cards; # foreach $i (@cards){ printf "%s ",deal(0,\@sdeck) ;} print"\n"; $ord=0; foreach $c ( qw( 2 3 4 5 6 7 8 9 T J Q K A )){ $ord{$c}= $ord++; }; %init=( "Ace High 3 str flush" => sub { ;( 10,11,12 ) }, "Ace high 4 str flush" => sub { ;( 9,10,11,12 ) }, "High 3 str flush" => sub { ;( 9,10,11 ) }, "High 3 straight" => sub { ;( 9+deal(\@suit),10+deal(\@suit),11+deal(\@suit) ) }, "High lovers" => sub { ;( 10, 11) }, "High pair" => sub {;( 10+deal(\@suit), 10+deal(\@suit) ) }, "Low 2 straight flush" => sub { ;( 5,6 ) }, "Low 2 split flush" => sub { ;( 4,6 ) }, "Low 2 flush" => sub { ;( 4,8 ) }, "Low 3 str flush" => sub { ;( 4,5,6 ) }, "Low 4 str flush" => sub { ;( 4,5,6,7 ) }, "Low 4 flush" => sub { ;( 4,12,6,7 ) }, "Low pair" => sub {;( 1+deal(\@suit), 1+deal(\@suit) ) }, "ace" => sub { ;( 12 ) }, "high & low" => sub { ;( 3,11) }, "high 4 str flush" => sub { ;( 8,9,10,11 ) }, "high 4 straight" => sub { ;( 8+deal(\@suit),9+deal(\@suit),10+deal(\@suit),7+deal(\@suit) ) }, "high friends" => sub {; ( 9+deal(\@suit) , 10+deal(\@suit) ) }, "High couple" => sub { ;( 10, 11+13) }, "low 3 straight" => sub { ;( 6+deal(\@suit),7+deal(\@suit),8+deal(\@suit) ) }, "low 4 straight" => sub { ;( 6+deal(\@suit),5+deal(\@suit),7+deal(\@suit),8+deal(\@suit) ) }, "queen" => sub { ;( 10 ) }, "random 3 flush" => sub { ;( 3,7,11) }, "low High 3 flush" => sub { ;( 3,7,11) }, "totally random" => sub { ; ()} ); foreach $start ( keys %init ){ $initprog=$init{$start}; foreach $v (keys %value ){ $count{$v}=0; }; @cards= qw ( 2 3 4 5 6 7 8 9 T J Q K A ); for ($loop1=0 ; $loop1<$count; $loop1++){ $debug=0; $hand=""; @suit=( 0,13,26,39 ); @suit2=( 0,13,26,39 ); @deck= @fulldeck; #$start="High couple"; $pick=int(rand(4)+9); @start=&$initprog ; $debug=1; @suit=( 0,13,26,39 ); foreach $card ( sort ( { $b - $a } @start )) { $hand .= deal($card,\@deck); }; # print "$hand\n"; $rdeal=5 - ( scalar ( ()=split(" ",$hand) ) ); for ($n=0; $n++ < $rdeal; ){ $hand .= deal( int(rand(scalar@deck)),\@deck ); } $original=$hand; $result="nothing\n"; if($hand =~ / (.). \1. \1. \1. \1./){ $result=sprintf "5 of a kind?? <%s> [ %s ]\n",$1,$hand; }elsif( $hand =~ s/ (.).(.*) \1.(.*) \1.(.*) \1./$2$3$4/){ $result=sprintf "4 of a kind \n", join("> <",$1,$original,$hand); }elsif( $hand =~ s/ (.).(.*) \1.(.*)\1./$2$3/){ $first=$1; if( $hand =~ s/ (.).(.*) \1./$2/){ $result=sprintf "full house \n", join("> <",$first,$1,$original,$hand); }else{ $result=sprintf "3 of a kind \n", join("> <",$1,$original,$hand); } }elsif( $hand =~ s/ (.).(.*) \1./$2/){ $first=$1; if( $hand =~ s/ (.).(.*) \1./$2/){ $result=sprintf "2 pair \n", join("> <",$first,$1,$original,$hand); }else{ if ( $first =~ /([AKQJ])/){ $result=sprintf "2 of a kind (royal) \n", join("> <",$1,$original,$hand); } } }else{ $first="UNDEF"; if($hand =~ / .(.) .\1 .\1 .\1 .\1/){ $result=sprintf "Flush \n", join("> <",$first,$1,$original,$hand); }; $hand =~ / (.). (.). (.). (.). (.)./; $p=join("",sort { $ord{$a} - $ord{ $b}} ($1,$2,$3,$4,$5)); # straight -- or ace low stright if ( "23456789TJQKA 2345A" =~ /$p/){ if($result =~ /(Flush)/){ $result=sprintf "Straight Flush \n",$original }else{ $result=sprintf "Straight \n", join("> <",$first,"\$1",$original,$p); }; }; # print "$hand $p\n"; $|=1; }; $debug=0; printf "%s %s",$original, $result if $debug && $result eq "nothing\n"; $debug=0; $count{$result}++; }; $bank=0; print "_____ $start\n"; foreach $result( sort {$count{$a}-$count{$b}} keys %count){ chomp( $name=$result); $hands=$count{$result}/$count*100; $earned=$value{$result}*$count{$result}; $print=sprintf "%4d\t%15s\t%7.4f%% %d\n" ,$count{$result} ,$name ,$hands ,$earned; $bank+=$earned; print $print; $count{$result}=0; } printf "%30s total bank: %.4f (%d)\n\n",$start,$bank/$count, $bank; };