Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Alright, I see a problem. Duplicates. Eg,

    K 2 2 2 2 and 2 K 2 2 2 are both the same hand, but the above considers one king-high and the other ace-high. (2s are wild.)

    Not sure how to represent the problem now.

    -scott

    • When wild cards are used in poker doesn't five of a kind become the highest hand? At least that's what I vaguely recall from Hoyle.

      A brief skimming of wikipedia and the wikibooks for poker doesn't show that but then again I would think the odds of 5 of a kind shouldn't be much different than four of a kind except that it's a specific 4 cards that are needed.

      Not sure how it really affects your calculations though.

      • Well, this isn't real poker, but instead video poker, where the rules are made up and people like it that way. But five of a kind is the highest paying hand in one of these. The other, five 3-5's, five 6-k, and five aces are all separate hands, and flush comes before four 2s (four wilds). So the number of card combinations that have a chance to match as a hand does vary by game. Simply subtracting out things that overlap, like subtracting out non-royal flushes and four 2s seems to work, at least for the other, non-wild games.

        The other night, I wrote a short program to compute all possible wild straight flushes and filter for duplicates, and it matched the scoring logic. It matched the test run. I'm not sure if I still need the math (depends on the Nevada Gaming Commission) but at this point, I'd like of like to see the solutions.

        use strict;
        use warnings;
         
        use Algorithm::Permute;
         
        # @deck = ( map($_."h", 1..13), map($_."d", 1..13), map($_."c", 1..13), map($_."s", 1..13), );
         
        my @deck = ( reverse map($_."h", 1..13, 1), ); # one suite for now, then x4
         
        # push @deck, '2c', '2d', '2s'; # but with all of the wilds in there
         
        my %hits;
         
        for my $i (0 .. $#deck-4) {
         
            my @subdeck = (@deck[$i..$i+4], '2c', '2d', '2s');
            push @subdeck, '2h' unless grep $_ eq '2h', @subdeck;
         
        warn "subdeck: @subdeck\n";
         
            my $p = new Algorithm::Permute(\@subdeck, 5);
         
            while(my @res = $p->next) {
                my @sorted_hand = sort { sortspec($a) <=> sortspec($b) } @res;
                my $hand = join '', @sorted_hand;
                $hits{$hand}++;
            }
         
            print scalar(keys %hits), " hits\n";
         
        }
         
        my $total_hits = 0;
         
        for my $k (keys %hits) {
            $total_hits++;
        }
         
        print "total hits: $total_hits\n";

        -scott