Last active
August 3, 2016 12:46
-
-
Save masak/57a50e1f4eae4f09b365e9c5f3c92a1f to your computer and use it in GitHub Desktop.
A modern take on rock-paper-scissors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Hand <Rock Paper Scissors>; | |
multi infix:<beats>(Paper, Rock) { True } | |
multi infix:<beats>(Rock, Scissors) { True } | |
multi infix:<beats>(Scissors, Paper) { True } | |
multi infix:<beats>($, $) { False } | |
my $p1 = Hand.roll; | |
say "Player 1 chooses {$p1}"; | |
my $p2 = Hand.roll; | |
say "Player 2 chooses {$p2}"; | |
say do { | |
when $p1 beats $p2 { "Player 1 wins!" } | |
when $p2 beats $p1 { "Player 2 wins!" } | |
default { "It's a tie!" } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment