blib/lib/Game/Checkers.pm

filter: Statementstmt 96.3% 237 / 246 Branchbran 81.6% 98 / 120 Conditioncond 75.7% 25 / 33 MC/DCmcdc 66.6% 14 / 21 Subroutinesub 97.2% 35 / 36 Podpod 93.7% 15 / 16 totaltotal 89.8% 424 / 472 CC 75 SCAR 19.5
CC
75
Cov
90%
_parse
14.8
_diagnose
14.4
move
10.0
CRAP 7.0
« blib/lib/Game/Checkers/Board.pm ↑ Summary blib/lib/Game/Checkers/Squares.pm »
1 package Game::Checkers;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 27 our $VERSION = '0.03';
7  
8 27 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use Game::Checkers::Squares;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use Game::Checkers::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use Game::Checkers::Move;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use Game::Checkers::Notation;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use Game::Checkers::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 27 ▶use Game::Checkers::Rules;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 27 ▶use Game::Checkers::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 27 ▶use Game::Checkers::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 27 ▶use constant NO_PROGRESS_PLIES => 80;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 27 my $STEP = \@Game::Checkers::Squares::STEP;
22 27 my $JUMP_OVER = \@Game::Checkers::Squares::JUMP_OVER;
23 27 my $JUMP_TO = \@Game::Checkers::Squares::JUMP_TO;
24  
25 27 my %FORWARD = (
26 black => {
27 Game::Checkers::Squares::SE, 1,
28 Game::Checkers::Squares::SW, 1
29 },
30 white => {
31 Game::Checkers::Squares::NE, 1,
32 Game::Checkers::Squares::NW, 1
33 },
34 );
35  
36 has board => (
37 is => 'rw',
38 isa => Object
39 27 );
40  
41 has [qw/turn variant fen/] => (
42 is => 'rw',
43 isa => Str
44 27 );
45  
46 has [qw/result draw_offered_by _legal/] => (
47 is => 'rw'
48 27 );
49  
50 has [qw/history _undo/] => (
51 is => 'rw',
52 isa => ArrayRef,
53 default => []
54 27 );
55  
56 has no_progress => (
57 is => 'rw',
58 isa => Int,
59 default => 0
60 27 );
61  
62 has repetition => (
63 is => 'rw',
64 isa => HashRef,
65 default => {}
66 27 );
67  
68 188 ▶sub BUILD {
Subroutine BUILD: called CC=9 SCAR=22.0
Pod undocumented
69 188 my ($self) = @_;
70 188 ▶ $self->variant('english') unless defined $self->variant;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->variant 173 15 188
71 188 ▶ die "variant must be english, got '" . $self->variant . "'"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->variant eq "english" 0 188 188
72 unless $self->variant eq 'english';
73  
74 188 ▶ if (!$self->board) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->board) 173 15 188
75 173 ▶ if (my $fen = $self->fen) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fen = $self->fen) { } 62 111 173
76 62 my ($board, $turn) = Game::Checkers::Board->from_fen($fen);
77 62 $self->board($board);
78 62 $self->turn($turn);
79 } else {
80 111 $self->board(Game::Checkers::Board->new);
81 }
82 }
83 188 ▶ $self->turn('black') unless defined $self->turn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->turn 111 77 188
84 die "turn must be black or white, got '" . $self->turn . "'"
85 188 ▶ unless $FORWARD{$self->turn};
Branch: 1 branch
BranchTrueFalseTotal
unless $FORWARD{$self->turn} 0 188 188
86  
87 188 ▶ $self->fen($self->board->to_fen($self->turn)) unless defined $self->fen;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->fen 111 77 188
88 $self->repetition->{$self->board->to_fen($self->turn)}++
89 188 ▶ unless %{$self->repetition};
Branch: 1 branch
BranchTrueFalseTotal
unless %{$self->repetition;} 188 0 188
90 188 $self->_check_end;
91 188 return $self;
92 }
93  
94 1291 ▶sub status {
Subroutine status: called CC=2 SCAR=6.9
Pod documented
95 1291 ▶ return $_[0]->result ? 'finished' : 'active';
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->result ? : 11 1280 1291
96 }
97  
98 5242 ▶sub ply {
Subroutine ply: called CC=1 SCAR=0.0
Pod documented
99 5242 return scalar @{$_[0]->history};
100 }
101  
102 1690 ▶sub to_fen {
Subroutine to_fen: called CC=1 SCAR=0.0
Pod documented
103 1690 my ($self) = @_;
104 1690 return $self->board->to_fen($self->turn);
105 }
106  
107 4344 ▶sub legal_moves {
Subroutine legal_moves: called CC=3 SCAR=11.0
Pod documented
108 4344 my ($self) = @_;
109 4344 my $legal = $self->_legal;
110 4344 ▶ return $legal if $legal;
Branch: 1 branch
BranchTrueFalseTotal
if $legal 2697 1647 4344
111 1647 $legal = [];
112 1647 ▶ unless ($self->result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->result) 1647 0 1647
113 1647 my $turn = $self->turn;
114 $legal = [
115 9834 map { Game::Checkers::Move->from_raw($_, $turn) }
116 1647 @{Game::Checkers::Rules::generate($self->board->position, $turn)}
117 ];
118 }
119 1647 $self->_legal($legal);
120 1647 return $legal;
121 }
122  
123 0 ▶sub legal_moves_for {
Subroutine legal_moves_for: not called CC=1 SCAR=6.9
Pod documented
124 0 my ($self, $square) = @_;
125 0 return [grep { $_->from == $square } @{$self->legal_moves}];
126 }
127  
128 61 ▶sub must_capture {
Subroutine must_capture: called CC=3 SCAR=11.0
Pod documented
129 61 my $legal = $_[0]->legal_moves;
130 61 ▶ return @{$legal} && $legal->[0]->is_jump ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$legal;} && $legal->[0]->is_jump ? : 16 45 61
Condition66%2/3
@{$legal;} and $legal->[0]->is_jump
!ll&&!rl&&r
04516
MC/DC50%1/2
@{$legal;} and $legal->[0]->is_jump
@{$legal;} $legal->[0]->is_jump
Truth table66%2/3
A and B
A= @{$legal;}B= $legal->[0]->is_jump
ABresult
0X0
100
111
131 }
132  
133 1603 ▶sub move {
Subroutine move: called CC=10 SCAR=23.0
Pod documented
134 1603 my ($self, $move) = @_;
135 1603 ▶ return $self->_error('game_over') if $self->result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->result 2 1601 1603
136  
137 1601 ▶ my $parsed = $self->_parse($move)
Branch: 1 branch
BranchTrueFalseTotal
my $parsed = $self->_parse($move) or return $self->_error("not_a_move") 1595 6 1601
138 or return $self->_error('not_a_move');
139  
140 1595 my ($from, $to) = @{$parsed}{qw/from to/};
141 1595 my $value = $self->board->at($from);
142 1595 ▶ return $self->_error('not_your_piece')
Branch: 2 branches
BranchTrueFalseTotal
unless $value and ($value > 0 ? "black" : "white") eq $self->turn 5 1590 1595
$value > 0 ? : 822 771 1593
Condition100%3/3
$value and ($value > 0 ? "black" : "white") eq $self->turn
!ll&&!rl&&r
231590
MC/DC100%2/2
$value and ($value > 0 ? "black" : "white") eq $self->turn
$value ($value > 0 ? "black" : "white") eq $self->turn
Truth table100%3/3
A and B
A= $valueB= ($value > 0 ? "black" : "white") eq $self->turn
ABresult
0X0
100
111
143 unless $value && ($value > 0 ? 'black' : 'white') eq $self->turn;
144  
145 1590 ▶ my @match = grep { $_->from == $from && $_->to == $to } @{$self->legal_moves};
Condition100%3/3
$_->from == $from && $_->to == $to
!ll&&!rl&&r
669912781575
MC/DC100%2/2
$_->from == $from && $_->to == $to
$_->from == $from $_->to == $to
Truth table100%3/3
A && B
A= $_->from == $fromB= $_->to == $to
ABresult
0X0
100
111
146 1590 ▶ if (@{$parsed->{squares}} > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$parsed->{"squares"};} > 2) 26 1564 1590
147 26 my $path = join '.', @{$parsed->{squares}};
148 26 @match = grep { join('.', @{$_->path}) eq $path } @match;
149 }
150 1590 ▶ return $self->_error('ambiguous', legal => \@match) if @match > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @match > 1 2 1588 1590
151 1588 ▶ return $self->_diagnose($parsed) unless @match;
Branch: 1 branch
BranchTrueFalseTotal
unless @match 18 1570 1588
152 1570 return $self->_play($match[0]);
153 }
154  
155 39 ▶sub undo {
Subroutine undo: called CC=4 SCAR=13.9
Pod documented
156 39 my ($self) = @_;
157 39 ▶ my $record = pop @{$self->_undo}
Branch: 1 branch
BranchTrueFalseTotal
my $record = pop @{$self->_undo;} or return $self->_error("nothing_to_undo") 38 1 39
158 or return $self->_error('nothing_to_undo');
159 38 my $move = pop @{$self->history};
160  
161 38 my $fen = $self->to_fen;
162 delete $self->repetition->{$fen}
163 38 ▶ unless --$self->repetition->{$fen};
Branch: 1 branch
BranchTrueFalseTotal
unless --$self->repetition->{$fen} 38 0 38
164  
165 38 Game::Checkers::Rules::unapply($self->board->position, $record->{raw});
166 38 ▶ $self->turn($self->turn eq 'black' ? 'white' : 'black');
Branch: 1 branch
BranchTrueFalseTotal
$self->turn eq 'black' ? : 17 21 38
167 38 $self->no_progress($record->{no_progress});
168 38 $self->draw_offered_by($record->{draw_offered_by});
169 38 $self->result(undef);
170 38 $self->_legal(undef);
171 38 return $move;
172 }
173  
174 4 ▶sub resign {
Subroutine resign: called CC=3 SCAR=11.4
Pod documented
175 4 my ($self, $side) = @_;
176 4 $side = $self->_side($side);
177 4 ▶ return $self->_error('game_over') if $self->result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->result 0 4 4
178 4 ▶ return $self->_finish($side eq 'black' ? 'white' : 'black', 'resign');
Branch: 1 branch
BranchTrueFalseTotal
$side eq 'black' ? : 4 0 4
179 }
180  
181 3 ▶sub offer_draw {
Subroutine offer_draw: called CC=2 SCAR=7.0
Pod documented
182 3 my ($self, $side) = @_;
183 3 $side = $self->_side($side);
184 3 ▶ return $self->_error('game_over') if $self->result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->result 0 3 3
185 3 $self->draw_offered_by($side);
186 3 return $side;
187 }
188  
189 5 ▶sub accept_draw {
Subroutine accept_draw: called CC=4 SCAR=13.9
Pod documented
190 5 my ($self, $side) = @_;
191 5 $side = $self->_side($side);
192 5 ▶ return $self->_error('game_over') if $self->result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->result 0 5 5
193 5 my $offered = $self->draw_offered_by;
194 5 ▶ return $self->_error('no_offer') unless $offered && $offered ne $side;
Branch: 1 branch
BranchTrueFalseTotal
unless $offered and $offered ne $side 4 1 5
Condition100%3/3
$offered and $offered ne $side
!ll&&!rl&&r
311
MC/DC100%2/2
$offered and $offered ne $side
$offered $offered ne $side
Truth table100%3/3
A and B
A= $offeredB= $offered ne $side
ABresult
0X0
100
111
195 1 return $self->_finish(undef, 'agreement');
196 }
197  
198 1 ▶sub decline_draw {
Subroutine decline_draw: called CC=3 SCAR=13.5
Pod documented
199 1 my ($self, $side) = @_;
200 1 $side = $self->_side($side);
201 1 my $offered = $self->draw_offered_by;
202 1 ▶ return $self->_error('no_offer') unless $offered && $offered ne $side;
Branch: 1 branch
BranchTrueFalseTotal
unless $offered and $offered ne $side 1 0 1
Condition33%1/3
$offered and $offered ne $side
!ll&&!rl&&r
100
MC/DC0%0/2
$offered and $offered ne $side
$offered $offered ne $side
Truth table33%1/3
A and B
A= $offeredB= $offered ne $side
ABresult
0X0
100
111
203 0 $self->draw_offered_by(undef);
204 0 return $side;
205 }
206  
207 7 ▶sub to_pdn {
Subroutine to_pdn: called CC=3 SCAR=11.0
Pod documented
208 7 my ($self, %tags) = @_;
209 7 my $opening = Game::Checkers::Board->new->to_fen('black');
210 7 ▶ if ($self->fen ne $opening) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fen ne $opening) 1 6 7
211 1 $tags{FEN} = $self->fen;
212 1 $tags{SetUp} = '1';
213 }
214 return Game::Checkers::Notation::format_pdn({
215 tags => \%tags,
216 7 ▶ moves => [map { $_->notation } @{$self->history}],
Branch: 1 branch
BranchTrueFalseTotal
$self->result ? : 2 5 7
217 result => $self->result ? $self->result->pdn : '*'
218 });
219 }
220  
221 5 ▶sub from_pdn {
Subroutine from_pdn: called CC=4 SCAR=13.9
Pod documented
222 5 my ($class, $text) = @_;
223 5 my $parsed = Game::Checkers::Notation::parse_pdn($text);
224 my $self = $class->new(
225 5 ▶ $parsed->{tags}{FEN} ? (fen => $parsed->{tags}{FEN}) : ()
Branch: 1 branch
BranchTrueFalseTotal
$parsed->{'tags'}{'FEN'} ? : 0 5 5
226 );
227 5 my $number = 0;
228 5 for my $notation (@{$parsed->{moves}}) {
229 259 $number++;
230 259 my $move = $self->move($notation);
231 259 ▶ next unless ref $move eq 'Game::Checkers::Error';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $move eq "Game::Checkers::Error" 258 1 259
232 1 die "illegal PDN: move $number, '$notation': " . $move->message . "\n";
233 }
234 4 return $self;
235 }
236  
237 15 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
238 15 my ($self) = @_;
239 15 my $clone = ref($self)->new(
240 variant => $self->variant,
241 fen => $self->fen,
242 board => $self->board->clone,
243 turn => $self->turn
244 );
245 15 $clone->history([@{$self->history}]);
246 15 $clone->_undo([@{$self->_undo}]);
247 15 $clone->no_progress($self->no_progress);
248 15 $clone->repetition({%{$self->repetition}});
249 15 $clone->draw_offered_by($self->draw_offered_by);
250 15 $clone->result($self->result);
251 15 $clone->_legal(undef);
252 15 return $clone;
253 }
254  
255 13 ▶sub _side {
Subroutine _side: called CC=3 SCAR=11.4
256 13 my ($self, $side) = @_;
257 13 ▶ $side = $self->turn unless defined $side;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $side 0 13 13
258 13 ▶ die "side must be black or white, got '$side'" unless $FORWARD{$side};
Branch: 1 branch
BranchTrueFalseTotal
unless $FORWARD{$side} 0 13 13
259 13 return $side;
260 }
261  
262 39 ▶sub _error {
Subroutine _error: called CC=1 SCAR=0.0
263 39 my ($self, $flag, %extra) = @_;
264 39 return Game::Checkers::Error->throw(
265 $flag,
266 legal => $self->legal_moves,
267 %extra
268 );
269 }
270  
271 1601 ▶sub _parse {
Subroutine _parse: called CC=12 SCAR=27.0
272 1601 my ($self, $move) = @_;
273 1601 ▶ if (ref $move eq 'Game::Checkers::Move') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $move eq "Game::Checkers::Move") 1239 362 1601
274 return {
275 from => $move->from,
276 to => $move->to,
277 1239 squares => [@{$move->path}],
278 jump => $move->is_jump
279 };
280 }
281 362 ▶ if (ref $move eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $move eq "HASH") 2 360 362
282 0 ▶ my @squares = $move->{squares} ? @{$move->{squares}}
Branch: 1 branch
BranchTrueFalseTotal
$move->{'path'} ? : 0 2 2
283 0 : $move->{path} ? @{$move->{path}}
284 2 ▶ : grep { defined } $move->{from}, $move->{to};
Branch: 1 branch
BranchTrueFalseTotal
$move->{'squares'} ? : 0 2 2
285 2 ▶ return undef unless @squares > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @squares > 1 1 1 2
286 1 for my $square (@squares) {
287 2 ▶ return undef unless $square =~ m/^[0-9]+$/ && $square >= 1 && $square <= 32;
Branch: 1 branch
BranchTrueFalseTotal
unless $square =~ /^[0-9]+$/ and $square >= 1 and $square <= 32 0 2 2
Condition33%2/6
$square =~ /^[0-9]+$/ and $square >= 1 and $square <= 32
!ll&&!rl&&r
002
$square =~ /^[0-9]+$/ and $square >= 1
!ll&&!rl&&r
002
MC/DC0%0/3
$square =~ /^[0-9]+$/ and $square >= 1 and $square <= 32
$square =~ /^[0-9]+$/ $square >= 1 $square <= 32
Truth table25%1/4
A and B and C
A= $square =~ /^[0-9]+$/B= $square >= 1C= $square <= 32
ABCresult
0XX0
10X0
1100
1111
288 }
289 return {
290 from => $squares[0],
291 to => $squares[-1],
292 squares => \@squares,
293 jump => @squares > 2 ? 1 : $move->{jump}
294 1 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
@squares > 2 ? : 0 1 1
295 }
296 360 ▶ return undef if ref $move;
Branch: 1 branch
BranchTrueFalseTotal
if ref $move 1 359 360
297 359 return Game::Checkers::Notation::parse_move($move);
298 }
299  
300 18 ▶sub _diagnose {
Subroutine _diagnose: called CC=14 SCAR=26.7
301 18 my ($self, $parsed) = @_;
302 18 my ($from, $to) = @{$parsed}{qw/from to/};
303 18 my $position = $self->board->position;
304 18 my $value = $position->[$from];
305 18 ▶ my $king = abs($value) == 2 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
abs $value == 2 ? : 1 17 18
306 18 my $base = $from * 4;
307  
308 18 for my $dir (@Game::Checkers::Squares::DIRS) {
309 56 ▶ my $forward = $king || $FORWARD{$self->turn}{$dir};
Condition100%3/3
$king || $FORWARD{$self->turn}{$dir}
l!l&&r!l&&!r
32429
MC/DC100%2/2
$king || $FORWARD{$self->turn}{$dir}
$king $FORWARD{$self->turn}{$dir}
Truth table100%3/3
A || B
A= $kingB= $FORWARD{$self->turn}{$dir}
ABresult
1X1
011
000
310 56 ▶ if ($STEP->[$base + $dir] && $STEP->[$base + $dir] == $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$STEP[$base + $dir] and $$STEP[$base + $dir] == $to) 8 48 56
Condition66%2/3
$$STEP[$base + $dir] and $$STEP[$base + $dir] == $to
!ll&&!rl&&r
0488
MC/DC50%1/2
$$STEP[$base + $dir] and $$STEP[$base + $dir] == $to
$$STEP[$base + $dir] $$STEP[$base + $dir] == $to
Truth table66%2/3
A and B
A= $$STEP[$base + $dir]B= $$STEP[$base + $dir] == $to
ABresult
0X0
100
111
311 8 ▶ return $self->_error('occupied') if $position->[$to];
Branch: 1 branch
BranchTrueFalseTotal
if $position->[$to] 3 5 8
312 5 ▶ return $self->_error('wrong_direction') unless $forward;
Branch: 1 branch
BranchTrueFalseTotal
unless $forward 3 2 5
313 2 ▶ return $self->_error('must_capture') if $self->must_capture;
Branch: 1 branch
BranchTrueFalseTotal
if $self->must_capture 2 0 2
314 0 return $self->_error('not_legal');
315 }
316 48 ▶ if ($JUMP_TO->[$base + $dir] && $JUMP_TO->[$base + $dir] == $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$JUMP_TO[$base + $dir] and $$JUMP_TO[$base + $dir] == $to) 7 41 48
Condition100%3/3
$$JUMP_TO[$base + $dir] and $$JUMP_TO[$base + $dir] == $to
!ll&&!rl&&r
2397
MC/DC100%2/2
$$JUMP_TO[$base + $dir] and $$JUMP_TO[$base + $dir] == $to
$$JUMP_TO[$base + $dir] $$JUMP_TO[$base + $dir] == $to
Truth table100%3/3
A and B
A= $$JUMP_TO[$base + $dir]B= $$JUMP_TO[$base + $dir] == $to
ABresult
0X0
100
111
317 7 ▶ return $self->_error('occupied') if $position->[$to];
Branch: 1 branch
BranchTrueFalseTotal
if $position->[$to] 0 7 7
318 7 ▶ return $self->_error('wrong_direction') unless $forward;
Branch: 1 branch
BranchTrueFalseTotal
unless $forward 0 7 7
319 7 return $self->_error('not_legal');
320 }
321 }
322 3 ▶ return $self->_error('must_capture') if $self->must_capture;
Branch: 1 branch
BranchTrueFalseTotal
if $self->must_capture 0 3 3
323 3 return $self->_error('not_legal');
324 }
325  
326 1570 ▶sub _play {
Subroutine _play: called CC=8 SCAR=20.8
327 1570 my ($self, $move) = @_;
328 1570 my $raw = $move->to_raw;
329 1570 my $mover = $self->turn;
330  
331 1570 push @{$self->_undo}, {
332 raw => $raw,
333 no_progress => $self->no_progress,
334 draw_offered_by => $self->draw_offered_by
335 };
336 1570 push @{$self->history}, $move;
337  
338 1570 Game::Checkers::Rules::apply($self->board->position, $raw);
339 1570 $self->_legal(undef);
340  
341 # an offer stands until the other side answers it with a move
342 1570 my $offered = $self->draw_offered_by;
343 1570 ▶ $self->draw_offered_by(undef) if $offered && $offered ne $mover;
Branch: 1 branch
BranchTrueFalseTotal
if $offered and $offered ne $mover 1 1569 1570
Condition100%3/3
$offered and $offered ne $mover
!ll&&!rl&&r
156811
MC/DC100%2/2
$offered and $offered ne $mover
$offered $offered ne $mover
Truth table100%3/3
A and B
A= $offeredB= $offered ne $mover
ABresult
0X0
100
111
344  
345 1570 ▶ $self->no_progress(
Branch: 1 branch
BranchTrueFalseTotal
Game::Checkers::Rules::progress($raw) ? : 1164 406 1570
346 Game::Checkers::Rules::progress($raw) ? 0 : $self->no_progress + 1
347 );
348 1570 ▶ $self->turn($mover eq 'black' ? 'white' : 'black');
Branch: 1 branch
BranchTrueFalseTotal
$mover eq 'black' ? : 805 765 1570
349  
350 1570 my $count = ++$self->repetition->{$self->to_fen};
351  
352 # a player with no move has lost, which beats either drawing counter
353 1570 $self->_check_end;
354 1570 ▶ return $move if $self->result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->result 14 1556 1570
355  
356 1556 ▶ if ($count >= 3) {
Branch: 2 branches
BranchTrueFalseTotal
if ($count >= 3) { } 2 1554 1556
elsif ($self->no_progress >= 80) { } 2 1552 1554
357 2 $self->_finish(undef, 'repetition');
358 } elsif ($self->no_progress >= NO_PROGRESS_PLIES) {
359 2 $self->_finish(undef, 'no_progress');
360 }
361 1556 return $move;
362 }
363  
364 1758 ▶sub _check_end {
Subroutine _check_end: called CC=4 SCAR=13.9
365 1758 my ($self) = @_;
366 1758 ▶ return if $self->result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->result 0 1758 1758
367 1758 ▶ return if Game::Checkers::Rules::has_move($self->board->position, $self->turn);
Branch: 1 branch
BranchTrueFalseTotal
if Game::Checkers::Rules::has_move($self->board->position, $self->turn) 1741 17 1758
368 17 ▶ return $self->_finish($self->turn eq 'black' ? 'white' : 'black', 'no_moves');
Branch: 1 branch
BranchTrueFalseTotal
$self->turn eq 'black' ? : 4 13 17
369 }
370  
371 26 ▶sub _finish {
Subroutine _finish: called CC=1 SCAR=0.0
372 26 my ($self, $winner, $reason) = @_;
373 26 $self->result(Game::Checkers::Result->new(
374 winner => $winner,
375 reason => $reason
376 ));
377 26 $self->_legal([]);
378 26 return $self->result;
379 }
380  
381 27 1;
382  
383 __END__
« blib/lib/Game/Checkers/Board.pm ↑ Summary blib/lib/Game/Checkers/Squares.pm »