line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Mastermind::Solver; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
842
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
95
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
107
|
|
5
|
3
|
|
|
3
|
|
25
|
use base qw(Class::Accessor::Fast); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2968
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(game won) ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
1
|
263
|
my( $class, $game ) = @_; |
13
|
2
|
|
|
|
|
31
|
my $self = $class->SUPER::new( { game => $game } ); |
14
|
2
|
|
|
|
|
39
|
$self->reset; |
15
|
2
|
|
|
|
|
6
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub move { |
19
|
8
|
|
|
8
|
1
|
16
|
my( $self, $guess ) = @_; |
20
|
8
|
100
|
|
|
|
27
|
return ( 1, undef, undef ) if $self->won; |
21
|
|
|
|
|
|
|
|
22
|
7
|
|
66
|
|
|
75
|
$guess ||= $self->guess; |
23
|
7
|
|
|
|
|
20
|
my $result = $self->game->play( @$guess ); |
24
|
7
|
100
|
|
|
|
390
|
if( $result->[0] == $self->game->holes ) { |
25
|
1
|
|
|
|
|
8
|
$self->{won} = 1; |
26
|
|
|
|
|
|
|
} else { |
27
|
6
|
|
|
|
|
65
|
$self->check( $guess, $result ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
7
|
|
|
|
|
94
|
return ( $self->won, $guess, $result ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub reset { |
34
|
3
|
|
|
3
|
1
|
6
|
my( $self ) = @_; |
35
|
3
|
|
|
|
|
76
|
$self->game->reset; |
36
|
3
|
|
|
|
|
108
|
$self->{won} = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |