| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Wx::App::Mastermind::Player::Computer; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1499
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use base qw(Wx::Perl::Thread::ClassPublisher Wx::App::Mastermind::Player); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
582
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Games::Mastermind::Solver::BruteForce; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
|
|
|
|
|
|
my( $class, @args ) = @_; |
|
11
|
|
|
|
|
|
|
my $self = $class->SUPER::new; |
|
12
|
|
|
|
|
|
|
$self->Wx::App::Mastermind::Player::init( @args ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
return $self; |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub moves_editable { 0 } |
|
18
|
|
|
|
|
|
|
sub answers_editable { 0 } |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub play { |
|
21
|
|
|
|
|
|
|
my( $self ) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->listener->guess; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub got_guess { |
|
27
|
|
|
|
|
|
|
my( $self, $itme, $event, $guess ) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->add_move( $guess ); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub got_answer { |
|
33
|
|
|
|
|
|
|
my( $self, $item, $event, $answer ) = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->add_answer( $answer ); |
|
36
|
|
|
|
|
|
|
$self->turn_finished; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub create_listener { |
|
40
|
|
|
|
|
|
|
my( $self, $game ) = @_; |
|
41
|
|
|
|
|
|
|
my $listener = Wx::App::Mastermind::Player::ComputerListener->create( $game, $self ); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->add_subscriber( 'guessed', $self, 'got_guess' ); |
|
44
|
|
|
|
|
|
|
$self->add_subscriber( 'answered', $self, 'got_answer' ); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $listener; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# screw multiple inheritance... |
|
50
|
|
|
|
|
|
|
sub notify_subscribers { |
|
51
|
|
|
|
|
|
|
shift->Wx::Perl::Thread::ClassPublisher::notify_subscribers( @_ ); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub terminate { |
|
55
|
|
|
|
|
|
|
my( $self ) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->listener->wpto_terminate; |
|
58
|
|
|
|
|
|
|
$self->listener->wpto_join; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package Wx::App::Mastermind::Player::ComputerListener; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use strict; |
|
64
|
|
|
|
|
|
|
use warnings; |
|
65
|
|
|
|
|
|
|
use base qw(Class::Accessor::Fast Wx::Perl::Thread::Object); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(solver handler) ); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
|
70
|
|
|
|
|
|
|
my( $class, $game, $handler ) = @_; |
|
71
|
|
|
|
|
|
|
my $self = $class->SUPER::new |
|
72
|
|
|
|
|
|
|
( { solver => Games::Mastermind::Solver::BruteForce->new( $game ), |
|
73
|
|
|
|
|
|
|
handler => $handler } ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $self; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub guess { |
|
79
|
|
|
|
|
|
|
my( $self ) = @_; |
|
80
|
|
|
|
|
|
|
my $guess = $self->solver->guess; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->handler->notify_subscribers( 'guessed', $guess ); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub on_move { |
|
86
|
|
|
|
|
|
|
my( $self, $item, $event, %params ) = @_; |
|
87
|
|
|
|
|
|
|
my $answer = $self->solver->game->play( @{$params{move}} ); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$self->handler->notify_subscribers( 'answered', $answer ); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub on_answer { |
|
93
|
|
|
|
|
|
|
my( $self, $item, $event, %params ) = @_; |
|
94
|
|
|
|
|
|
|
my $guess = $self->solver->game->history->[-1][0]; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$self->solver->check( $guess, $params{answer} ); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub reset { $_[0]->solver->reset } |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |