Playing cards: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: this code is broken) |
(→{{header|Perl 6}}: modernize) |
||
Line 2,008: | Line 2,008: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{incorrect|generates "use of unitialized value" warnings and no significative output}} |
|||
<lang perl6>enum Pip <A 2 3 4 5 6 7 8 9 10 J Q K>; |
<lang perl6>enum Pip <A 2 3 4 5 6 7 8 9 10 J Q K>; |
||
enum Suit <♦ ♣ ♥ ♠>; |
enum Suit <♦ ♣ ♥ ♠>; |
||
class Card { |
class Card { |
||
has Pip $ |
has Pip $.pip; |
||
has Suit $ |
has Suit $.suit; |
||
method Str { $!pip ~ $!suit } |
method Str { $!pip ~ $!suit } |
||
} |
} |
||
class Deck { |
class Deck { |
||
has Card @ |
has Card @.cards = pick *, |
||
⚫ | |||
submethod BUILD { |
|||
⚫ | |||
⚫ | |||
} |
|||
method shuffle { @!cards .= pick: * } |
method shuffle { @!cards .= pick: * } |
||
method deal { shift @!cards } |
method deal { shift @!cards } |
||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
}</lang> |
|||
Some examples of use: |
|||
⚫ | |||
⚫ | |||
my $top = $d.deal; |
my $top = $d.deal; |
||
say "Top card: $top"; |
say "Top card: $top"; |
||
$d.shuffle; |
$d.shuffle; |
||
say "Deck, re-shuffled: ", $d;</lang> |
say "Deck, re-shuffled: ", $d;</lang> |
||
{{out}} |
|||
⚫ | |||
Output: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |