blib/lib/Game/Merrills/Terminal.pm

filter: Statementstmt 96.2% 745 / 774 Branchbran 87.8% 392 / 446 Conditioncond 70.7% 162 / 229 MC/DCmcdc 51.1% 69 / 135 Subroutinesub 98.6% 73 / 74 Podpod 98.3% 60 / 61 totaltotal 87.3% 1501 / 1719 CC 331 SCAR 25.9
CC
331
Cov
90%
pick
40.0
show_choice
27.1
command
25.0
CRAP 13.3
« blib/lib/Game/Merrills/Bot.pm ↑ Summary blib/lib/Game/Merrills/Notation.pm »
1 package Game::Merrills::Terminal;
2  
3 68 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 68 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 68 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7 68 ▶use Game::Merrills;
Subroutine __ANON__: called CC=1 SCAR=0.0
8 68 ▶use Game::Merrills::Bot;
Subroutine __ANON__: called CC=1 SCAR=0.0
9 68 ▶use Game::Merrills::Notation;
Subroutine __ANON__: called CC=1 SCAR=0.0
10 68 ▶use Game::Merrills::Points;
Subroutine __ANON__: called CC=1 SCAR=0.0
11  
12 68 our $VERSION = '0.01';
13  
14 68 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
15 68 PITCH => 4,
16 WIDTH => 27,
17 ROWS => 13,
18 RECENT => 2,
19 68 };
20  
21 68 our (%COMMAND, %GLYPH, %INK, %GROUND, %BRACKET, %SEQUENCE, %CONTROL, %KEY);
22  
23 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
24 68 %COMMAND = (
25 help => 'this list',
26 '?' => 'this list',
27 moves => 'the legal moves, numbered: play one by its number',
28 pick => 'choose a move with the arrow keys instead of typing it',
29 type => 'go back to typing moves out',
30 hint => 'what the bot would play here',
31 board => 'draw the board again',
32 position => 'the position as one line of text',
33 undo => 'take back your last move, and the reply to it',
34 'save FILE' => 'write the game out',
35 'load FILE' => 'read a game back in',
36 'level N' => 'set the strength of the bot, 1 to 5',
37 ascii => 'letters and dashes instead of drawn men and lines',
38 colour => 'turn the colours on or off',
39 draw => 'offer a draw',
40 accept => 'accept a draw that was offered',
41 decline => 'turn a draw down',
42 resign => 'give the game up',
43 quit => 'stop playing',
44 );
45  
46 68 %GLYPH = (
47 ascii => {
48 across => '-', down => '|', empty => '.', taken => 'x',
49 white => 'W', black => 'B',
50 },
51 wide => {
52 across => "\x{2500}", down => "\x{2502}", empty => "\x{00B7}", taken => "\x{00D7}",
53 white => "\x{25CB}", black => "\x{25CF}",
54 },
55 painted => {
56 across => "\x{2500}", down => "\x{2502}", empty => "\x{00B7}", taken => "\x{00D7}",
57 white => "\x{25CF}", black => "\x{25CF}",
58 },
59 );
60  
61 68 %INK = (
62 line => '38;5;179',
63 empty => '1;38;5;222',
64 white => '1;38;5;231',
65 black => '1;38;5;16',
66 bracket => '1;38;5;230',
67 taken => '1;38;5;217',
68 label => '38;5;109',
69 title => '1;38;5;222',
70 you => '1;38;5;120',
71 them => '1;38;5;215',
72 said => '38;5;250',
73 turn => '1;38;5;231',
74 mill => '1;38;5;220',
75 warn => '1;38;5;209',
76 good => '1;38;5;120',
77 hint => '38;5;117',
78 dim => '38;5;244',
79 step => '1;38;5;159',
80 cursor => '1;38;5;16;48;5;220',
81 key => '1;38;5;222',
82 );
83  
84 68 %GROUND = (
85 board => '48;5;94',
86 mill => '48;5;130',
87 last => '48;5;25',
88 left => '48;5;24',
89 taken => '48;5;124',
90 candidate => '48;5;28',
91 takeable => '48;5;127',
92 option => '48;5;58',
93 chosen => '48;5;31',
94 );
95  
96 68 %BRACKET = (
97 last => [ '(', ')' ],
98 left => [ '(', ')' ],
99 taken => [ '(', ')' ],
100 candidate => [ '[', ']' ],
101 takeable => [ '{', '}' ],
102 chosen => [ '<', '>' ],
103 );
104  
105 68 %SEQUENCE = (
106 'A' => 'up',
107 'B' => 'down',
108 'C' => 'right',
109 'D' => 'left',
110 'H' => 'home',
111 'F' => 'end',
112 'Z' => 'back_tab',
113 '1~' => 'home',
114 '4~' => 'end',
115 '5~' => 'page_up',
116 '6~' => 'page_down',
117 '7~' => 'home',
118 '8~' => 'end',
119 );
120  
121 68 %CONTROL = (
122 "\r" => 'enter',
123 "\n" => 'enter',
124 "\t" => 'tab',
125 "\x7f" => 'backspace',
126 "\x08" => 'backspace',
127 "\x03" => 'interrupt',
128 "\x04" => 'eof',
129 );
130  
131 68 %KEY = (
132 u => 'undo',
133 t => 'type',
134 q => 'quit',
135 );
136 }
137  
138 68 my %OTHER = (white => 'black', black => 'white');
139  
140 has game => (
141 is => 'rw',
142 isa => Object
143 68 );
144  
145 has bot => (
146 is => 'rw'
147 68 );
148  
149 has human => (
150 is => 'rw',
151 isa => Str,
152 default => 'white'
153 68 );
154  
155 has [qw/in out/] => (
156 is => 'rw'
157 68 );
158  
159 has [qw/interactive colour/] => (
160 is => 'rw'
161 68 );
162  
163 has ascii => (
164 is => 'rw',
165 isa => Bool,
166 default => 0
167 68 );
168  
169 has redraw => (
170 is => 'rw',
171 isa => Bool,
172 default => 1
173 68 );
174  
175 has highlight => (
176 is => 'rw',
177 isa => HashRef,
178 1016 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
179 68 );
180  
181 has recent => (
182 is => 'rw',
183 isa => ArrayRef,
184 1016 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
185 68 );
186  
187 has picking => (
188 is => 'rw',
189 isa => Bool
190 68 );
191  
192 has raw => (
193 is => 'rw',
194 isa => Bool,
195 default => 0
196 68 );
197  
198 has keysource => (
199 is => 'rw',
200 isa => CodeRef
201 68 );
202  
203 has [qw/pending heard/] => (
204 is => 'rw',
205 isa => ArrayRef,
206 2032 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
207 68 );
208  
209 has preview => (
210 is => 'rw'
211 68 );
212  
213 has frames => (
214 is => 'rw',
215 isa => Int,
216 default => 0
217 68 );
218  
219 1016 ▶sub BUILD {
Subroutine BUILD: called CC=13 SCAR=25.9
Pod undocumented
220 1016 my ($self) = @_;
221 1016 ▶ $self->game(Game::Merrills->new) unless $self->game;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->game 64 952 1016
222 1016 ▶ die "human must be white, black, both or none, got '" . $self->human . "'"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->human =~ /^(?:white|black|both|none)$/ 1 1015 1016
223 unless $self->human =~ m/^(?:white|black|both|none)$/;
224 1015 ▶ $self->in(\*STDIN) unless $self->in;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in 43 972 1015
225 1015 ▶ $self->out(\*STDOUT) unless $self->out;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out 43 972 1015
226 1015 ▶ $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->interactive 45 970 1015
-t $self->in ? : 0 45 45
227 1015 ▶ $self->colour($self->interactive && !$ENV{NO_COLOR} ? 1 : 0)
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->colour 3 1012 1015
$self->interactive && !$ENV{'NO_COLOR'} ? : 0 3 3
Condition33%1/3
$self->interactive and not $ENV{"NO_COLOR"}
!ll&&!rl&&r
300
MC/DC0%0/2
$self->interactive and not $ENV{"NO_COLOR"}
$self->interactive not $ENV{"NO_COLOR"}
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not $ENV{"NO_COLOR"}
ABresult
0X0
100
111
228 unless defined $self->colour;
229 1015 ▶ $self->picking($self->interactive ? 1 : 0) unless defined $self->picking;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->picking 123 892 1015
$self->interactive ? : 0 123 123
230 1015 ▶ $self->picking(0) unless $self->keys_available;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keys_available 126 889 1015
231 1015 $self->layer;
232  
233 1015 my $previous = select $self->out;
234 1015 $| = 1;
235 1015 select $previous;
236 1015 return $self;
237 }
238  
239 1019 ▶sub layer {
Subroutine layer: called CC=2 SCAR=6.9
Pod documented
240 1019 my ($self) = @_;
241 1019 binmode $self->out, ':raw';
242 1019 ▶ binmode $self->out, ':encoding(UTF-8)' unless $self->ascii;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->ascii 8 1011 1019
243 1019 return $self;
244 }
245  
246 77 ▶sub start {
Subroutine start: called CC=4 SCAR=15.2
Pod documented
247 77 my ($self) = @_;
248 77 $self->say($self->paint("Nine Men's Morris.", 'title')
249 . $self->paint(' Type help for the commands.', 'dim'));
250 77 ▶ $self->picking(0) if $self->picking && !$self->enter_raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->picking and not $self->enter_raw 0 77 77
Condition66%2/3
$self->picking and not $self->enter_raw
!ll&&!rl&&r
7250
MC/DC0%0/2
$self->picking and not $self->enter_raw
$self->picking not $self->enter_raw
Truth table66%2/3
A and not(B)
A= $self->pickingB= not $self->enter_raw
ABresult
0X0
100
111
251  
252 77 my $interrupt = $SIG{INT};
253 0 ▶ local $SIG{INT} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
254 0 $self->leave_raw;
255 0 ▶ $SIG{INT} = defined $interrupt ? $interrupt : 'DEFAULT';
Branch: 1 branch
BranchTrueFalseTotal
defined $interrupt ? : 0 0 0
256 0 kill 'INT', $$;
257 77 };
258  
259 77 my $played = eval { $self->turns; 1 };
260 77 my $error = $@;
261 77 $self->leave_raw;
262 77 ▶ die $error unless $played;
Branch: 1 branch
BranchTrueFalseTotal
unless $played 0 77 77
263 77 return $self->game->result;
264 }
265  
266 77 ▶sub turns {
Subroutine turns: called CC=13 SCAR=25.7
Pod documented
267 77 my ($self) = @_;
268 77 while (1) {
269 555 ▶ my $picking = $self->picking && $self->raw && $self->human ne 'none';
Condition83%5/6
$self->picking && $self->raw && $self->human ne 'none'
!ll&&!rl&&r
4833537
$self->picking and $self->raw
!ll&&!rl&&r
483072
MC/DC66%2/3
$self->picking && $self->raw && $self->human ne 'none'
$self->picking $self->raw $self->human ne 'none'
Truth table75%3/4
A and B && C
A= $self->pickingB= $self->rawC= $self->human ne 'none'
ABCresult
0XX0
10X0
1100
1111
270 555 ▶ $self->render if $self->redraw && !$picking;
Branch: 1 branch
BranchTrueFalseTotal
if $self->redraw and not $picking 474 81 555
Condition100%3/3
$self->redraw and not $picking
!ll&&!rl&&r
4536474
MC/DC100%2/2
$self->redraw and not $picking
$self->redraw not $picking
Truth table100%3/3
A and not(B)
A= $self->redrawB= not $picking
ABresult
0X0
100
111
271 555 ▶ if (my $result = $self->game->result) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $self->game->result) 18 537 555
272 18 ▶ $self->render if $picking;
Branch: 1 branch
BranchTrueFalseTotal
if $picking 0 18 18
273 18 last;
274 }
275 537 ▶ if ($self->bot_plays($self->game->turn)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->bot_plays($self->game->turn)) 354 183 537
276 354 $self->bot_move;
277 354 next;
278 }
279 183 ▶ my $line = $picking ? $self->pick : $self->read_line;
Branch: 1 branch
BranchTrueFalseTotal
$picking ? : 35 148 183
280 183 ▶ unless (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 57 126 183
281 57 $self->say('Bye.');
282 57 last;
283 }
284 126 $self->heard([]);
285 126 my $stop = $self->command($line);
286 126 ▶ $self->heard([]) unless $self->picking && $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->picking and $self->raw 95 31 126
Condition66%2/3
$self->picking and $self->raw
!ll&&!rl&&r
95031
MC/DC50%1/2
$self->picking and $self->raw
$self->picking $self->raw
Truth table66%2/3
A and B
A= $self->pickingB= $self->raw
ABresult
0X0
100
111
287 126 ▶ last if $stop;
Branch: 1 branch
BranchTrueFalseTotal
if $stop 2 124 126
288 }
289 77 return $self;
290 }
291  
292 1017 ▶sub keys_available {
Subroutine keys_available: called CC=5 SCAR=21.7
Pod documented
293 1017 my ($self) = @_;
294 1017 ▶ return 1 if $self->keysource;
Branch: 1 branch
BranchTrueFalseTotal
if $self->keysource 889 128 1017
295 128 ▶ return 0 unless defined $self->in && -t $self->in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->in and -t $self->in 128 0 128
Condition33%1/3
defined $self->in and -t $self->in
!ll&&!rl&&r
01280
MC/DC0%0/2
defined $self->in and -t $self->in
defined $self->in -t $self->in
Truth table33%1/3
A and B
A= defined $self->inB= -t $self->in
ABresult
0X0
100
111
296 0 ▶ return eval { require Term::ReadKey; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Term::ReadKey; 1 } } ? : 0 0 0
297 }
298  
299 36 ▶sub enter_raw {
Subroutine enter_raw: called CC=5 SCAR=20.4
Pod documented
300 36 my ($self) = @_;
301 36 ▶ return $self if $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->raw 0 36 36
302 36 ▶ if ($self->keysource) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->keysource) 35 1 36
303 35 $self->raw(1);
304 35 return $self;
305 }
306 1 ▶ return undef unless $self->keys_available;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keys_available 1 0 1
307 0 ▶ return undef unless eval { Term::ReadKey::ReadMode(3, $self->in); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { Term::ReadKey::ReadMode(3, $self->in); 1 } } 0 0 0
308 0 $self->raw(1);
309 0 return $self;
310 }
311  
312 121 ▶sub leave_raw {
Subroutine leave_raw: called CC=3 SCAR=11.2
Pod documented
313 121 my ($self) = @_;
314 121 ▶ return $self unless $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->raw 115 6 121
315 6 ▶ eval { Term::ReadKey::ReadMode(0, $self->in) } unless $self->keysource;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keysource 0 6 6
316 6 $self->raw(0);
317 6 return $self;
318 }
319  
320 266 ▶sub read_char {
Subroutine read_char: called CC=6 SCAR=25.4
Pod documented
321 266 my ($self, $wait) = @_;
322 266 my $pending = $self->pending;
323 266 ▶ return shift @{$pending} if @{$pending};
Branch: 1 branch
BranchTrueFalseTotal
if @{$pending;} 4 262 266
324 262 ▶ return $self->keysource->($wait) if $self->keysource;
Branch: 1 branch
BranchTrueFalseTotal
if $self->keysource 262 0 262
325 0 ▶ my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->in);
Branch: 1 branch
BranchTrueFalseTotal
$wait ? : 0 0 0
326 0 ▶ return $char if defined $char || $wait;
Branch: 1 branch
BranchTrueFalseTotal
if defined $char or $wait 0 0 0
Condition0%0/3
defined $char or $wait
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $char or $wait
defined $char $wait
Truth table0%0/3
A or B
A= defined $charB= $wait
ABresult
1X1
011
000
327 0 select undef, undef, undef, 0.05;
328 0 return Term::ReadKey::ReadKey(-1, $self->in);
329 }
330  
331 229 ▶sub read_key {
Subroutine read_key: called CC=4 SCAR=13.9
Pod documented
332 229 my ($self) = @_;
333 229 my $char = $self->read_char(1);
334 229 ▶ return undef unless defined $char;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $char 15 214 229
335 214 ▶ return $CONTROL{$char} if $CONTROL{$char};
Branch: 1 branch
BranchTrueFalseTotal
if $Game::Merrills::Terminal::CONTROL{$char} 110 104 214
336 104 ▶ return $self->read_sequence if $char eq "\e";
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "\e" 19 85 104
337 85 return $char;
338 }
339  
340 19 ▶sub read_sequence {
Subroutine read_sequence: called CC=8 SCAR=21.0
Pod documented
341 19 my ($self) = @_;
342 19 my $opener = $self->read_char(0);
343 19 ▶ return 'escape' unless defined $opener;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opener 0 19 19
344 19 ▶ unless ($opener eq '[' || $opener eq 'O') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opener eq "[" or $opener eq "O") 4 15 19
Condition100%3/3
$opener eq "[" or $opener eq "O"
l!l&&r!l&&!r
1414
MC/DC100%2/2
$opener eq "[" or $opener eq "O"
$opener eq "[" $opener eq "O"
Truth table100%3/3
A or B
A= $opener eq "["B= $opener eq "O"
ABresult
1X1
011
000
345 4 unshift @{ $self->pending }, $opener;
346 4 return 'escape';
347 }
348 15 my $tail = '';
349 15 ▶ while (length $tail < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tail < 8) 18 0 18
350 18 my $char = $self->read_char(0);
351 18 ▶ last unless defined $char;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $char 0 18 18
352 18 $tail .= $char;
353 18 ▶ last if $char =~ m/[A-Za-z~]/;
Branch: 1 branch
BranchTrueFalseTotal
if $char =~ /[A-Za-z~]/ 15 3 18
354 }
355 15 ▶ return $SEQUENCE{$tail} || 'escape';
Condition50%1/2
$Game::Merrills::Terminal::SEQUENCE{$tail} || 'escape'
l!l
150
MC/DC0%0/1
$Game::Merrills::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Merrills::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Merrills::Terminal::SEQUENCE{$tail}
Aresult
11
00
356 }
357  
358 94123 ▶sub components {
Subroutine components: called CC=1 SCAR=0.0
Pod documented
359 94123 my ($self, $move) = @_;
360 94123 return [ grep { defined } $move->from, $move->to, $move->remove ];
361 }
362  
363 4387 ▶sub matching {
Subroutine matching: called CC=5 SCAR=16.1
Pod documented
364 4387 my ($self, $prefix) = @_;
365 4387 my @match;
366 4387 MOVE: for my $move (@{ $self->game->legal_moves }) {
367 71622 my $parts = $self->components($move);
368 71622 ▶ next if @{$parts} < @{$prefix};
Branch: 1 branch
BranchTrueFalseTotal
if @{$parts;} < @{$prefix;} 1667 69955 71622
369 69955 for my $i (0 .. $#{$prefix}) {
370 61853 ▶ next MOVE unless $parts->[$i] == $prefix->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $parts->[$i] == $prefix->[$i] 47316 14537 61853
371 }
372 22639 push @match, $move;
373 }
374 4387 return \@match;
375 }
376  
377 1791 ▶sub options_for {
Subroutine options_for: called CC=3 SCAR=11.0
Pod documented
378 1791 my ($self, $prefix) = @_;
379 1791 my %next;
380 1791 for my $move (@{ $self->matching($prefix) }) {
381 17519 my $parts = $self->components($move);
382 17519 ▶ $next{ $parts->[ scalar @{$prefix} ] } = 1 if @{$parts} > @{$prefix};
Branch: 1 branch
BranchTrueFalseTotal
if @{$parts;} > @{$prefix;} 17519 0 17519
383 }
384 1791 return [ sort { $a <=> $b } keys %next ];
385 }
386  
387 2478 ▶sub complete {
Subroutine complete: called CC=3 SCAR=11.0
Pod documented
388 2478 my ($self, $prefix) = @_;
389 2478 for my $move (@{ $self->matching($prefix) }) {
390 4978 ▶ return $move if @{ $self->components($move) } == @{$prefix};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->components($move);} == @{$prefix;} 1624 3354 4978
391 }
392 854 return undef;
393 }
394  
395 8316 ▶sub nearest {
Subroutine nearest: called CC=12 SCAR=24.8
Pod documented
396 8316 my ($self, $from, $direction, $candidates) = @_;
397 8316 my ($row, $col) = (Game::Merrills::Points::row_of($from), Game::Merrills::Points::col_of($from));
398 8316 my ($best, $best_cost, $best_off);
399 8316 for my $point (@{$candidates}) {
400 92991 ▶ next if $point == $from;
Branch: 1 branch
BranchTrueFalseTotal
if $point == $from 8315 84676 92991
401 84676 my $down = Game::Merrills::Points::row_of($point) - $row;
402 84676 my $right = Game::Merrills::Points::col_of($point) - $col;
403 84676 ▶ my ($along, $off) = $direction eq 'up' ? (-$down, abs $right)
Branch: 3 branches
BranchTrueFalseTotal
$direction eq 'up' ? : 21134 63542 84676
$direction eq 'down' ? : 21203 42339 63542
$direction eq 'left' ? : 21134 21205 42339
404 : $direction eq 'down' ? ($down, abs $right)
405 : $direction eq 'left' ? (-$right, abs $down)
406 : ($right, abs $down);
407 84676 ▶ next unless $along > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $along > 0 47398 37278 84676
408 37278 my $cost = $along + 2 * $off;
409 37278 ▶ next if defined $best && ($cost > $best_cost || ($cost == $best_cost && $off >= $best_off));
Branch: 1 branch
BranchTrueFalseTotal
if defined $best and $cost > $best_cost || $cost == $best_cost && $off >= $best_off 21265 16013 37278
Condition100%9/9
defined $best and $cost > $best_cost || $cost == $best_cost && $off >= $best_off
!ll&&!rl&&r
6365964821265
$cost > $best_cost or $cost == $best_cost and $off >= $best_off
l!l&&r!l&&!r
202969699648
$cost == $best_cost and $off >= $best_off
!ll&&!rl&&r
8716932969
MC/DC100%4/4
defined $best and $cost > $best_cost || $cost == $best_cost && $off >= $best_off
defined $best $cost > $best_cost $cost == $best_cost $off >= $best_off
Truth table100%5/5
A and B or C and D
A= defined $bestB= $cost > $best_costC= $cost == $best_costD= $off >= $best_off
ABCDresult
0XXX0
100X0
10100
11XX1
10111
410 16013 ($best, $best_cost, $best_off) = ($point, $cost, $off);
411 }
412 8316 ▶ return defined $best ? $best : $from;
Branch: 1 branch
BranchTrueFalseTotal
defined $best ? : 6365 1951 8316
413 }
414  
415 164 ▶sub step_of {
Subroutine step_of: called CC=2 SCAR=6.9
Pod documented
416 164 my ($self, $prefix) = @_;
417 164 my $placing = $self->game->phase eq 'placing';
418 164 ▶ my @steps = $placing ? qw/to remove/ : qw/from to remove/;
Branch: 1 branch
BranchTrueFalseTotal
$placing ? : 84 80 164
419 164 return $steps[ scalar @{$prefix} ];
420 }
421  
422 65 ▶sub pick {
Subroutine pick: called CC=39 SCAR=36.9
Pod documented
423 65 my ($self) = @_;
424 65 ▶ return undef unless $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->raw 1 64 65
425 64 ▶ return undef unless @{ $self->game->legal_moves };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->game->legal_moves;} 0 64 64
426  
427 64 my (@prefix, $at, $hinted);
428 64 my $notice = [ @{ $self->heard } ];
429 64 $self->heard([]);
430 64 while (1) {
431 164 my $options = $self->options_for(\@prefix);
432 164 ▶ if ($hinted && !(defined $at && grep { $_ == $at } @{$options})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hinted and not defined $at && grep({$_ == $at;} @{$options;})) 4 160 164
Condition50%3/6
$hinted and not defined $at && grep({$_ == $at;} @{$options;})
!ll&&!rl&&r
16004
defined $at && grep({$_ == $at;} @{$options;})
!ll&&!rl&&r
400
MC/DC33%1/3
$hinted and not defined $at && grep({$_ == $at;} @{$options;})
$hinted defined $at grep({$_ == $at;} @{$options;})
Truth table50%2/4
A and not(B && C)
A= $hintedB= defined $atC= grep({$_ == $at;} @{$options;})
ABCresult
0XX0
1110
10X1
1101
433 4 my $parts = $self->components($hinted);
434 4 my $follows = !grep { $parts->[$_] != $prefix[$_] } 0 .. $#prefix;
435 4 ▶ $at = $parts->[ scalar @prefix ] if $follows && @{$parts} > @prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $follows and @{$parts;} > @prefix 4 0 4
Condition33%1/3
$follows and @{$parts;} > @prefix
!ll&&!rl&&r
004
MC/DC0%0/2
$follows and @{$parts;} > @prefix
$follows @{$parts;} > @prefix
Truth table33%1/3
A and B
A= $followsB= @{$parts;} > @prefix
ABresult
0X0
100
111
436 }
437 164 ▶ $at = $options->[0] unless defined $at && grep { $_ == $at } @{$options};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $at and grep {$_ == $at;} @{$options;} 89 75 164
Condition66%2/3
defined $at and grep {$_ == $at;} @{$options;}
!ll&&!rl&&r
89075
MC/DC50%1/2
defined $at and grep {$_ == $at;} @{$options;}
defined $at grep {$_ == $at;} @{$options;}
Truth table66%2/3
A and B
A= defined $atB= grep {$_ == $at;} @{$options;}
ABresult
0X0
100
111
438  
439 164 $self->show_choice(\@prefix, $options, $at, $notice);
440 164 $notice = [];
441 164 my $key = $self->read_key;
442 164 ▶ if (!defined $key || $key eq 'eof' || $key eq 'interrupt') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $key or $key eq "eof" or $key eq "interrupt") 16 148 164
Condition100%6/6
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
151148
not defined $key or $key eq "eof"
l!l&&r!l&&!r
141149
MC/DC100%3/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key $key eq "eof" $key eq "interrupt"
Truth table100%4/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
ABCresult
1XX1
01X1
0011
0000
443 16 $self->done_picking;
444 16 return undef;
445 }
446  
447 148 ▶ if ($key =~ m/^(?:up|down|left|right)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^(?:up|down|left|right)$/) 2 146 148
448 2 $at = $self->nearest($at, $key, $options);
449 2 next;
450 }
451 146 ▶ if ($key eq 'tab' || $key eq 'j' || $key eq 'back_tab' || $key eq 'k') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "tab" or $key eq "j" or $key eq "back_tab" or $key eq "k") 29 117 146
Condition88%8/9
$key eq "tab" or $key eq "j" or $key eq "back_tab" or $key eq "k"
l!l&&r!l&&!r
281117
$key eq "tab" or $key eq "j" or $key eq "back_tab"
l!l&&r!l&&!r
271118
$key eq "tab" or $key eq "j"
l!l&&r!l&&!r
270119
MC/DC75%3/4
$key eq "tab" or $key eq "j" or $key eq "back_tab" or $key eq "k"
$key eq "tab" $key eq "j" $key eq "back_tab" $key eq "k"
Truth table80%4/5
A or B or C or D
A= $key eq "tab"B= $key eq "j"C= $key eq "back_tab"D= $key eq "k"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
452 29 my ($index) = grep { $options->[$_] == $at } 0 .. $#{$options};
453 29 ▶ $index += $key eq 'tab' || $key eq 'j' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$key eq 'tab' || $key eq 'j' ? : 27 2 29
Condition66%2/3
$key eq "tab" or $key eq "j"
l!l&&r!l&&!r
2702
MC/DC50%1/2
$key eq "tab" or $key eq "j"
$key eq "tab" $key eq "j"
Truth table66%2/3
A or B
A= $key eq "tab"B= $key eq "j"
ABresult
1X1
011
000
454 29 $at = $options->[ $index % @{$options} ];
455 29 next;
456 }
457 117 ▶ if ($key eq 'home' || $key eq 'page_up') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "home" or $key eq "page_up") 1 116 117
Condition66%2/3
$key eq "home" or $key eq "page_up"
l!l&&r!l&&!r
10116
MC/DC50%1/2
$key eq "home" or $key eq "page_up"
$key eq "home" $key eq "page_up"
Truth table66%2/3
A or B
A= $key eq "home"B= $key eq "page_up"
ABresult
1X1
011
000
458 1 $at = $options->[0];
459 1 next;
460 }
461 116 ▶ if ($key eq 'end' || $key eq 'page_down') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "end" or $key eq "page_down") 2 114 116
Condition100%3/3
$key eq "end" or $key eq "page_down"
l!l&&r!l&&!r
11114
MC/DC100%2/2
$key eq "end" or $key eq "page_down"
$key eq "end" $key eq "page_down"
Truth table100%3/3
A or B
A= $key eq "end"B= $key eq "page_down"
ABresult
1X1
011
000
462 2 $at = $options->[-1];
463 2 next;
464 }
465 114 ▶ if ($key =~ m/^[a-gA-G]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^[a-gA-G]$/) 28 86 114
466 28 my $rank = $self->read_key;
467 28 ▶ my $point = defined $rank ? Game::Merrills::Points::point($key . $rank) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $rank ? : 28 0 28
468 28 ▶ if (defined $point && grep { $_ == $point } @{$options}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $point and grep {$_ == $point;} @{$options;}) { } 26 2 28
Condition100%3/3
defined $point and grep {$_ == $point;} @{$options;}
!ll&&!rl&&r
1126
MC/DC100%2/2
defined $point and grep {$_ == $point;} @{$options;}
defined $point grep {$_ == $point;} @{$options;}
Truth table100%3/3
A and B
A= defined $pointB= grep {$_ == $point;} @{$options;}
ABresult
0X0
100
111
469 26 $at = $point;
470 }
471 else {
472 2 ▶ $notice = [ $self->paint(
Branch: 1 branch
BranchTrueFalseTotal
defined $point ? : 1 1 2
473 defined $point ? ucfirst(Game::Merrills::Points::name($point)) . ' cannot be chosen here.'
474 : 'A point is a letter and a number, like d2.', 'warn') ];
475 }
476 28 next;
477 }
478 86 ▶ if ($key eq 'enter' || $key eq ' ') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "enter" or $key eq " ") 68 18 86
Condition66%2/3
$key eq "enter" or $key eq " "
l!l&&r!l&&!r
68018
MC/DC50%1/2
$key eq "enter" or $key eq " "
$key eq "enter" $key eq " "
Truth table66%2/3
A or B
A= $key eq "enter"B= $key eq " "
ABresult
1X1
011
000
479 68 push @prefix, $at;
480 68 undef $at;
481 68 ▶ my $move = $self->complete(\@prefix) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $move = $self->complete(\@prefix) or next 41 27 68
482 41 $self->done_picking;
483 41 $self->played($self->game->move($move));
484 41 return '';
485 }
486 18 ▶ if ($key eq 'backspace' || $key eq 'escape') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "backspace" or $key eq "escape") 7 11 18
Condition100%3/3
$key eq "backspace" or $key eq "escape"
l!l&&r!l&&!r
5211
MC/DC100%2/2
$key eq "backspace" or $key eq "escape"
$key eq "backspace" $key eq "escape"
Truth table100%3/3
A or B
A= $key eq "backspace"B= $key eq "escape"
ABresult
1X1
011
000
487 7 ▶ if (@prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if (@prefix) { } 5 2 7
488 5 $at = pop @prefix;
489 }
490 else {
491 2 $notice = [ $self->paint('There is nothing to go back over.', 'warn') ];
492 }
493 7 next;
494 }
495 11 ▶ if ($key eq 'h') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "h") 2 9 11
496 2 my $hint = $self->hint;
497 2 $notice = [ $self->paint($hint->{line}, 'hint') ];
498 2 $hinted = $hint->{move};
499 2 @prefix = ();
500 2 undef $at;
501 2 next;
502 }
503 9 ▶ if ($key eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "?") 1 8 9
504 1 $notice = $self->key_lines;
505 1 next;
506 }
507 8 ▶ if ($key eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq ":") 2 6 8
508 2 $self->done_picking;
509 2 return $self->read_line(': ');
510 }
511 6 ▶ if ($KEY{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Game::Merrills::Terminal::KEY{$key}) 5 1 6
512 5 $self->done_picking;
513 5 return $KEY{$key};
514 }
515 1 $notice = [ $self->paint('That key does nothing here. Press ? for the ones that do.', 'warn') ];
516 }
517 }
518  
519 64 ▶sub done_picking {
Subroutine done_picking: called CC=1 SCAR=0.0
Pod documented
520 64 my ($self) = @_;
521 64 $self->highlight({});
522 64 $self->preview(undef);
523 64 return $self;
524 }
525  
526 164 ▶sub show_choice {
Subroutine show_choice: called CC=27 SCAR=33.0
Pod documented
527 164 my ($self, $prefix, $options, $at, $notice) = @_;
528 164 my $game = $self->game;
529 164 my $step = $self->step_of($prefix);
530 164 my $side = $game->turn;
531 164 my %mark = map { $_ => 'option' } @{$options};
532 164 my @said;
533  
534 164 my $board = $game->board;
535 my ($from, $to) = $step eq 'from' ? ($at, undef)
536 : $step eq 'to' ? ($game->phase eq 'placing' ? undef : $prefix->[0], $at)
537 164 ▶ : ($game->phase eq 'placing' ? (undef, $prefix->[0]) : @{$prefix}[ 0, 1 ]);
Branch: 4 branches
BranchTrueFalseTotal
$step eq 'from' ? : 40 124 164
$step eq 'to' ? : 118 6 124
$game->phase eq 'placing' ? : 84 34 118
$game->phase eq 'placing' ? : 0 6 6
538  
539 164 ▶ if (defined $to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to) 124 40 164
540 124 ▶ $board->set($from, undef) if defined $from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from 40 84 124
541 124 $board->set($to, $side);
542 124 ▶ $mark{$from} = 'left' if defined $from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from 40 84 124
543 124 $mark{$to} = 'chosen';
544 }
545 164 ▶ if ($step eq 'to') {
Branch: 2 branches
BranchTrueFalseTotal
if ($step eq 'to') { } 118 46 164
elsif ($step eq 'remove') { } 6 40 46
546 118 my @takes = grep { defined $_->remove } @{ $self->matching([ @{$prefix}, $at ]) };
547 118 $mark{ $_->remove } = 'takeable' for @takes;
548 118 $mark{$at} = 'candidate';
549 118 ▶ push @said, $takes[0]->closes > 1 ? 'closes two mills' : 'closes a mill' if @takes;
Branch: 2 branches
BranchTrueFalseTotal
if @takes 17 101 118
$takes[0]->closes > 1 ? : 0 17 17
550 118 ▶ push @said, 'a flight'
Branch: 1 branch
BranchTrueFalseTotal
if defined $from and not Game::Merrills::Points::is_adjacent($from, $at) 1 117 118
Condition100%3/3
defined $from and not Game::Merrills::Points::is_adjacent($from, $at)
!ll&&!rl&&r
84331
MC/DC100%2/2
defined $from and not Game::Merrills::Points::is_adjacent($from, $at)
defined $from not Game::Merrills::Points::is_adjacent($from, $at)
Truth table100%3/3
A and not(B)
A= defined $fromB= not Game::Merrills::Points::is_adjacent($from, $at)
ABresult
0X0
100
111
551 if defined $from && !Game::Merrills::Points::is_adjacent($from, $at);
552 }
553 elsif ($step eq 'remove') {
554 6 $mark{$_} = 'takeable' for @{$options};
555 6 $mark{$at} = 'candidate';
556 6 push @said, 'takes this man';
557 }
558 else {
559 40 $mark{$at} = 'candidate';
560 }
561  
562 164 $self->preview($board);
563 164 $self->highlight(\%mark);
564 164 $self->frames($self->frames + 1);
565  
566 164 my $name = Game::Merrills::Points::name($at);
567 164 my ($index) = grep { $options->[$_] == $at } 0 .. $#{$options};
568 164 ▶ my $ask = $step eq 'from' ? 'Choose a man to move.'
Branch: 4 branches
BranchTrueFalseTotal
$step eq 'from' ? : 40 124 164
$step eq 'to' && !defined($from) ? : 84 40 124
$step eq 'to' ? : 34 6 40
defined $from ? : 6 0 6
Condition100%3/3
$step eq "to" and not defined $from
!ll&&!rl&&r
63484
MC/DC100%2/2
$step eq "to" and not defined $from
$step eq "to" not defined $from
Truth table100%3/3
A and not(B)
A= $step eq "to"B= not defined $from
ABresult
0X0
100
111
569 : $step eq 'to' && !defined $from ? 'Choose a point to place a man on.'
570 : $step eq 'to' ? sprintf('Move %s to where?', Game::Merrills::Points::name($from))
571 : defined $from ? sprintf('Move %s to %s and take which man?',
572 Game::Merrills::Points::name($from), Game::Merrills::Points::name($to))
573 : sprintf('Place on %s and take which man?', Game::Merrills::Points::name($to));
574 164 ▶ my $cursor = sprintf '> %s%s', $name, @said ? ', ' . join(', ', @said) : '';
Branch: 1 branch
BranchTrueFalseTotal
@said ? : 24 140 164
575  
576 164 $self->clear;
577 164 $self->say($_) for @{ $self->board_lines }, '', @{ $self->status_lines }, '',
578 $self->paint($ask, 'step'),
579 ' ' . $self->paint($cursor, 'cursor')
580 164 . $self->paint(sprintf(' %d of %d', $index + 1, scalar @{$options}), 'dim');
581 164 ▶ $self->say('') if $notice && @{$notice};
Branch: 1 branch
BranchTrueFalseTotal
if $notice and @{$notice;} 13 151 164
Condition66%2/3
$notice and @{$notice;}
!ll&&!rl&&r
015113
MC/DC50%1/2
$notice and @{$notice;}
$notice @{$notice;}
Truth table66%2/3
A and B
A= $noticeB= @{$notice;}
ABresult
0X0
100
111
582 164 ▶ $self->say($_) for @{ $notice || [] };
Condition50%1/2
$notice || []
l!l
1640
MC/DC0%0/1
$notice || []
$notice
Truth table50%1/2
A
A= $notice
Aresult
11
00
583 164 $self->say('');
584 164 $self->say($self->legend);
585 164 $self->redraw(0);
586 164 return $self;
587 }
588  
589 164 ▶sub legend {
Subroutine legend: called CC=1 SCAR=0.0
Pod documented
590 164 my ($self) = @_;
591 164 my @keys = (
592 [ 'arrows', 'move' ], [ 'tab', 'next' ], [ 'enter', 'choose' ],
593 [ 'backspace', 'back' ], [ 'h', 'hint' ], [ 'u', 'undo' ], [ 't', 'type' ],
594 [ 'q', 'quit' ], [ '?', 'help' ],
595 );
596 return join $self->paint(' | ', 'dim'),
597 164 map { $self->paint($_->[0], 'key') . ' ' . $self->paint($_->[1], 'dim') } @keys;
598 }
599  
600 1 ▶sub key_lines {
Subroutine key_lines: called CC=1 SCAR=0.0
Pod documented
601 1 my ($self) = @_;
602 return [
603 1 'The arrow keys move to the nearest point that can be chosen that way.',
604 'Tab and shift-tab, or j and k, go round every one of them in turn.',
605 'A letter and a number, like d2, jump straight to that point.',
606 'Enter or space chooses. A move is chosen a step at a time: the man,',
607 'where it goes, and the man it takes if it closes a mill.',
608 'Backspace or escape goes back a step. h shows what the bot would play.',
609 'u takes a move back, t goes back to typing, q quits, : types a command.',
610 ];
611 }
612  
613 2 ▶sub keyed_line {
Subroutine keyed_line: called CC=9 SCAR=23.0
Pod documented
614 2 my ($self) = @_;
615 2 my $out = $self->out;
616 2 my $line = '';
617 2 while (1) {
618 16 my $key = $self->read_key;
619 16 ▶ return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $key or $key eq "eof" or $key eq "interrupt" 0 16 16
Condition33%2/6
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
0016
not defined $key or $key eq "eof"
l!l&&r!l&&!r
0016
MC/DC0%0/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key $key eq "eof" $key eq "interrupt"
Truth table25%1/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
ABCresult
1XX1
01X1
0011
0000
620 16 ▶ last if $key eq 'enter';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "enter" 2 14 16
621 14 ▶ if ($key eq 'backspace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "backspace") 1 13 14
622 1 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 1 1
623 1 chop $line;
624 1 print {$out} "\b \b";
625 1 next;
626 }
627 13 ▶ next if length $key > 1 || $key lt ' ';
Branch: 1 branch
BranchTrueFalseTotal
if length $key > 1 or $key lt " " 0 13 13
Condition33%1/3
length $key > 1 or $key lt " "
l!l&&r!l&&!r
0013
MC/DC0%0/2
length $key > 1 or $key lt " "
length $key > 1 $key lt " "
Truth table33%1/3
A or B
A= length $key > 1B= $key lt " "
ABresult
1X1
011
000
628 13 $line .= $key;
629 13 print {$out} $key;
630 }
631 2 print {$out} "\n";
632 2 return $line;
633 }
634  
635 3 ▶sub set_picking {
Subroutine set_picking: called CC=4 SCAR=13.9
Pod documented
636 3 my ($self, $word) = @_;
637 3 ▶ if ($word eq 'type') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "type") 1 2 3
638 1 $self->leave_raw;
639 1 $self->picking(0);
640 1 $self->redraw(1);
641 1 $self->say('Type your moves. The command pick brings the keys back.');
642 1 return 0;
643 }
644 2 ▶ return $self->say('This terminal cannot be read a key at a time.') && 0
Branch: 1 branch
BranchTrueFalseTotal
unless $self->enter_raw 1 1 2
Condition50%1/2
$self->say('This terminal cannot be read a key at a time.') && 0
!ll
01
MC/DC0%0/1
$self->say('This terminal cannot be read a key at a time.') && 0
$self->say('This terminal cannot be read a key at a time.')
Truth table50%1/2
A
A= $self->say('This terminal cannot be read a key at a time.')
Aresult
00
11
645 unless $self->enter_raw;
646 1 $self->picking(1);
647 1 return 0;
648 }
649  
650 3 ▶sub replay {
Subroutine replay: called CC=7 SCAR=20.7
Pod documented
651 3 my ($self, $record) = @_;
652 3 my $moves = Game::Merrills::Notation::parse_record($record);
653 3 my $position = Game::Merrills::Notation::record_position($record);
654 3 ▶ my $game = Game::Merrills->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $position ? : 1 2 3
655 flying => $self->game->flying,
656 defined $position ? (position => $position) : ()
657 );
658 3 $self->game($game);
659 3 $self->recent([]);
660 3 $self->render;
661  
662 3 my $number = 0;
663 3 for my $move (@{$moves}) {
664 60 $number++;
665 60 ▶ if ($self->interactive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->interactive) 0 60 60
666 0 my $line = $self->read_line($self->paint('enter for the next move, q to stop: ', 'dim'));
667 0 ▶ last if !defined $line || $line =~ m/^\s*q/i;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $line or $line =~ /^\s*q/i 0 0 0
Condition0%0/3
not defined $line or $line =~ /^\s*q/i
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $line or $line =~ /^\s*q/i
not defined $line $line =~ /^\s*q/i
Truth table0%0/3
not(A) or B
A= not defined $lineB= $line =~ /^\s*q/i
ABresult
1X1
011
000
668 }
669 60 my $played = $game->move($move);
670 60 ▶ die "illegal record: move $number, '"
Branch: 1 branch
BranchTrueFalseTotal
if ref $played eq "Game::Merrills::Error" 1 59 60
671 . Game::Merrills::Notation::format_move($move) . "': " . $played->message . "\n"
672 if ref $played eq 'Game::Merrills::Error';
673 59 $self->played($played);
674 59 $self->render;
675 }
676 2 return $game->result;
677 }
678  
679 774 ▶sub bot_for {
Subroutine bot_for: called CC=2 SCAR=6.9
Pod documented
680 774 my ($self, $side) = @_;
681 774 my $bot = $self->bot;
682 774 ▶ return ref $bot eq 'HASH' ? $bot->{$side} : $bot;
Branch: 1 branch
BranchTrueFalseTotal
ref $bot eq 'HASH' ? : 672 102 774
683 }
684  
685 545 ▶sub bot_plays {
Subroutine bot_plays: called CC=5 SCAR=16.1
Pod documented
686 545 my ($self, $side) = @_;
687 545 ▶ return 0 if $self->human eq 'both' || !$self->bot_for($side);
Branch: 1 branch
BranchTrueFalseTotal
if $self->human eq "both" or not $self->bot_for($side) 140 405 545
Condition66%2/3
$self->human eq "both" or not $self->bot_for($side)
l!l&&r!l&&!r
1400405
MC/DC50%1/2
$self->human eq "both" or not $self->bot_for($side)
$self->human eq "both" not $self->bot_for($side)
Truth table66%2/3
A or not(B)
A= $self->human eq "both"B= not $self->bot_for($side)
ABresult
1X1
011
000
688 405 ▶ return 1 if $self->human eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $self->human eq "none" 336 69 405
689 69 ▶ return $side eq $self->human ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$side eq $self->human ? : 47 22 69
690 }
691  
692 354 ▶sub bot_move {
Subroutine bot_move: called CC=4 SCAR=14.8
Pod documented
693 354 my ($self) = @_;
694 354 my $side = $self->game->turn;
695 354 my $out = $self->out;
696 354 ▶ print {$out} $self->paint(ucfirst($side) . ' is thinking', 'dim') if $self->interactive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->interactive 0 354 354
697 354 my $move = $self->bot_for($side)->choose($self->game);
698 354 ▶ print {$out} "\r\e[K" if $self->interactive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->interactive 0 354 354
699 354 ▶ return undef unless $move;
Branch: 1 branch
BranchTrueFalseTotal
unless $move 0 354 354
700 354 $self->played($self->game->move($move));
701 354 return $move;
702 }
703  
704 496 ▶sub played {
Subroutine played: called CC=2 SCAR=6.9
Pod documented
705 496 my ($self, $move) = @_;
706 496 my $recent = $self->recent;
707 496 push @{$recent}, $self->narrate($move);
708 496 ▶ shift @{$recent} while @{$recent} > RECENT;
Branch: 1 branch
BranchTrueFalseTotal
@{$recent;} > 2 and do { shift @{$recent;} } 407 496 903
709 496 $self->redraw(1);
710 496 return $move;
711 }
712  
713 501 ▶sub name_of {
Subroutine name_of: called CC=2 SCAR=6.9
Pod documented
714 501 my ($self, $side) = @_;
715 501 ▶ return $side eq $self->human ? 'You' : ucfirst $side;
Branch: 1 branch
BranchTrueFalseTotal
$side eq $self->human ? : 16 485 501
716 }
717  
718 501 ▶sub narrate {
Subroutine narrate: called CC=6 SCAR=17.9
Pod documented
719 501 my ($self, $move) = @_;
720 501 my $who = $self->name_of($move->side);
721 501 my $to = Game::Merrills::Points::name($move->to);
722 501 ▶ my $text = $move->is_placement
Branch: 2 branches
BranchTrueFalseTotal
$move->is_placement ? : 221 280 501
$move->flew ? : 56 224 280
723 ? sprintf('%s placed a man on %s', $who, $to)
724 : sprintf('%s %s %s to %s', $who, $move->flew ? 'flew' : 'moved',
725 Game::Merrills::Points::name($move->from), $to);
726 501 ▶ if ($move->is_capture) {
Branch: 1 branch
BranchTrueFalseTotal
if ($move->is_capture) 60 441 501
727 60 my $victim = $OTHER{ $move->side };
728 60 ▶ $text .= sprintf ', closed %s and took %s man on %s',
Branch: 2 branches
BranchTrueFalseTotal
$move->closes > 1 ? : 1 59 60
$victim eq $self->human ? : 1 59 60
729 $move->closes > 1 ? 'two mills' : 'a mill',
730 $victim eq $self->human ? 'your' : "the $victim",
731 Game::Merrills::Points::name($move->remove);
732 }
733 501 return $text . '.';
734 }
735  
736 152 ▶sub read_line {
Subroutine read_line: called CC=6 SCAR=18.0
Pod documented
737 152 my ($self, $prompt) = @_;
738 152 my $out = $self->out;
739 152 ▶ print {$out} defined $prompt ? $prompt
Branch: 1 branch
BranchTrueFalseTotal
defined $prompt ? : 4 148 152
740 : $self->paint($self->game->turn . '>', $self->ink_of($self->game->turn)) . ' ';
741 152 ▶ return $self->keyed_line if $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->raw 2 150 152
742 150 my $line = readline $self->in;
743 150 ▶ unless (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 53 97 150
744 53 ▶ print {$out} "\n" unless $self->interactive;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->interactive 53 0 53
745 53 return undef;
746 }
747 97 chomp $line;
748 97 ▶ print {$out} "$line\n" unless $self->interactive;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->interactive 97 0 97
749 97 return $line;
750 }
751  
752 13689 ▶sub say {
Subroutine say: called CC=4 SCAR=14.0
Pod documented
753 13689 my ($self, $line) = @_;
754 13689 my $out = $self->out;
755 13689 ▶ print {$out} (defined $line ? $line : ''), "\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $line ? : 13689 0 13689
756 13689 ▶ push @{ $self->heard }, $line if defined $line && length $line;
Branch: 1 branch
BranchTrueFalseTotal
if defined $line and length $line 12638 1051 13689
Condition66%2/3
defined $line and length $line
!ll&&!rl&&r
0105112638
MC/DC50%1/2
defined $line and length $line
defined $line length $line
Truth table66%2/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
757 13689 return $self;
758 }
759  
760 710 ▶sub clear {
Subroutine clear: called CC=2 SCAR=10.9
Pod documented
761 710 my ($self) = @_;
762 710 ▶ return $self unless $self->interactive;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->interactive 710 0 710
763 0 my $out = $self->out;
764 0 print {$out} "\e[2J\e[H";
765 0 return $self;
766 }
767  
768 19419 ▶sub paint {
Subroutine paint: called CC=4 SCAR=14.0
Pod documented
769 19419 my ($self, $text, @keys) = @_;
770 19419 ▶ return $text unless $self->colour;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->colour 19086 333 19419
771 333 ▶ my @codes = grep { defined } map { $INK{$_} || $GROUND{$_} } @keys;
Condition66%2/3
$Game::Merrills::Terminal::INK{$_} || $Game::Merrills::Terminal::GROUND{$_}
l!l&&r!l&&!r
333240
MC/DC0%0/2
$Game::Merrills::Terminal::INK{$_} || $Game::Merrills::Terminal::GROUND{$_}
$Game::Merrills::Terminal::INK{$_} $Game::Merrills::Terminal::GROUND{$_}
Truth table66%2/3
A || B
A= $Game::Merrills::Terminal::INK{$_}B= $Game::Merrills::Terminal::GROUND{$_}
ABresult
1X1
011
000
772 333 ▶ return $text unless @codes;
Branch: 1 branch
BranchTrueFalseTotal
unless @codes 0 333 333
773 333 return "\e[" . join(';', @codes) . 'm' . $text . "\e[0m";
774 }
775  
776 2354 ▶sub ink_of {
Subroutine ink_of: called CC=4 SCAR=13.9
Pod documented
777 2354 my ($self, $side) = @_;
778 2354 ▶ return 'turn' if $self->human eq 'both' || $self->human eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $self->human eq "both" or $self->human eq "none" 2104 250 2354
Condition100%3/3
$self->human eq "both" or $self->human eq "none"
l!l&&r!l&&!r
10781026250
MC/DC100%2/2
$self->human eq "both" or $self->human eq "none"
$self->human eq "both" $self->human eq "none"
Truth table100%3/3
A or B
A= $self->human eq "both"B= $self->human eq "none"
ABresult
1X1
011
000
779 250 ▶ return $side eq $self->human ? 'you' : 'them';
Branch: 1 branch
BranchTrueFalseTotal
$side eq $self->human ? : 160 90 250
780 }
781  
782 546 ▶sub render {
Subroutine render: called CC=2 SCAR=6.9
Pod documented
783 546 my ($self) = @_;
784 546 $self->clear;
785 546 $self->say($_) for @{ $self->board_lines }, '', @{ $self->status_lines };
786 546 $self->redraw(0);
787 546 return $self;
788 }
789  
790 1500 ▶sub glyphs {
Subroutine glyphs: called CC=3 SCAR=11.0
Pod documented
791 1500 my ($self) = @_;
792 1500 ▶ return $GLYPH{ $self->ascii ? 'ascii' : $self->colour ? 'painted' : 'wide' };
Branch: 2 branches
BranchTrueFalseTotal
$self->ascii ? : 1478 22 1500
$self->colour ? : 14 8 22
793 }
794  
795 750 ▶sub marks {
Subroutine marks: called CC=5 SCAR=16.1
Pod documented
796 750 my ($self) = @_;
797 750 my %mark;
798 750 ▶ if (my $last = $self->game->history->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $last = $self->game->history->[-1]) 518 232 750
799 518 ▶ $mark{ $last->from } = 'left' if defined $last->from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last->from 283 235 518
800 518 ▶ $mark{ $last->remove } = 'taken' if defined $last->remove;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last->remove 64 454 518
801 518 $mark{ $last->to } = 'last';
802 }
803 750 my $extra = $self->highlight;
804 750 $mark{$_} = $extra->{$_} for keys %{$extra};
805 750 return \%mark;
806 }
807  
808 750 ▶sub canvas {
Subroutine canvas: called CC=19 SCAR=29.4
Pod documented
809 750 my ($self) = @_;
810 750 my @canvas = map { [ map { [ ' ', 'gap' ] } 1 .. WIDTH ] } 1 .. ROWS;
811 750 for my $mill (Game::Merrills::Points::mills()) {
812 12000 for my $step (0, 1) {
813 24000 my ($one, $two) = @{$mill}[ $step, $step + 1 ];
814 24000 my ($row, $col) = (2 * Game::Merrills::Points::row_of($one),
815 1 + PITCH * Game::Merrills::Points::col_of($one));
816 24000 my ($end_row, $end_col) = (2 * Game::Merrills::Points::row_of($two),
817 1 + PITCH * Game::Merrills::Points::col_of($two));
818 24000 ▶ if ($row == $end_row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row == $end_row) { } 12000 12000 24000
819 12000 $canvas[$row][$_] = [ 'across', 'line' ] for $col + 1 .. $end_col - 1;
820 }
821 else {
822 12000 $canvas[$_][$col] = [ 'down', 'line' ] for $row + 1 .. $end_row - 1;
823 }
824 }
825 }
826  
827 750 ▶ my $board = $self->preview || $self->game->board;
Condition66%2/3
$self->preview || $self->game->board
l!l&&r!l&&!r
1645860
MC/DC0%0/2
$self->preview || $self->game->board
$self->preview $self->game->board
Truth table66%2/3
A || B
A= $self->previewB= $self->game->board
ABresult
1X1
011
000
828 750 my $marks = $self->marks;
829 750 for my $point (Game::Merrills::Points::all_points()) {
830 18000 my ($row, $col) = (2 * Game::Merrills::Points::row_of($point),
831 1 + PITCH * Game::Merrills::Points::col_of($point));
832 18000 my $side = $board->side_at($point);
833 18000 my $mark = $marks->{$point};
834 18000 ▶ my $ground = $mark ? $mark : $side && $board->in_mill($point) ? 'mill' : undef;
Branch: 2 branches
BranchTrueFalseTotal
$mark ? : 3147 14853 18000
$side && $board->in_mill($point) ? : 792 14061 14853
Condition100%3/3
$side and $board->in_mill($point)
!ll&&!rl&&r
96514410792
MC/DC100%2/2
$side and $board->in_mill($point)
$side $board->in_mill($point)
Truth table100%3/3
A and B
A= $sideB= $board->in_mill($point)
ABresult
0X0
100
111
835 18000 ▶ $canvas[$row][$col] = [
Branch: 4 branches
BranchTrueFalseTotal
$side ? : 6092 11908 18000
$mark && $mark eq 'taken' ? : 64 11844 11908
$side ? : 6092 11908 18000
$mark && $mark eq 'taken' ? : 64 11844 11908
Condition100%6/6
$mark and $mark eq "taken"
!ll&&!rl&&r
9651219364
$mark and $mark eq "taken"
!ll&&!rl&&r
9651219364
MC/DC100%2/2
$mark and $mark eq "taken"
$mark $mark eq "taken"
MC/DC100%2/2
$mark and $mark eq "taken"
$mark $mark eq "taken"
Truth table100%3/3
A and B
A= $markB= $mark eq "taken"
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= $markB= $mark eq "taken"
ABresult
0X0
100
111
836 $side ? $side : $mark && $mark eq 'taken' ? 'taken' : 'empty',
837 $side ? $side : $mark && $mark eq 'taken' ? 'taken' : 'empty',
838 $ground,
839 ];
840 18000 ▶ next unless $mark && $BRACKET{$mark};
Branch: 1 branch
BranchTrueFalseTotal
unless $mark and $Game::Merrills::Terminal::BRACKET{$mark} 16848 1152 18000
Condition100%3/3
$mark and $Game::Merrills::Terminal::BRACKET{$mark}
!ll&&!rl&&r
1485319951152
MC/DC100%2/2
$mark and $Game::Merrills::Terminal::BRACKET{$mark}
$mark $Game::Merrills::Terminal::BRACKET{$mark}
Truth table100%3/3
A and B
A= $markB= $Game::Merrills::Terminal::BRACKET{$mark}
ABresult
0X0
100
111
841 1152 $canvas[$row][ $col - 1 ] = [ $BRACKET{$mark}[0], 'bracket', $mark ];
842 1152 $canvas[$row][ $col + 1 ] = [ $BRACKET{$mark}[1], 'bracket', $mark ];
843 }
844 750 return \@canvas;
845 }
846  
847 750 ▶sub board_lines {
Subroutine board_lines: called CC=13 SCAR=25.7
Pod documented
848 750 my ($self) = @_;
849 750 my $glyph = $self->glyphs;
850 750 my $canvas = $self->canvas;
851 750 my @aside = @{ $self->aside };
852 750 my @lines;
853 750 for my $row (0 .. ROWS - 1) {
854 9750 my $drawn = WIDTH;
855 9750 ▶ my $label = $row % 2 ? ' ' : 7 - ($row / 2);
Branch: 1 branch
BranchTrueFalseTotal
$row % 2 ? : 4500 5250 9750
856 9750 ▶ my $line = ($row % 2 ? ' ' : $self->paint($label, 'label')) . ' ';
Branch: 1 branch
BranchTrueFalseTotal
$row % 2 ? : 4500 5250 9750
857 9750 ▶ if ($self->colour) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->colour) { } 156 9594 9750
858 156 my $code = '';
859 156 for my $cell (@{ $canvas->[$row] }) {
860 4212 my ($what, $kind, $ground) = @{$cell};
861 4212 ▶ my $want = join ';', $INK{$kind} || $INK{line}, $GROUND{ $ground || 'board' };
Condition80%4/5
$Game::Merrills::Terminal::INK{$kind} || $Game::Merrills::Terminal::INK{'line'}
l!l&&r!l&&!r
193722750
$ground || 'board'
l!l
1194093
MC/DC0%0/2
$Game::Merrills::Terminal::INK{$kind} || $Game::Merrills::Terminal::INK{'line'}
$Game::Merrills::Terminal::INK{$kind} $Game::Merrills::Terminal::INK{'line'}
MC/DC100%1/1
$ground || 'board'
$ground
Truth table66%2/3
A || B
A= $Game::Merrills::Terminal::INK{$kind}B= $Game::Merrills::Terminal::INK{'line'}
ABresult
1X1
011
000
Truth table100%2/2
A
A= $ground
Aresult
11
00
862 4212 ▶ $line .= "\e[${want}m" unless $want eq $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $want eq $code 769 3443 4212
863 4212 $code = $want;
864 4212 ▶ $line .= defined $glyph->{$what} ? $glyph->{$what} : $what;
Branch: 1 branch
BranchTrueFalseTotal
defined $glyph->{$what} ? : 1887 2325 4212
865 }
866 156 $line .= "\e[0m";
867 }
868 else {
869 259038 ▶ my $text = join '', map { defined $glyph->{ $_->[0] } ? $glyph->{ $_->[0] } : $_->[0] }
Branch: 1 branch
BranchTrueFalseTotal
defined $$glyph{$_->[0]} ? : 116498 142540 259038
870 9594 @{ $canvas->[$row] };
871 9594 $text =~ s/ +$//;
872 9594 $drawn = length $text;
873 9594 $line .= $text;
874 }
875 9750 my $note = $aside[$row];
876 9750 ▶ if (defined $note && length $note) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $note and length $note) 3758 5992 9750
Condition100%3/3
defined $note and length $note
!ll&&!rl&&r
52507423758
MC/DC100%2/2
defined $note and length $note
defined $note length $note
Truth table100%3/3
A and B
A= defined $noteB= length $note
ABresult
0X0
100
111
877 3758 $line .= ' ' x (2 + WIDTH - $drawn);
878 3758 $line .= $note;
879 }
880 9750 $line =~ s/ +$//;
881 9750 push @lines, $line;
882 }
883 750 push @lines, ' ' . join ' ', map { $self->paint($_, 'label') } 'a' .. 'g';
884 750 return \@lines;
885 }
886  
887 750 ▶sub aside {
Subroutine aside: called CC=5 SCAR=16.1
Pod documented
888 750 my ($self) = @_;
889 750 my $game = $self->game;
890 750 my $glyph = $self->glyphs;
891 750 my @aside;
892 750 my $row = 2;
893 750 for my $side (qw/white black/) {
894 1500 my $man = $self->paint($glyph->{$side}, $side, 'board');
895 1500 my $name = $self->paint(sprintf('%-5s', ucfirst $side), $self->ink_of($side));
896 1500 ▶ $name .= $self->paint(' (you)', 'dim') if $side eq $self->human;
Branch: 1 branch
BranchTrueFalseTotal
if $side eq $self->human 69 1431 1500
897 1500 $aside[$row] = $name;
898 1500 $aside[ $row + 1 ] = sprintf 'in hand %d on the board %d lost %d',
899 $game->in_hand($side), $game->on_board($side),
900 Game::Merrills::Board::MEN - $game->men($side);
901 1500 my $hand = $game->in_hand($side);
902 $aside[ $row + 2 ] = $hand
903 1500 ▶ ? join ' ', ($self->colour ? $man : $glyph->{$side}) x $hand
Branch: 2 branches
BranchTrueFalseTotal
$hand ? : 758 742 1500
$self->colour ? : 12 746 758
904 : '';
905 1500 $row += 4;
906 }
907 750 return \@aside;
908 }
909  
910 1454 ▶sub mills_of {
Subroutine mills_of: called CC=4 SCAR=13.9
Pod documented
911 1454 my ($self, $side) = @_;
912 1454 my $board = $self->game->board;
913 1454 my @mills;
914 1454 for my $mill (Game::Merrills::Points::mills()) {
915 23264 ▶ next if grep { ($board->side_at($_) || '') ne $side } @{$mill};
Branch: 1 branch
BranchTrueFalseTotal
if grep {($board->side_at($_) || "") ne $side;} @{$mill;} 22983 281 23264
Condition100%2/2
$board->side_at($_) || ''
l!l
2402445768
MC/DC100%1/1
$board->side_at($_) || ''
$board->side_at($_)
Truth table100%2/2
A
A= $board->side_at($_)
Aresult
11
00
916 281 push @mills, join '-', map { Game::Merrills::Points::name($_) } @{$mill};
917 }
918 1454 return \@mills;
919 }
920  
921 727 ▶sub status_lines {
Subroutine status_lines: called CC=14 SCAR=26.4
Pod documented
922 727 my ($self) = @_;
923 727 my $game = $self->game;
924 727 my @lines = map { $self->paint($_, 'said') } @{ $self->recent };
925  
926 727 for my $side (qw/white black/) {
927 1454 my $mills = $self->mills_of($side);
928 1454 ▶ next unless @{$mills};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$mills;} 1203 251 1454
929 push @lines, $self->paint(
930 251 sprintf('%s %s: %s', ucfirst $side, @{$mills} == 1 ? 'mill' : 'mills',
931 251 ▶ join ', ', @{$mills}),
Branch: 1 branch
BranchTrueFalseTotal
@{$mills;} == 1 ? : 223 28 251
932 'mill'
933 );
934 }
935  
936 727 ▶ if (my $result = $game->result) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $game->result) 21 706 727
937 21 ▶ push @lines, $self->paint($result->stringify,
Branch: 3 branches
BranchTrueFalseTotal
$result->is_draw ? : 5 16 21
$result->winner eq $self->human ? : 1 15 16
$self->human =~ /^(?:white|black)$/ ? : 2 13 15
938 $result->is_draw ? 'mill'
939 : $result->winner eq $self->human ? 'good'
940 : $self->human =~ m/^(?:white|black)$/ ? 'warn' : 'good');
941 21 return \@lines;
942 }
943  
944 706 my $turn = $game->turn;
945 706 ▶ my $who = ucfirst($turn) . ($turn eq $self->human ? ' (you)' : '');
Branch: 1 branch
BranchTrueFalseTotal
$turn eq $self->human ? : 47 659 706
946 706 my $phase = $game->phase;
947 706 ▶ push @lines, $self->paint(
Branch: 2 branches
BranchTrueFalseTotal
$phase eq 'placing' ? : 346 360 706
$phase eq 'flying' ? : 71 289 360
948 $phase eq 'placing' ? sprintf('%s to place, %d in hand.', $who, $game->in_hand($turn))
949 : $phase eq 'flying' ? sprintf('%s to move, and flying.', $who)
950 : sprintf('%s to move.', $who),
951 $self->ink_of($turn)
952 );
953  
954 706 my $limit = $Game::Merrills::NO_MILL_LIMIT;
955 706 ▶ push @lines, $self->paint(
Branch: 1 branch
BranchTrueFalseTotal
if $limit and $game->no_mill * 2 >= $limit 1 705 706
Condition66%2/3
$limit and $game->no_mill * 2 >= $limit
!ll&&!rl&&r
07051
MC/DC50%1/2
$limit and $game->no_mill * 2 >= $limit
$limit $game->no_mill * 2 >= $limit
Truth table66%2/3
A and B
A= $limitB= $game->no_mill * 2 >= $limit
ABresult
0X0
100
111
956 sprintf('No mill for %d moves: it is a draw at %d.', $game->no_mill, $limit), 'warn'
957 ) if $limit && $game->no_mill * 2 >= $limit;
958  
959 706 ▶ push @lines, $self->paint(
Branch: 1 branch
BranchTrueFalseTotal
if $game->draw_offered_by 1 705 706
960 sprintf('%s has offered a draw: accept or decline.', ucfirst $game->draw_offered_by), 'hint'
961 ) if $game->draw_offered_by;
962  
963 706 return \@lines;
964 }
965  
966 131 ▶sub command {
Subroutine command: called CC=25 SCAR=32.2
Pod documented
967 131 my ($self, $line) = @_;
968 131 $line =~ s/^\s+|\s+$//g;
969 131 ▶ return 0 unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 31 100 131
970  
971 100 my ($word, $argument) = split ' ', $line, 2;
972 100 $word = lc $word;
973  
974 100 ▶ return $self->show_help if $word eq 'help' || $word eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "help" or $word eq "?" 3 97 100
Condition100%3/3
$word eq "help" or $word eq "?"
l!l&&r!l&&!r
2197
MC/DC100%2/2
$word eq "help" or $word eq "?"
$word eq "help" $word eq "?"
Truth table100%3/3
A or B
A= $word eq "help"B= $word eq "?"
ABresult
1X1
011
000
975 97 ▶ return $self->redraw(1) && 0 if $word eq 'board';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "board" 1 96 97
Condition50%1/2
$self->redraw(1) && 0
!ll
01
MC/DC0%0/1
$self->redraw(1) && 0
$self->redraw(1)
Truth table50%1/2
A
A= $self->redraw(1)
Aresult
00
11
976 96 ▶ return $self->show_moves if $word eq 'moves';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "moves" 4 92 96
977 92 ▶ return $self->set_picking($word) if $word eq 'pick' || $word eq 'type';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "pick" or $word eq "type" 3 89 92
Condition100%3/3
$word eq "pick" or $word eq "type"
l!l&&r!l&&!r
2189
MC/DC100%2/2
$word eq "pick" or $word eq "type"
$word eq "pick" $word eq "type"
Truth table100%3/3
A or B
A= $word eq "pick"B= $word eq "type"
ABresult
1X1
011
000
978 89 ▶ return $self->show_hint if $word eq 'hint';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "hint" 4 85 89
979 85 ▶ return $self->say($self->game->to_position) && 0 if $word eq 'position';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "position" 5 80 85
Condition50%1/2
$self->say($self->game->to_position) && 0
!ll
05
MC/DC0%0/1
$self->say($self->game->to_position) && 0
$self->say($self->game->to_position)
Truth table50%1/2
A
A= $self->say($self->game->to_position)
Aresult
00
11
980 80 ▶ return $self->take_back if $word eq 'undo';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "undo" 4 76 80
981 76 ▶ return $self->save($argument) if $word eq 'save';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "save" 4 72 76
982 72 ▶ return $self->load($argument) if $word eq 'load';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "load" 4 68 72
983 68 ▶ return $self->set_level($argument) if $word eq 'level';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "level" 3 65 68
984 65 ▶ return $self->toggle($word) if $word eq 'ascii' || $word eq 'colour' || $word eq 'color';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "ascii" or $word eq "colour" or $word eq "color" 4 61 65
Condition100%6/6
$word eq "ascii" or $word eq "colour" or $word eq "color"
l!l&&r!l&&!r
3161
$word eq "ascii" or $word eq "colour"
l!l&&r!l&&!r
2162
MC/DC100%3/3
$word eq "ascii" or $word eq "colour" or $word eq "color"
$word eq "ascii" $word eq "colour" $word eq "color"
Truth table100%4/4
A or B or C
A= $word eq "ascii"B= $word eq "colour"C= $word eq "color"
ABCresult
1XX1
01X1
0011
0000
985 61 ▶ return $self->offer_draw if $word eq 'draw';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "draw" 5 56 61
986 56 ▶ return $self->answer_draw($word) if $word eq 'accept' || $word eq 'decline';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "accept" or $word eq "decline" 3 53 56
Condition100%3/3
$word eq "accept" or $word eq "decline"
l!l&&r!l&&!r
2153
MC/DC100%2/2
$word eq "accept" or $word eq "decline"
$word eq "accept" $word eq "decline"
Truth table100%3/3
A or B
A= $word eq "accept"B= $word eq "decline"
ABresult
1X1
011
000
987 53 ▶ return $self->resign if $word eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "resign" 5 48 53
988 48 ▶ return $self->quit if $word eq 'quit';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "quit" 3 45 48
989  
990 45 ▶ return $self->play_number($word) if $word =~ m/^[0-9]+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^[0-9]+$/ 5 40 45
991 40 return $self->play($line);
992 }
993  
994 40 ▶sub play {
Subroutine play: called CC=8 SCAR=21.0
Pod documented
995 40 my ($self, $notation) = @_;
996 40 my $move = $self->game->move($notation);
997 40 ▶ unless (ref $move eq 'Game::Merrills::Error') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $move eq "Game::Merrills::Error") 36 4 40
998 36 $self->played($move);
999 36 return 0;
1000 }
1001  
1002 4 $self->say($self->paint(ucfirst($move->message) . '.', 'warn'));
1003 4 ▶ $self->say('Type moves for the list, or help for the commands.')
Branch: 1 branch
BranchTrueFalseTotal
if $move->not_a_move 2 2 4
1004 if $move->not_a_move;
1005 4 my @legal = @{ $move->legal };
1006 4 ▶ $self->say('You could play: ' . join(', ', map { $_->notation } @legal[ 0 .. ($#legal > 11 ? 11 : $#legal) ])
Branch: 3 branches
BranchTrueFalseTotal
if @legal and not $move->not_a_move and not $move->game_over 2 2 4
$#legal > 11 ? : 2 0 2
@legal > 12 ? : 2 0 2
Condition66%4/6
@legal and not $move->not_a_move and not $move->game_over
!ll&&!rl&&r
202
@legal and not $move->not_a_move
!ll&&!rl&&r
022
MC/DC33%1/3
@legal and not $move->not_a_move and not $move->game_over
@legal not $move->not_a_move not $move->game_over
Truth table50%2/4
A and not(B) and not(C)
A= @legalB= not $move->not_a_moveC= not $move->game_over
ABCresult
0XX0
10X0
1100
1111
1007 . (@legal > 12 ? sprintf(', and %d more', @legal - 12) : '') . '.')
1008 if @legal && !$move->not_a_move && !$move->game_over;
1009 4 return 0;
1010 }
1011  
1012 5 ▶sub play_number {
Subroutine play_number: called CC=4 SCAR=13.9
Pod documented
1013 5 my ($self, $number) = @_;
1014 5 my $legal = $self->game->legal_moves;
1015 return $self->say("There is no move $number. Type moves for the list.") && 0
1016 5 ▶ unless $number >= 1 && $number <= @{$legal};
Branch: 1 branch
BranchTrueFalseTotal
unless $number >= 1 and $number <= @{$legal;} 2 3 5
Condition80%4/5
$number >= 1 and $number <= @{$legal;}
!ll&&!rl&&r
113
$self->say("There is no move $number. Type moves for the list.") && 0
!ll
02
MC/DC100%2/2
$number >= 1 and $number <= @{$legal;}
$number >= 1 $number <= @{$legal;}
MC/DC0%0/1
$self->say("There is no move $number. Type moves for the list.") && 0
$self->say("There is no move $number. Type moves for the list.")
Truth table100%3/3
A and B
A= $number >= 1B= $number <= @{$legal;}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $self->say("There is no move $number. Type moves for the list.")
Aresult
00
11
1017 3 $self->played($self->game->move($legal->[ $number - 1 ]));
1018 3 return 0;
1019 }
1020  
1021 4 ▶sub show_moves {
Subroutine show_moves: called CC=4 SCAR=14.0
Pod documented
1022 4 my ($self) = @_;
1023 4 my $legal = $self->game->legal_moves;
1024 4 ▶ return $self->say('There is nothing to play.') && 0 unless @{$legal};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$legal;} 0 4 4
Condition0%0/2
$self->say('There is nothing to play.') && 0
!ll
00
MC/DC0%0/1
$self->say('There is nothing to play.') && 0
$self->say('There is nothing to play.')
Truth table0%0/2
A
A= $self->say('There is nothing to play.')
Aresult
00
11
1025 4 my @cells = map { sprintf '%2d. %-9s', $_ + 1, $legal->[$_]->notation } 0 .. $#{$legal};
1026 4 ▶ while (my @row = splice @cells, 0, 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@row) = splice(@cells, 0, 5)) 23 4 27
1027 23 my $text = join ' ', @row;
1028 23 $text =~ s/ +$//;
1029 23 $self->say($text);
1030 }
1031 4 $self->say('Play one by its number, or type it out.');
1032 4 return 0;
1033 }
1034  
1035 7 ▶sub hint {
Subroutine hint: called CC=5 SCAR=16.4
Pod documented
1036 7 my ($self) = @_;
1037 7 ▶ my $bot = $self->bot_for($OTHER{ $self->game->turn })
Condition66%4/6
$self->bot_for($OTHER{$self->game->turn}) || $self->bot_for($self->game->turn) || 'Game::Merrills::Bot'->new
l!l&&r!l&&!r
250
$self->bot_for($OTHER{$self->game->turn}) or $self->bot_for($self->game->turn)
l!l&&r!l&&!r
205
MC/DC0%0/3
$self->bot_for($OTHER{$self->game->turn}) || $self->bot_for($self->game->turn) || 'Game::Merrills::Bot'->new
$self->bot_for($OTHER{$self->game->turn}) $self->bot_for($self->game->turn) 'Game::Merrills::Bot'->new
Truth table50%2/4
A or B || C
A= $self->bot_for($OTHER{$self->game->turn})B= $self->bot_for($self->game->turn)C= 'Game::Merrills::Bot'->new
ABCresult
1XX1
01X1
0011
0000
1038 || $self->bot_for($self->game->turn)
1039 || Game::Merrills::Bot->new;
1040 7 my $move = $bot->choose($self->game);
1041 7 ▶ return { line => 'There is nothing to play.' } unless $move;
Branch: 1 branch
BranchTrueFalseTotal
unless $move 1 6 7
1042 6 my $score = $bot->last_search->{score};
1043 return {
1044 6 ▶ move => $move,
Branch: 1 branch
BranchTrueFalseTotal
defined $score ? : 6 0 6
1045 line => sprintf('Try %s%s.', $move->notation,
1046 defined $score ? sprintf(' (it scores that %+.2f)', $score / 100) : '')
1047 };
1048 }
1049  
1050 4 ▶sub show_hint {
Subroutine show_hint: called CC=1 SCAR=0.0
Pod documented
1051 4 my ($self) = @_;
1052 4 $self->say($self->paint($self->hint->{line}, 'hint'));
1053 4 return 0;
1054 }
1055  
1056 4 ▶sub take_back {
Subroutine take_back: called CC=5 SCAR=16.2
Pod documented
1057 4 my ($self) = @_;
1058 4 my $game = $self->game;
1059 4 ▶ return $self->say('There is nothing to take back.') && 0 unless @{ $game->history };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$game->history;} 1 3 4
Condition50%1/2
$self->say('There is nothing to take back.') && 0
!ll
01
MC/DC0%0/1
$self->say('There is nothing to take back.') && 0
$self->say('There is nothing to take back.')
Truth table50%1/2
A
A= $self->say('There is nothing to take back.')
Aresult
00
11
1060  
1061 3 $game->undo;
1062 3 ▶ $game->undo if @{ $game->history } && $self->bot_plays($game->turn);
Branch: 1 branch
BranchTrueFalseTotal
if @{$game->history;} and $self->bot_plays($game->turn) 1 2 3
Condition66%2/3
@{$game->history;} and $self->bot_plays($game->turn)
!ll&&!rl&&r
021
MC/DC50%1/2
@{$game->history;} and $self->bot_plays($game->turn)
@{$game->history;} $self->bot_plays($game->turn)
Truth table66%2/3
A and B
A= @{$game->history;}B= $self->bot_plays($game->turn)
ABresult
0X0
100
111
1063 3 $self->recent([]);
1064 3 $self->later('Taken back.');
1065 3 return 0;
1066 }
1067  
1068 4 ▶sub later {
Subroutine later: called CC=3 SCAR=11.0
Pod documented
1069 4 my ($self, $line) = @_;
1070 4 ▶ if ($self->picking && $self->raw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->picking and $self->raw) { } 1 3 4
Condition66%2/3
$self->picking and $self->raw
!ll&&!rl&&r
301
MC/DC50%1/2
$self->picking and $self->raw
$self->picking $self->raw
Truth table66%2/3
A and B
A= $self->pickingB= $self->raw
ABresult
0X0
100
111
1071 1 $self->redraw(1);
1072 }
1073 else {
1074 3 $self->render;
1075 }
1076 4 $self->say($line);
1077 4 return $self;
1078 }
1079  
1080 4 ▶sub save {
Subroutine save: called CC=5 SCAR=16.2
Pod documented
1081 4 my ($self, $file) = @_;
1082 4 ▶ return $self->say('Save needs a file name.') && 0 unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 1 3 4
Condition50%1/2
$self->say('Save needs a file name.') && 0
!ll
01
MC/DC0%0/1
$self->say('Save needs a file name.') && 0
$self->say('Save needs a file name.')
Truth table50%1/2
A
A= $self->say('Save needs a file name.')
Aresult
00
11
1083 3 ▶ open my $handle, '>', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $handle, ">", $file or return $self->say("Cannot write ${file}: $!") && 0 2 1 3
Condition50%1/2
$self->say("Cannot write ${file}: $!") && 0
!ll
01
MC/DC0%0/1
$self->say("Cannot write ${file}: $!") && 0
$self->say("Cannot write ${file}: $!")
Truth table50%1/2
A
A= $self->say("Cannot write ${file}: $!")
Aresult
00
11
1084 or return $self->say("Cannot write $file: $!") && 0;
1085 2 print {$handle} $self->game->to_text;
1086 2 close $handle;
1087 2 $self->say("Saved to $file.");
1088 2 return 0;
1089 }
1090  
1091 4 ▶sub load {
Subroutine load: called CC=7 SCAR=19.5
Pod documented
1092 4 my ($self, $file) = @_;
1093 4 ▶ return $self->say('Load needs a file name.') && 0 unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 1 3 4
Condition50%1/2
$self->say('Load needs a file name.') && 0
!ll
01
MC/DC0%0/1
$self->say('Load needs a file name.') && 0
$self->say('Load needs a file name.')
Truth table50%1/2
A
A= $self->say('Load needs a file name.')
Aresult
00
11
1094 3 ▶ open my $handle, '<', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $handle, "<", $file or return $self->say("Cannot read ${file}: $!") && 0 2 1 3
Condition50%1/2
$self->say("Cannot read ${file}: $!") && 0
!ll
01
MC/DC0%0/1
$self->say("Cannot read ${file}: $!") && 0
$self->say("Cannot read ${file}: $!")
Truth table50%1/2
A
A= $self->say("Cannot read ${file}: $!")
Aresult
00
11
1095 or return $self->say("Cannot read $file: $!") && 0;
1096 2 my $text = do { local $/; <$handle> };
1097 2 close $handle;
1098 2 my $game = eval { Game::Merrills->from_text($text, flying => $self->game->flying) };
1099 2 ▶ unless ($game) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game) 1 1 2
1100 1 my $why = $@;
1101 1 $why =~ s/\s+$//;
1102 1 ▶ return $self->say("That is not a game I can read: $why") && 0;
Condition50%1/2
$self->say("That is not a game I can read: $why") && 0
!ll
01
MC/DC0%0/1
$self->say("That is not a game I can read: $why") && 0
$self->say("That is not a game I can read: $why")
Truth table50%1/2
A
A= $self->say("That is not a game I can read: $why")
Aresult
00
11
1103 }
1104 1 $self->game($game);
1105 1 $self->recent([]);
1106 1 $self->later("Loaded $file, " . scalar(@{ $game->history }) . ' moves in.');
1107 1 return 0;
1108 }
1109  
1110 3 ▶sub set_level {
Subroutine set_level: called CC=7 SCAR=21.0
Pod documented
1111 3 my ($self, $level) = @_;
1112 3 ▶ return $self->say('Level takes a number from 1 to 5.') && 0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $level and $level =~ /^[1-5]$/ 2 1 3
Condition80%4/5
defined $level and $level =~ /^[1-5]$/
!ll&&!rl&&r
111
$self->say('Level takes a number from 1 to 5.') && 0
!ll
02
MC/DC100%2/2
defined $level and $level =~ /^[1-5]$/
defined $level $level =~ /^[1-5]$/
MC/DC0%0/1
$self->say('Level takes a number from 1 to 5.') && 0
$self->say('Level takes a number from 1 to 5.')
Truth table100%3/3
A and B
A= defined $levelB= $level =~ /^[1-5]$/
ABresult
0X0
100
111
Truth table50%1/2
A
A= $self->say('Level takes a number from 1 to 5.')
Aresult
00
11
1113 unless defined $level && $level =~ m/^[1-5]$/;
1114 1 my $bot = $self->bot;
1115 1 ▶ if (ref $bot eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bot eq 'HASH') { } 0 1 1
1116 $bot->{$_} = Game::Merrills::Bot->new(level => $level, seed => $bot->{$_}->seed)
1117 0 for grep { $bot->{$_} } keys %{$bot};
1118 }
1119 else {
1120 1 ▶ $self->bot(Game::Merrills::Bot->new(level => $level, seed => $bot ? $bot->seed : 0));
Branch: 1 branch
BranchTrueFalseTotal
$bot ? : 1 0 1
1121 }
1122 1 $self->say("The bot is at level $level.");
1123 1 return 0;
1124 }
1125  
1126 4 ▶sub toggle {
Subroutine toggle: called CC=3 SCAR=11.0
Pod documented
1127 4 my ($self, $what) = @_;
1128 4 ▶ $what = 'colour' if $what eq 'color';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "color" 1 3 4
1129 4 ▶ $self->$what($self->$what ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->$what ? : 2 2 4
1130 4 $self->layer;
1131 4 $self->redraw(1);
1132 4 return 0;
1133 }
1134  
1135 5 ▶sub offer_draw {
Subroutine offer_draw: called CC=9 SCAR=22.3
Pod documented
1136 5 my ($self) = @_;
1137 5 my $game = $self->game;
1138 5 ▶ my $side = $self->human =~ m/^(?:white|black)$/ ? $self->human : $game->turn;
Branch: 1 branch
BranchTrueFalseTotal
$self->human =~ /^(?:white|black)$/ ? : 3 2 5
1139 5 my $offered = $game->offer_draw($side);
1140 5 ▶ return $self->say(ucfirst($offered->message) . '.') && 0
Branch: 1 branch
BranchTrueFalseTotal
if ref $offered eq "Game::Merrills::Error" 0 5 5
Condition0%0/2
$self->say(ucfirst($offered->message) . '.') && 0
!ll
00
MC/DC0%0/1
$self->say(ucfirst($offered->message) . '.') && 0
$self->say(ucfirst($offered->message) . '.')
Truth table0%0/2
A
A= $self->say(ucfirst($offered->message) . '.')
Aresult
00
11
1141 if ref $offered eq 'Game::Merrills::Error';
1142 5 ▶ my $bot = $self->bot_plays($OTHER{$side}) ? $self->bot_for($OTHER{$side}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->bot_plays($OTHER{$side}) ? : 3 2 5
1143 5 ▶ unless ($bot) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bot) 2 3 5
1144 2 $self->say(ucfirst($side) . ' offers a draw. ' . ucfirst($OTHER{$side})
1145 . ' may accept or decline.');
1146 2 return 0;
1147 }
1148  
1149 3 ▶ my $score = $bot->last_search ? $bot->last_search->{score} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$bot->last_search ? : 3 0 3
1150 3 ▶ if (defined $score && $score <= 30) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $score and $score <= 30) { } 2 1 3
Condition66%2/3
defined $score and $score <= 30
!ll&&!rl&&r
012
MC/DC50%1/2
defined $score and $score <= 30
defined $score $score <= 30
Truth table66%2/3
A and B
A= defined $scoreB= $score <= 30
ABresult
0X0
100
111
1151 2 $game->accept_draw($OTHER{$side});
1152 2 $self->say('The bot takes the draw.');
1153 2 $self->redraw(1);
1154 }
1155 else {
1156 1 $game->decline_draw($OTHER{$side});
1157 1 $self->say('The bot plays on.');
1158 }
1159 3 return 0;
1160 }
1161  
1162 3 ▶sub answer_draw {
Subroutine answer_draw: called CC=7 SCAR=19.5
Pod documented
1163 3 my ($self, $word) = @_;
1164 3 my $game = $self->game;
1165 3 my $offered = $game->draw_offered_by;
1166 3 ▶ my $side = $offered ? $OTHER{$offered} : $game->turn;
Branch: 1 branch
BranchTrueFalseTotal
$offered ? : 2 1 3
1167 3 ▶ my $answer = $word eq 'accept' ? $game->accept_draw($side) : $game->decline_draw($side);
Branch: 1 branch
BranchTrueFalseTotal
$word eq 'accept' ? : 2 1 3
1168 3 ▶ return $self->say(ucfirst($answer->message) . '.') && 0
Branch: 1 branch
BranchTrueFalseTotal
if ref $answer eq "Game::Merrills::Error" 1 2 3
Condition50%1/2
$self->say(ucfirst($answer->message) . '.') && 0
!ll
01
MC/DC0%0/1
$self->say(ucfirst($answer->message) . '.') && 0
$self->say(ucfirst($answer->message) . '.')
Truth table50%1/2
A
A= $self->say(ucfirst($answer->message) . '.')
Aresult
00
11
1169 if ref $answer eq 'Game::Merrills::Error';
1170 2 ▶ return $self->redraw(1) && 0 if $word eq 'accept';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "accept" 1 1 2
Condition50%1/2
$self->redraw(1) && 0
!ll
01
MC/DC0%0/1
$self->redraw(1) && 0
$self->redraw(1)
Truth table50%1/2
A
A= $self->redraw(1)
Aresult
00
11
1171 1 $self->say(ucfirst($side) . ' plays on.');
1172 1 return 0;
1173 }
1174  
1175 6 ▶sub resign {
Subroutine resign: called CC=4 SCAR=14.5
Pod documented
1176 6 my ($self) = @_;
1177 6 my $game = $self->game;
1178 6 ▶ my $resigned = $game->resign($self->human =~ m/^(?:white|black)$/ ? $self->human : $game->turn);
Branch: 1 branch
BranchTrueFalseTotal
$self->human =~ /^(?:white|black)$/ ? : 3 3 6
1179 6 ▶ return $self->say(ucfirst($resigned->message) . '.') && 0
Branch: 1 branch
BranchTrueFalseTotal
if ref $resigned eq "Game::Merrills::Error" 0 6 6
Condition0%0/2
$self->say(ucfirst($resigned->message) . '.') && 0
!ll
00
MC/DC0%0/1
$self->say(ucfirst($resigned->message) . '.') && 0
$self->say(ucfirst($resigned->message) . '.')
Truth table0%0/2
A
A= $self->say(ucfirst($resigned->message) . '.')
Aresult
00
11
1180 if ref $resigned eq 'Game::Merrills::Error';
1181 6 $self->redraw(1);
1182 6 return 0;
1183 }
1184  
1185 3 ▶sub quit {
Subroutine quit: called CC=5 SCAR=16.2
Pod documented
1186 3 my ($self) = @_;
1187 3 ▶ return 1 unless $self->game->status eq 'active' && @{ $self->game->history };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->game->status eq "active" and @{$self->game->history;} 1 2 3
Condition66%2/3
$self->game->status eq "active" and @{$self->game->history;}
!ll&&!rl&&r
012
MC/DC50%1/2
$self->game->status eq "active" and @{$self->game->history;}
$self->game->status eq "active" @{$self->game->history;}
Truth table66%2/3
A and B
A= $self->game->status eq "active"B= @{$self->game->history;}
ABresult
0X0
100
111
1188 2 my $answer = $self->read_line('Really quit, with the game unfinished? (y/n) ');
1189 2 ▶ return 1 if !defined $answer || $answer =~ m/^\s*y/i;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $answer or $answer =~ /^\s*y/i 1 1 2
Condition66%2/3
not defined $answer or $answer =~ /^\s*y/i
l!l&&r!l&&!r
011
MC/DC50%1/2
not defined $answer or $answer =~ /^\s*y/i
not defined $answer $answer =~ /^\s*y/i
Truth table66%2/3
not(A) or B
A= not defined $answerB= $answer =~ /^\s*y/i
ABresult
1X1
011
000
1190 1 return 0;
1191 }
1192  
1193 3 ▶sub help_lines {
Subroutine help_lines: called CC=2 SCAR=7.0
Pod documented
1194 3 my ($self) = @_;
1195 return [
1196 'A move is its points: d2 to place a man, d2-d3 to move one.',
1197 'One that closes a mill says which man it takes: d2-d3xa1.',
1198 57 map { sprintf ' %-10s %s', $_, $COMMAND{$_} }
1199 3 ▶ sort { length $a <=> length $b || $a cmp $b } keys %COMMAND
Condition66%2/3
length $a <=> length $b || $a cmp $b
l!l&&r!l&&!r
107610
MC/DC0%0/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b $a cmp $b
Truth table66%2/3
A || B
A= length $a <=> length $bB= $a cmp $b
ABresult
1X1
011
000
1200 ];
1201 }
1202  
1203 3 ▶sub show_help {
Subroutine show_help: called CC=2 SCAR=6.9
Pod documented
1204 3 my ($self) = @_;
1205 3 $self->say($_) for @{ $self->help_lines };
1206 3 return 0;
1207 }
1208  
1209 68 1;
1210  
1211 __END__
« blib/lib/Game/Merrills/Bot.pm ↑ Summary blib/lib/Game/Merrills/Notation.pm »