Poker hand analyser: Difference between revisions

→‎{{header|Raku}}: tweak 'rank' and 'straight' subroutines
(→‎{{header|Raku}}: tweak 'rank' and 'straight' subroutines)
Line 3,725:
method TOP($/) {
my UInt @n = n-of-a-kind($/);
my $flush = 'flush' if flush($/);
my $straight = 'straight' if straight($/);
make rank(@n[0], @n[1], $flush, $straight);
}
multi sub rank(5,$,$,$*@) { 'five-of-a-kind' }
multi sub rank($,$,$f'flush',$s'straight') where {$f && $s}) { 'straight-flush' }
multi sub rank(4,$,$,$*@) { 'four-of-a-kind' }
multi sub rank($,$,$f'flush',$) where {$f}) { 'flush' }
multi sub rank($,$,$,$s where {$s}'straight') { 'straight' }
multi sub rank(3,2,$,$*@) { 'full-house' }
multi sub rank(3,$,$,$*@) { 'three-of-a-kind' }
multi sub rank(2,2,$,$*@) { 'two-pair' }
multi sub rank(2,$,$,$*@) { 'one-pair' }
multi sub rank($,$,$,$*@) is default { 'high-card' }
sub n-of-a-kind($/) {
Line 3,755:
# allow both ace-low and ace-high straights
constant @Faces = [ "a 2 3 4 5 6 7 8 9 10 j q k a".split: ' ' ];
constant @Possible-Straights = [ (04 ..^ (+@Faces - 5)).map: { set @Faces[$_-4 .. $_+4] } ];
 
my $faces = set @<face-card>.map: -> $/ {~$<face>.lc};
Anonymous user