line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Games::Checkers, Copyright (C) 1996-2012 Mikhael Goikhman, migo@cpan.org |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
4
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
5
|
|
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
6
|
|
|
|
|
|
|
# (at your option) any later version. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
9
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11
|
|
|
|
|
|
|
# GNU General Public License for more details. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
14
|
|
|
|
|
|
|
# along with this program. If not, see . |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
17
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package Games::Checkers::CreateMoveList; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use base 'Games::Checkers::ExpandMoveList'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
331
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
6
|
use Games::Checkers::Constants; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
26
|
1
|
|
|
1
|
|
5
|
use Games::Checkers::MoveConstants; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new ($$$) { |
29
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
30
|
0
|
|
|
|
|
|
my $board = shift; |
31
|
0
|
|
|
|
|
|
my $color = shift; |
32
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($board, $color); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self->{mbs} = []; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self->build; |
37
|
0
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub gather_move ($) { |
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $move = $self->create_move; |
44
|
0
|
0
|
|
|
|
|
return Err unless $move; ### not needed |
45
|
0
|
0
|
|
|
|
|
die "Internal Error" if $move == NO_MOVE; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
push @{$self->{mbs}}, [ $move, $self->{work_board}->clone ]; |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return Ok; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get_move_boards ($) { |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $self->{mbs}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
package Games::Checkers::CountMoveList; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
1
|
|
6
|
use base 'Games::Checkers::ExpandMoveList'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
1
|
|
6
|
use Games::Checkers::Constants; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub new ($$$) { |
67
|
0
|
|
|
0
|
|
|
my $class = shift; |
68
|
0
|
|
|
|
|
|
my $board = shift; |
69
|
0
|
|
|
|
|
|
my $color = shift; |
70
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($board, $color); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->{count} = 0; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$self->build; |
75
|
0
|
|
|
|
|
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub gather_move ($) { |
79
|
0
|
|
|
0
|
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
$self->{count}++; |
81
|
0
|
|
|
|
|
|
return Ok; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_count ($) { |
85
|
0
|
|
|
0
|
|
|
my $self = shift; |
86
|
0
|
0
|
|
|
|
|
return $self->{status} == Ok ? $self->{count} : 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
package Games::Checkers::CreateUniqueMove; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
1
|
|
6
|
use base 'Games::Checkers::ExpandMoveList'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
113
|
|
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
1
|
|
6
|
use Games::Checkers::Constants; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
96
|
1
|
|
|
1
|
|
5
|
use Games::Checkers::MoveConstants; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub new ($$$) { |
99
|
0
|
|
|
0
|
|
|
my $class = shift; |
100
|
0
|
|
|
|
|
|
my $board = shift; |
101
|
0
|
|
|
|
|
|
my $color = shift; |
102
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($board, $color); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$self->{move} = NO_MOVE; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$self->build; |
107
|
0
|
|
|
|
|
|
return $self; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub gather_move ($) { |
111
|
0
|
|
|
0
|
|
|
my $self = shift; |
112
|
0
|
0
|
|
|
|
|
return Err if $self->{move} != NO_MOVE; |
113
|
0
|
|
|
|
|
|
$self->{move} = $self->create_move; |
114
|
0
|
|
|
|
|
|
return Ok; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_move ($) { |
118
|
0
|
|
|
0
|
|
|
my $self = shift; |
119
|
0
|
0
|
|
|
|
|
return $self->{status} == Ok ? $self->{move} : NO_MOVE; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
package Games::Checkers::CreateVergeMove; |
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
1
|
|
6
|
use base 'Games::Checkers::ExpandMoveList'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
1
|
|
5
|
use Games::Checkers::Constants; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
5
|
|
129
|
1
|
|
|
1
|
|
5
|
use Games::Checkers::MoveConstants; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
130
|
1
|
|
|
1
|
|
5
|
use Games::Checkers::Move; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
401
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub new ($$$$$$) { |
133
|
0
|
|
|
0
|
|
|
my $class = shift; |
134
|
0
|
|
|
|
|
|
my $board = shift; |
135
|
0
|
|
|
|
|
|
my $color = shift; |
136
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($board, $color); |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
die "Not enough arguments in constructor" unless @_ >= 3; |
139
|
0
|
|
|
|
|
|
my $is_beat = $self->{is_beat} = shift; |
140
|
0
|
|
|
|
|
|
my $src = $self->{src0} = shift; |
141
|
0
|
|
|
|
|
|
my $dst = $self->{dst0} = shift; |
142
|
0
|
|
|
|
|
|
my @extra_dsts = @_; |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
die "Bad verge move source location ($src): not occupied\n" |
145
|
|
|
|
|
|
|
unless $board->occup($src); |
146
|
0
|
0
|
|
|
|
|
die "Bad verge move source location ($src): incorrect color\n" |
147
|
|
|
|
|
|
|
unless $board->color($src) == $color; |
148
|
0
|
0
|
0
|
|
|
|
die "Bad verge move source location ($src): can't beat\n" |
149
|
|
|
|
|
|
|
unless !$is_beat || $board->can_piece_beat($src); |
150
|
|
|
|
|
|
|
# die "Bad verge move source location ($src): can't step\n" |
151
|
|
|
|
|
|
|
# unless $is_beat || $board->can_piece_step($src); |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if (!$is_beat) { |
154
|
0
|
0
|
|
|
|
|
if ($board->can_piece_step($src, $dst)) { |
155
|
0
|
0
|
|
|
|
|
die "Bad verge move ($src-$dst): extra destinations @extra_dsts given\n" |
156
|
|
|
|
|
|
|
if @extra_dsts; |
157
|
0
|
|
|
|
|
|
$self->{move} = new Games::Checkers::Move($is_beat, $src, [$dst]); |
158
|
0
|
|
|
|
|
|
return $self; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
# give it the last chance |
161
|
0
|
0
|
|
|
|
|
$board->can_piece_beat($src) ? $is_beat = 1 : |
162
|
|
|
|
|
|
|
die "Bad verge move ($src-$dst): can't step\n"; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# support British rules |
166
|
0
|
0
|
|
|
|
|
if ($is_beat) { |
167
|
0
|
0
|
|
|
|
|
if ($board->can_piece_beat($src, $dst)) { |
168
|
0
|
|
|
|
|
|
$self->{move} = new Games::Checkers::Move($is_beat, $src, [$dst, @extra_dsts]); |
169
|
0
|
|
|
|
|
|
return $self; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
0
|
|
|
|
|
|
$self->{move} = NO_MOVE; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
$self->build; |
175
|
0
|
|
|
|
|
|
return $self; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub gather_move ($) { |
179
|
0
|
|
|
0
|
|
|
my $self = shift; |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
return Err if !$self->{must_beat}; |
182
|
0
|
0
|
0
|
|
|
|
return Ok if $self->{src} != $self->{src0} || $self->dst_1 != $self->{dst0}; |
183
|
|
|
|
|
|
|
|
184
|
0
|
0
|
|
|
|
|
return Err if $self->{move} != NO_MOVE; |
185
|
0
|
|
|
|
|
|
$self->{move} = $self->create_move; |
186
|
0
|
|
|
|
|
|
return Ok; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub get_move ($) { |
190
|
0
|
|
|
0
|
|
|
my $self = shift; |
191
|
0
|
0
|
|
|
|
|
return $self->{status} == Ok ? $self->{move} : NO_MOVE; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |