Poker hand analyser: Difference between revisions

Content deleted Content added
m →‎{{header|Perl 6}}: tweak straight detection + indentation
Line 2,099: Line 2,099:
token joker {:i 'joker' <?{
token joker {:i 'joker' <?{
my $card = ~$/.lc;
my $card = ~$/.lc;
# allow two jokers in a hand
# allow two jokers in a hand
++%*PLAYED{$card} <= 2;
++%*PLAYED{$card} <= 2;
Line 2,127: Line 2,127:
multi sub rank($,$,$,$) is default { 'high-card' }
multi sub rank($,$,$,$) is default { 'high-card' }
sub n-of-a-kind($/) {
sub n-of-a-kind($/) {
my %faces := bag @<face-card>.map: -> $/ {~$<face>.lc};
my %faces := bag @<face-card>.map: -> $/ {~$<face>.lc};
my @counts = %faces.values.sort.reverse;
my @counts = %faces.values.sort.reverse;
@counts[0] += @<joker>;
@counts[0] += @<joker>;
return @counts;
return @counts;
}
}
Line 2,139: Line 2,139:
}
}
sub straight($/) {
sub straight($/) {
# allow both ace-low and ace-high straights
# 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 @Faces = [ "a 2 3 4 5 6 7 8 9 10 j q k a".split: ' ' ];
constant @Possible-Straights = [ (0 .. (+@Faces - 5)).map: { set @Faces[$_ .. $_+4] } ];
constant @Possible-Straights = [ (0 .. (+@Faces - 5)).map: { set @Faces[$_ .. $_+4] } ];
my $faces = set @<face-card>.map: -> $/ {~$<face>.lc};
my $non-jokers = 5 - +@<joker>;


return ?( @Possible-Straights.first: { +($faces ∩ $_) == $non-jokers; } );
my $faces = set @<face-card>.map: -> $/ {~$<face>.lc};
my $jokers = +@<joker>;
}
return ?( @Possible-Straights.first: { +($faces ∩ $_) + $jokers == 5 } );
}
}
}