Skip to content

Instantly share code, notes, and snippets.

@tomcha tomcha/card_sim2.pl
Created Jan 27, 2019

Embed
What would you like to do?
card_simulator_without_ref
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
my @player_a = (1, 5, 10);
my @player_b = (2, 2, 2);
my %winer = (
pa => 0,
pb => 0,
draw => 0,
);
print "How many times try it ? >>>";
chomp(my $times = <STDIN>);
for (1..$times){
for (1..3){
my $num = int(rand(40)) + 1;
my @kari;
for my $card (@player_a){
if ($card != $num){
push(@kari, $card);
}
}
@player_a = @kari;
for my $card (@player_b){
if ($card != $num){
push(@kari, $card);
}
}
@player_b = @kari;
}
if (!@player_a){
$winer{pa} += 1;
}
elsif (!@player_b){
$winer{pb} += 1;
}
else{
$winer{draw} += 1;
}
}
say "player_a win:$winer{pa}, player_b win: $winer{pb}, draw: $winer{draw}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.