line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Game::RockPaperScissorsLizardSpock; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28663
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
172
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$Game::RockPaperScissorsLizardSpock::VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %choices = ( |
9
|
|
|
|
|
|
|
'rock' => 0, |
10
|
|
|
|
|
|
|
'Spock' => 1, |
11
|
|
|
|
|
|
|
'paper' => 2, |
12
|
|
|
|
|
|
|
'lizard' => 3, |
13
|
|
|
|
|
|
|
'scissors' => 4, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
17
|
1
|
|
|
1
|
|
9
|
my $caller = caller(); |
18
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; ## no critic |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
339
|
|
19
|
1
|
|
|
|
|
2
|
*{ $caller . '::rpsls' } = \&rpsls; |
|
1
|
|
|
|
|
7631
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub rpsls { |
23
|
37
|
|
|
37
|
1
|
558
|
my ( $player1, $player2 ) = @_; |
24
|
37
|
100
|
66
|
|
|
147
|
return if !defined $player1 || !exists $choices{$player1}; |
25
|
33
|
100
|
|
|
|
58
|
if ( defined $player2 ) { |
26
|
27
|
100
|
|
|
|
66
|
return if !exists $choices{$player2}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
6
|
|
|
|
|
59
|
$player2 = ( keys %choices )[ rand keys %choices ]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
31
|
100
|
|
|
|
98
|
return 3 if $choices{$player1} == $choices{$player2}; |
33
|
|
|
|
|
|
|
|
34
|
24
|
|
|
|
|
44
|
my $difference = ( $choices{$player1} - $choices{$player2} ) % 5; |
35
|
|
|
|
|
|
|
|
36
|
24
|
100
|
100
|
|
|
86
|
if ( $difference == 1 || $difference == 2 ) { |
37
|
13
|
|
|
|
|
53
|
return 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
11
|
|
|
|
|
41
|
return 2; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |