blib/lib/Game/Go/Terminal.pm

filter: Statementstmt 91.7% 579 / 631 Branchbran 77.2% 292 / 378 Conditioncond 69.2% 63 / 91 MC/DCmcdc 48.2% 27 / 56 Subroutinesub 96.1% 74 / 77 Podpod 96.4% 27 / 28 totaltotal 84.2% 1062 / 1261 CC 232 SCAR 26.5
CC
232
Cov
85%
run
35.9
_human_marking
29.3
BUILD
26.4
CRAP 14.1
« blib/lib/Game/Go/GTP.pm ↑ Summary blib/lib/Game/Go.pm »
1 package Game::Go::Terminal;
2  
3 23 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 23 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 ▶use Game::Go;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use Game::Go::Bot;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 23 ▶use Game::Go::Rules;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 23 ▶use Game::Go::Notation;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 23 ▶use Game::Go::Scoring;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 23 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 23 ▶use Game::Terminal::Kit::Keys;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 23 ▶use Game::Terminal::Kit::Replay;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 23 ▶use Game::Terminal::Kit::Screen;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 23 ▶use Game::Terminal::Kit::Steer;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 23 ▶use Game::Terminal::Kit::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 23 ▶use Game::Terminal::Kit::Save;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 23 ▶use Game::Terminal::Kit::History;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 23 our $VERSION = '0.05';
24  
25 23 our %STONE = (
26 wide => {
27 black => "\x{25cf}", white => "\x{25cb}",
28 black_last => "\x{25c9}", white_last => "\x{25ce}",
29 took => "\x{00d7}",
30 star => "\x{254b}",
31 cross => "\x{253c}",
32 tl => "\x{250c}", tr => "\x{2510}", bl => "\x{2514}", br => "\x{2518}",
33 t => "\x{252c}", b => "\x{2534}", l => "\x{251c}", r => "\x{2524}",
34 bar => "\x{2500}",
35 },
36 ascii => {
37 black => 'X', white => 'O',
38 black_last => 'x', white_last => 'o',
39 took => 'x',
40 star => '*',
41 cross => '+',
42 tl => '+', tr => '+', bl => '+', br => '+',
43 t => '+', b => '+', l => '+', r => '+',
44 bar => '-',
45 },
46 );
47  
48 23 my $B = Game::Go::Rules::BLACK;
49 23 my $W = Game::Go::Rules::WHITE;
50  
51 23 has in => (is => 'ro');
52 23 has out => (is => 'ro');
53  
54 23 has size => (is => 'ro', isa => Int, default => 9);
55 23 has level => (is => 'ro', isa => Int, default => 2);
56 23 has colour => (is => 'ro', default => 'b');
57 23 has komi => (is => 'ro');
58 23 has handicap => (is => 'ro', isa => Int, default => 0);
59 23 has seed => (is => 'ro', default => 'terminal');
60  
61 23 has ascii => (is => 'ro', default => 0);
62 23 has quiet => (is => 'ro', default => 0);
63 23 has _ansi => (is => 'rw', init_arg => 'ansi', private => 1);
64  
65 23 has game => (is => 'rw');
66 23 has bot => (is => 'rw');
67 23 has history => (is => 'rw');
68 23 has save_file => (is => 'rw');
69  
70 23 has keysource => (is => 'rw');
71  
72 81 ▶has pending => (is => 'rw', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
73  
74 23 has _picking => (is => 'rw', init_arg => 'picking', private => 1);
75  
76 23 has keyboard => (is => 'rw');
77 23 has screen => (is => 'rw');
78  
79 23 has _human => (is => 'rw', private => 1);
80 23 has _shown => (is => 'rw', private => 1, default => 0);
81  
82 81 ▶sub BUILD {
Subroutine BUILD: called CC=26 SCAR=32.7
Pod undocumented
83 81 my ($self) = @_;
84  
85 81 my $size = $self->size;
86 die "Game::Go::Terminal: size must be 9, 13 or 19, not '$size'\n"
87 81 ▶ unless grep { $_ == $size } Game::Go->sizes;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ == $size;} "Game::Go"->sizes 2 79 81
88  
89 79 my $level = $self->level;
90 79 ▶ die "Game::Go::Terminal: level must be 1 to 5, not '$level'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $level >= 1 and $level <= 5 2 77 79
Condition100%3/3
$level >= 1 and $level <= 5
!ll&&!rl&&r
1177
MC/DC100%2/2
$level >= 1 and $level <= 5
$level >= 1 $level <= 5
Truth table100%3/3
A and B
A= $level >= 1B= $level <= 5
ABresult
0X0
100
111
91 unless $level >= 1 && $level <= 5;
92  
93 77 my $colour = lc $self->colour;
94 77 ▶ $colour = 'b' if $colour eq 'black' || $colour eq 'dark';
Branch: 1 branch
BranchTrueFalseTotal
if $colour eq "black" or $colour eq "dark" 16 61 77
Condition100%3/3
$colour eq "black" or $colour eq "dark"
l!l&&r!l&&!r
15161
MC/DC100%2/2
$colour eq "black" or $colour eq "dark"
$colour eq "black" $colour eq "dark"
Truth table100%3/3
A or B
A= $colour eq "black"B= $colour eq "dark"
ABresult
1X1
011
000
95 77 ▶ $colour = 'w' if $colour eq 'white' || $colour eq 'light';
Branch: 1 branch
BranchTrueFalseTotal
if $colour eq "white" or $colour eq "light" 3 74 77
Condition100%3/3
$colour eq "white" or $colour eq "light"
l!l&&r!l&&!r
2174
MC/DC100%2/2
$colour eq "white" or $colour eq "light"
$colour eq "white" $colour eq "light"
Truth table100%3/3
A or B
A= $colour eq "white"B= $colour eq "light"
ABresult
1X1
011
000
96 77 my $who = Game::Go::Rules::from_letter($colour);
97 77 ▶ die "Game::Go::Terminal: colour must be black or white, not '" . $self->colour . "'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $who 1 76 77
98 unless $who;
99 76 $self->_human($who);
100  
101 76 my $most = Game::Go::Rules::max_handicap($size);
102 76 ▶ die "Game::Go::Terminal: handicap must be 0 to $most on a ${size}x$size board\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->handicap < 0 or $self->handicap > $most 1 75 76
Condition66%2/3
$self->handicap < 0 or $self->handicap > $most
l!l&&r!l&&!r
0175
MC/DC50%1/2
$self->handicap < 0 or $self->handicap > $most
$self->handicap < 0 $self->handicap > $most
Truth table66%2/3
A or B
A= $self->handicap < 0B= $self->handicap > $most
ABresult
1X1
011
000
103 if $self->handicap < 0 || $self->handicap > $most;
104  
105 75 ▶ if (defined $self->komi) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->komi) 1 74 75
106 1 ▶ die "Game::Go::Terminal: komi must be a multiple of 0.5\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->komi =~ /\A-?[0-9]+(?:\.[05])?\z/ 1 0 1
107 unless $self->komi =~ /\A-?[0-9]+(?:\.[05])?\z/;
108 }
109  
110 74 ▶ $self->game(Game::Go->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $self->komi ? : 0 74 74
111 size => $size,
112 handicap => $self->handicap,
113 (defined $self->komi ? (komi => $self->komi) : ()),
114 seed => $self->seed,
115 ));
116 74 $self->bot(Game::Go::Bot->new(level => $level, seed => $self->seed));
117 74 ▶ $self->history(_new_history()) unless $self->history;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->history 74 0 74
118 74 ▶ $self->history->name('go') unless defined $self->history->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->history->name 0 74 74
119 74 $self->history->version($VERSION);
120 74 ▶ $self->history->file($self->save_file) if defined $self->save_file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->save_file 7 67 74
121 74 $self->history->start($self->game);
122  
123 74 my $out = $self->out;
124 74 ▶ my $ansi = defined $self->_ansi ? $self->_ansi : $self->_want_ansi;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_ansi ? : 49 25 74
125 74 ▶ $self->keyboard(Game::Terminal::Kit::Keys->new(
Branch: 3 branches
BranchTrueFalseTotal
unless $self->keyboard 74 0 74
$self->in ? : 64 10 74
$self->keysource ? : 26 48 74
126 ($self->in ? (in => $self->in) : ()),
127 pending => $self->pending,
128 ($self->keysource ? (keysource => $self->keysource) : ()),
129 )) unless $self->keyboard;
130 74 ▶ $self->screen(Game::Terminal::Kit::Screen->new(
Branch: 4 branches
BranchTrueFalseTotal
unless $self->screen 74 0 74
$out ? : 65 9 74
$ansi ? : 2 72 74
$self->ascii ? : 50 24 74
131 ($out ? (out => $out) : (interactive => 0)),
132 colour => ($ansi ? 1 : 0),
133 ascii => ($self->ascii ? 1 : 0),
134 )) unless $self->screen;
135 74 ▶ $self->screen->utf8 if $out;
Branch: 1 branch
BranchTrueFalseTotal
if $out 65 9 74
136 74 return;
137 }
138  
139 25 ▶sub _want_ansi {
Subroutine _want_ansi: called CC=4 SCAR=13.9
140 25 my ($self) = @_;
141 25 ▶ return 0 if Game::Terminal::Kit::Screen::no_colour();
Branch: 1 branch
BranchTrueFalseTotal
if Game::Terminal::Kit::Screen::no_colour() 14 11 25
142 11 my $out = $self->out;
143 11 ▶ return 0 unless $out;
Branch: 1 branch
BranchTrueFalseTotal
unless $out 7 4 11
144 4 ▶ return -t $out ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
-t $out ? : 0 4 4
145 }
146  
147 2336 ▶sub _say {
Subroutine _say: called CC=4 SCAR=15.2
148 2336 my ($self, @lines) = @_;
149 2336 ▶ return if $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $self->quiet 0 2336 2336
150 2336 ▶ return unless $self->out && @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out and @lines 0 2336 2336
Condition33%1/3
$self->out and @lines
!ll&&!rl&&r
002336
MC/DC0%0/2
$self->out and @lines
$self->out @lines
Truth table33%1/3
A and B
A= $self->outB= @lines
ABresult
0X0
100
111
151 2336 $self->screen->say(@lines);
152 2336 return;
153 }
154  
155 2 ▶sub ansi {
Subroutine ansi: called CC=2 SCAR=7.1
Pod documented
156 2 my ($self, @set) = @_;
157 2 ▶ $self->screen->colour($set[0]) if @set;
Branch: 1 branch
BranchTrueFalseTotal
if @set 0 2 2
158 2 return $self->screen->colour;
159 }
160  
161 40587 ▶sub _ink {
Subroutine _ink: called CC=1 SCAR=0.0
162 40587 my ($self, $code, $text) = @_;
163 40587 return $self->screen->paint($text, $code);
164 }
165  
166 38071 ▶sub glyph {
Subroutine glyph: called CC=12 SCAR=24.9
Pod documented
167 38071 my ($self, $colour, %o) = @_;
168  
169 38071 ▶ my $set = $self->ascii ? 'ascii' : 'wide';
Branch: 1 branch
BranchTrueFalseTotal
$self->ascii ? : 34911 3160 38071
170 38071 my $stone = $STONE{$set};
171  
172 38071 ▶ if ($colour == $B || $colour == $W) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colour == $B or $colour == $W) 6721 31350 38071
Condition100%3/3
$colour == $B or $colour == $W
l!l&&r!l&&!r
184653731350
MC/DC100%2/2
$colour == $B or $colour == $W
$colour == $B $colour == $W
Truth table100%3/3
A or B
A= $colour == $BB= $colour == $W
ABresult
1X1
011
000
173 my $face = $o{last}
174 ? ($colour == $B ? $stone->{black_last} : $stone->{white_last})
175 6721 ▶ : ($colour == $B ? $stone->{black} : $stone->{white});
Branch: 3 branches
BranchTrueFalseTotal
$o{'last'} ? : 336 6385 6721
$colour == $B ? : 2 334 336
$colour == $B ? : 182 6203 6385
176 6721 ▶ my $ink = $o{last} ? '1;31' : $colour == $B ? '1;30' : '1;37';
Branch: 2 branches
BranchTrueFalseTotal
$o{'last'} ? : 336 6385 6721
$colour == $B ? : 182 6203 6385
177 6721 return $self->_ink($ink, $face);
178 }
179  
180 return $o{took} ? $self->_ink('1;31', $stone->{took})
181 : $o{star} ? $stone->{star}
182 31350 ▶ : $stone->{$o{line} || 'cross'};
Branch: 2 branches
BranchTrueFalseTotal
$o{'took'} ? : 0 31350 31350
$o{'star'} ? : 1708 29642 31350
Condition50%1/2
$o{'line'} || 'cross'
l!l
296420
MC/DC0%0/1
$o{'line'} || 'cross'
$o{'line'}
Truth table50%1/2
A
A= $o{'line'}
Aresult
11
00
183 }
184  
185 470 ▶sub board_text {
Subroutine board_text: called CC=18 SCAR=29.0
Pod documented
186 470 my ($self, %o) = @_;
187 470 my $game = $self->game;
188 470 my $size = $game->size;
189 470 my $board = $game->board;
190  
191 470 my @letters = map { Game::Go::Notation::col_letter($_) } 0 .. $size - 1;
192 470 my $width = length $size;
193 470 $o{stars} = { map { $_ => 1 } @{ $game->star_points } };
194  
195 470 ▶ my $set = $self->ascii ? 'ascii' : 'wide';
Branch: 1 branch
BranchTrueFalseTotal
$self->ascii ? : 431 39 470
196 470 my $bar = $STONE{$set}{bar};
197 0 ▶ my %took = map { $_ => 1 } @{ $o{took} || [] };
Condition50%1/2
$o{'took'} || []
l!l
4700
MC/DC0%0/1
$o{'took'} || []
$o{'took'}
Truth table50%1/2
A
A= $o{'took'}
Aresult
11
00
198  
199 470 my @lines;
200 470 push @lines, sprintf('%*s %s', $width, '', join ' ', @letters);
201  
202 470 for my $row (0 .. $size - 1) {
203 4230 my $number = $size - $row;
204 4230 my @cells;
205 4230 for my $col (0 .. $size - 1) {
206 38070 my $at = $board->at($col, $row);
207 38070 my $pt = $game->point($col, $row);
208  
209 38070 ▶ my $on = defined $o{cursor} && $o{cursor} == $pt;
Condition100%3/3
defined $o{'cursor'} && $o{'cursor'} == $pt
!ll&&!rl&&r
30618736092
MC/DC100%2/2
defined $o{'cursor'} && $o{'cursor'} == $pt
defined $o{'cursor'} $o{'cursor'} == $pt
Truth table100%3/3
A && B
A= defined $o{'cursor'}B= $o{'cursor'} == $pt
ABresult
0X0
100
111
210  
211 my $cell = $on && $at == Game::Go::Rules::EMPTY
212 ? $self->_ink('7', $self->glyph($o{to_play} || $B))
213 : $on
214 ? $self->_ink('7', $self->glyph($at))
215 : $self->glyph($at,
216 star => $o{stars}{$pt},
217 took => ($at == Game::Go::Rules::EMPTY && $took{$pt}),
218 38070 ▶ last => (defined $o{last} && $o{last} == $pt),
Branch: 2 branches
BranchTrueFalseTotal
$on && $at == 0 ? : 82 37988 38070
$on ? : 10 37978 37988
Condition75%9/12
$on and $at == 0
!ll&&!rl&&r
379781082
$o{'to_play'} || $B
l!l&&r!l&&!r
8200
$at == 0 && $took{$pt}
!ll&&!rl&&r
6628313500
defined $o{'last'} && $o{'last'} == $pt
!ll&&!rl&&r
996227680336
MC/DC100%2/2
$on and $at == 0
$on $at == 0
MC/DC0%0/2
$o{'to_play'} || $B
$o{'to_play'} $B
MC/DC0%0/2
$at == 0 && $took{$pt}
$at == 0 $took{$pt}
MC/DC100%2/2
defined $o{'last'} && $o{'last'} == $pt
defined $o{'last'} $o{'last'} == $pt
Truth table100%3/3
A and B
A= $onB= $at == 0
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= $o{'to_play'}B= $B
ABresult
1X1
011
000
Truth table66%2/3
A && B
A= $at == 0B= $took{$pt}
ABresult
0X0
100
111
Truth table100%3/3
A && B
A= defined $o{'last'}B= $o{'last'} == $pt
ABresult
0X0
100
111
219 line => $self->_line_at($col, $row, $size));
220  
221 38070 push @cells, { text => $cell, cursor => $on };
222 }
223  
224 4230 my $line = '';
225 4230 for my $i (0 .. $#cells) {
226 $line .= $cells[$i]{cursor} ? '['
227 38070 ▶ : $cells[ $i - 1 ]{cursor} ? ']'
Branch: 3 branches
BranchTrueFalseTotal
if $i 33840 4230 38070
$cells[$i]{'cursor'} ? : 84 33756 33840
$cells[$i - 1]{'cursor'} ? : 85 33671 33756
228 : $self->_ink('2', $bar)
229 if $i;
230 38070 $line .= $cells[$i]{text};
231 }
232  
233 push @lines, sprintf('%*d%s%s%s%d', $width, $number,
234 ($cells[0]{cursor} ? '[' : ' '), $line,
235 4230 ▶ ($cells[-1]{cursor} ? ']' : ' '), $number);
Branch: 2 branches
BranchTrueFalseTotal
$cells[0]{'cursor'} ? : 8 4222 4230
$cells[-1]{'cursor'} ? : 7 4223 4230
236 }
237  
238 470 push @lines, sprintf('%*s %s', $width, '', join ' ', @letters);
239 470 return @lines;
240 }
241  
242 37978 ▶sub _line_at {
Subroutine _line_at: called CC=13 SCAR=25.6
243 37978 my ($self, $col, $row, $size) = @_;
244 37978 my $top = $row == 0;
245 37978 my $bottom = $row == $size - 1;
246 37978 my $left = $col == 0;
247 37978 my $right = $col == $size - 1;
248  
249 37978 ▶ return 'tl' if $top && $left;
Branch: 1 branch
BranchTrueFalseTotal
if $top and $left 470 37508 37978
Condition100%3/3
$top and $left
!ll&&!rl&&r
337503758470
MC/DC100%2/2
$top and $left
$top $left
Truth table100%3/3
A and B
A= $topB= $left
ABresult
0X0
100
111
250 37508 ▶ return 'tr' if $top && $right;
Branch: 1 branch
BranchTrueFalseTotal
if $top and $right 470 37038 37508
Condition100%3/3
$top and $right
!ll&&!rl&&r
337503288470
MC/DC100%2/2
$top and $right
$top $right
Truth table100%3/3
A and B
A= $topB= $right
ABresult
0X0
100
111
251 37038 ▶ return 'bl' if $bottom && $left;
Branch: 1 branch
BranchTrueFalseTotal
if $bottom and $left 470 36568 37038
Condition100%3/3
$bottom and $left
!ll&&!rl&&r
328103758470
MC/DC100%2/2
$bottom and $left
$bottom $left
Truth table100%3/3
A and B
A= $bottomB= $left
ABresult
0X0
100
111
252 36568 ▶ return 'br' if $bottom && $right;
Branch: 1 branch
BranchTrueFalseTotal
if $bottom and $right 470 36098 36568
Condition100%3/3
$bottom and $right
!ll&&!rl&&r
328103288470
MC/DC100%2/2
$bottom and $right
$bottom $right
Truth table100%3/3
A and B
A= $bottomB= $right
ABresult
0X0
100
111
253 36098 ▶ return 't' if $top;
Branch: 1 branch
BranchTrueFalseTotal
if $top 3288 32810 36098
254 32810 ▶ return 'b' if $bottom;
Branch: 1 branch
BranchTrueFalseTotal
if $bottom 3288 29522 32810
255 29522 ▶ return 'l' if $left;
Branch: 1 branch
BranchTrueFalseTotal
if $left 3282 26240 29522
256 26240 ▶ return 'r' if $right;
Branch: 1 branch
BranchTrueFalseTotal
if $right 3283 22957 26240
257 22957 return 'cross';
258 }
259  
260 79 ▶sub _new_history {
Subroutine _new_history: called CC=1 SCAR=0.0
261 return Game::Terminal::Kit::History->new(
262 name => 'go',
263 version => $VERSION,
264 476 ▶ save => sub { $_[0]->to_text },
Subroutine __ANON__: called CC=1 SCAR=0.0
265 16 ▶ load => sub { Game::Go->from_text($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
266 79 );
267 }
268  
269 466 ▶sub _show {
Subroutine _show: called CC=1 SCAR=0.0
270 466 my ($self, %o) = @_;
271 466 my $game = $self->game;
272 466 $self->_say('', $self->board_text(%o));
273  
274 466 my $p = $game->prisoners;
275 $self->_say(sprintf(' captures: black %d, white %d komi %s',
276 466 $p->{$B}, $p->{$W}, $game->komi));
277 466 return;
278 }
279  
280  
281 43 ▶sub start {
Subroutine start: called CC=7 SCAR=19.5
Pod documented
282 43 my ($self) = @_;
283 43 $self->history->start($self->game);
284  
285 43 $self->_intro;
286  
287 43 my $guard = 0;
288 43 ▶ while ($self->game->status eq 'active' && $guard++ < 4 * $self->game->size * $self->game->size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->game->status eq "active" and $guard++ < 4 * $self->game->size * $self->game->size) 643 2 645
Condition66%2/3
$self->game->status eq "active" and $guard++ < 4 * $self->game->size * $self->game->size
!ll&&!rl&&r
20643
MC/DC50%1/2
$self->game->status eq "active" and $guard++ < 4 * $self->game->size * $self->game->size
$self->game->status eq "active" $guard++ < 4 * $self->game->size * $self->game->size
Truth table66%2/3
A and B
A= $self->game->status eq "active"B= $guard++ < 4 * $self->game->size * $self->game->size
ABresult
0X0
100
111
289 643 my ($who) = $self->game->waiting_on;
290 643 ▶ last unless defined $who;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $who 0 643 643
291  
292 643 my $ok;
293 643 ▶ if ($who == $self->_human) {
Branch: 1 branch
BranchTrueFalseTotal
if ($who == $self->_human) { } 347 296 643
294 347 $self->person_turn;
295 347 $ok = $self->_human_turn($who);
296 }
297 else {
298 296 $ok = $self->_bot_turn($who);
299 }
300 643 ▶ last unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 41 602 643
301 }
302  
303 43 $self->_finish;
304 43 ▶ return $self->game->outcome || $self->game->result;
Condition66%2/3
$self->game->outcome || $self->game->result
l!l&&r!l&&!r
2410
MC/DC0%0/2
$self->game->outcome || $self->game->result
$self->game->outcome $self->game->result
Truth table66%2/3
A || B
A= $self->game->outcomeB= $self->game->result
ABresult
1X1
011
000
305 }
306  
307 347 ▶sub person_turn {
Subroutine person_turn: called CC=1 SCAR=0.0
Pod documented
308 347 my ($self) = @_;
309 347 $self->history->turn($self->game);
310 347 return $self;
311 }
312  
313 12 ▶sub take_back {
Subroutine take_back: called CC=2 SCAR=6.9
Pod documented
314 12 my ($self) = @_;
315 12 my $game = $self->history->undo;
316 12 ▶ return 0 unless $game;
Branch: 1 branch
BranchTrueFalseTotal
unless $game 3 9 12
317 9 $self->swap($game);
318 9 return 1;
319 }
320  
321 5 ▶sub play_again {
Subroutine play_again: called CC=2 SCAR=6.9
Pod documented
322 5 my ($self) = @_;
323 5 my $game = $self->history->redo;
324 5 ▶ return 0 unless $game;
Branch: 1 branch
BranchTrueFalseTotal
unless $game 3 2 5
325 2 $self->swap($game);
326 2 return 1;
327 }
328  
329 16 ▶sub swap {
Subroutine swap: called CC=1 SCAR=0.0
Pod documented
330 16 my ($self, $game) = @_;
331 16 $self->game($game);
332 16 $self->_shown(0);
333 16 return $self;
334 }
335  
336 809 ▶sub _history_word {
Subroutine _history_word: called CC=6 SCAR=17.9
337 809 my ($self, $line) = @_;
338 809 ▶ if ($line =~ /\Aundo\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Aundo\z/i) 7 802 809
339 7 ▶ return 1 if $self->take_back;
Branch: 1 branch
BranchTrueFalseTotal
if $self->take_back 6 1 7
340 1 $self->_say(' There is nothing to take back.');
341 1 return 0;
342 }
343 802 ▶ if ($line =~ /\Aredo\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Aredo\z/i) 2 800 802
344 2 ▶ return 1 if $self->play_again;
Branch: 1 branch
BranchTrueFalseTotal
if $self->play_again 1 1 2
345 1 $self->_say(' There is nothing to play again.');
346 1 return 0;
347 }
348 800 ▶ if (my (undef, $file) = Game::Terminal::Kit::Save::command($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(undef, $file) = Game::Terminal::Kit::Save::command($line)) 11 789 800
349 11 $self->_say(' ' . $self->save($file));
350 11 return 0;
351 }
352 789 return undef;
353 }
354  
355 43 ▶sub _intro {
Subroutine _intro: called CC=2 SCAR=7.0
356 43 my ($self) = @_;
357 43 my $game = $self->game;
358 43 ▶ $self->_say(
Branch: 1 branch
BranchTrueFalseTotal
$game->handicap ? : 0 43 43
359 sprintf('Go, %dx%d, komi %s%s.', $game->size, $game->size, $game->komi,
360 $game->handicap ? sprintf(', handicap %d', $game->handicap) : ''),
361 sprintf('You are %s; the bot is level %d.',
362 Game::Go::Rules::colour_name($self->_human), $self->bot->level),
363 'Enter a point such as D4, or: pass, resign, board, libs D4, help.',
364 );
365 43 return;
366 }
367  
368 849 ▶sub _prompt {
Subroutine _prompt: called CC=5 SCAR=16.3
369 849 my ($self, $text) = @_;
370 849 my $out = $self->out;
371 849 ▶ print {$out} $text unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 849 0 849
372 849 ▶ my $in = $self->in or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $in = $self->in or return undef 849 0 849
373 849 my $line = <$in>;
374 849 ▶ return undef unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 11 838 849
375  
376 838 ▶ print {$out} "\n" unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 838 0 838
377  
378 838 chomp $line;
379 838 return $line;
380 }
381  
382 0 ▶sub raw {
Subroutine raw: not called CC=1 SCAR=6.9
Pod documented
383 0 my ($self) = @_;
384 0 return $self->keyboard->raw;
385 }
386  
387 188 ▶sub keys_available {
Subroutine keys_available: called CC=3 SCAR=11.4
Pod documented
388 188 my ($self) = @_;
389 188 ▶ return 0 unless $self->in || $self->keyboard->keysource;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in or $self->keyboard->keysource 0 188 188
Condition66%2/3
$self->in or $self->keyboard->keysource
l!l&&r!l&&!r
18710
MC/DC0%0/2
$self->in or $self->keyboard->keysource
$self->in $self->keyboard->keysource
Truth table66%2/3
A or B
A= $self->inB= $self->keyboard->keysource
ABresult
1X1
011
000
390 188 return $self->keyboard->keys_available;
391 }
392  
393 342 ▶sub picking {
Subroutine picking: called CC=6 SCAR=18.1
Pod documented
394 342 my ($self, @set) = @_;
395 342 ▶ $self->_picking($set[0] ? 1 : 0) if @set;
Branch: 2 branches
BranchTrueFalseTotal
if @set 1 341 342
$set[0] ? : 0 1 1
396 342 ▶ return 0 if $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $self->quiet 0 342 342
397 342 ▶ return $self->_picking ? 1 : 0 if defined $self->_picking;
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->_picking 187 155 342
$self->_picking ? : 18 169 187
398 155 return $self->keys_available;
399 }
400  
401 32 ▶sub enter_raw {
Subroutine enter_raw: called CC=3 SCAR=11.1
Pod documented
402 32 my ($self) = @_;
403 32 ▶ return undef unless $self->keys_available;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keys_available 1 31 32
404 31 ▶ return $self->keyboard->enter_raw ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->keyboard->enter_raw ? : 31 0 31
405 }
406  
407 7 ▶sub leave_raw {
Subroutine leave_raw: called CC=1 SCAR=0.0
Pod documented
408 7 my ($self) = @_;
409 7 $self->keyboard->leave_raw;
410 7 return $self;
411 }
412  
413 111 ▶sub read_key {
Subroutine read_key: called CC=1 SCAR=0.0
Pod documented
414 111 my ($self) = @_;
415 111 return $self->keyboard->read_key;
416 }
417  
418 97 ▶sub preview {
Subroutine preview: called CC=4 SCAR=13.9
Pod documented
419 97 my ($self, $who, $pt) = @_;
420  
421 97 my $game = $self->game;
422 97 my ($col, $row) = $game->col_row($pt);
423 97 my $at = $game->board->at($col, $row);
424  
425 97 ▶ return { refused => 'there is a stone there' }
Branch: 1 branch
BranchTrueFalseTotal
if $at != 0 11 86 97
426 if $at != Game::Go::Rules::EMPTY;
427  
428 86 my $trial = $game->clone;
429 86 my $move = $trial->play($who, $pt);
430 86 ▶ return { refused => $move->message } if ref $move eq 'Game::Go::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $move eq "Game::Go::Error" 1 85 86
431  
432 return {
433 move => $move,
434 85 ▶ caps => scalar @{ $move->caps || [] },
Condition50%1/2
$move->caps || []
l!l
850
MC/DC0%0/1
$move->caps || []
$move->caps
Truth table50%1/2
A
A= $move->caps
Aresult
11
00
435 libs => $trial->board->libs($col, $row),
436 size => $trial->board->chain_size($col, $row),
437 };
438 }
439  
440 97 ▶sub point_line {
Subroutine point_line: called CC=5 SCAR=16.1
Pod documented
441 97 my ($self, $who, $pt) = @_;
442  
443 97 my $game = $self->game;
444 97 my $name = Game::Go::Notation::to_human($game->size, $game->col_row($pt));
445 97 my $peek = $self->preview($who, $pt);
446  
447 97 ▶ return "$name: " . $peek->{refused} if $peek->{refused};
Branch: 1 branch
BranchTrueFalseTotal
if $peek->{"refused"} 12 85 97
448  
449 85 my $line = "$name: ";
450 85 ▶ $line .= sprintf 'takes %d, ', $peek->{caps} if $peek->{caps};
Branch: 1 branch
BranchTrueFalseTotal
if $peek->{"caps"} 1 84 85
451 $line .= $peek->{size} == 1
452 ? sprintf('a lone stone with %d liberties', $peek->{libs})
453 : sprintf('joins a group of %d with %d liberties',
454 85 ▶ $peek->{size}, $peek->{libs});
Branch: 1 branch
BranchTrueFalseTotal
$peek->{'size'} == 1 ? : 84 1 85
455 85 ▶ $line .= $self->_ink('1;31', ' (atari)') if $peek->{libs} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $peek->{"libs"} == 1 0 85 85
456  
457 85 return $line;
458 }
459  
460 0 ▶sub interactive {
Subroutine interactive: not called CC=3 SCAR=24.8
Pod documented
461 0 my ($self) = @_;
462 0 ▶ return 0 unless $self->out;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out 0 0 0
463 0 ▶ return $self->screen->interactive ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->screen->interactive ? : 0 0 0
464 }
465  
466 92 ▶sub clear {
Subroutine clear: called CC=2 SCAR=7.0
Pod documented
467 92 my ($self) = @_;
468 92 ▶ return $self unless $self->out;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out 0 92 92
469 92 $self->screen->clear(scrollback => 1);
470 92 return $self;
471 }
472  
473 31 ▶sub pick_point {
Subroutine pick_point: called CC=24 SCAR=32.4
Pod documented
474 31 my ($self, $who) = @_;
475  
476 31 my $game = $self->game;
477 31 my $size = $game->size;
478 31 my $at = $self->_last_point;
479 31 ▶ $at = $game->point(int($size / 2), int($size / 2)) unless defined $at;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $at 24 7 31
480  
481 31 my ($col, $row) = $game->col_row($at);
482 31 my @notice;
483  
484 31 while (1) {
485 92 my $pt = $game->point($col, $row);
486 92 $self->clear;
487 92 $self->_show($self->_since, cursor => $pt, to_play => $who);
488 92 $self->_say(' ' . $self->point_line($who, $pt));
489 92 $self->_say(' ' . $self->_ink('2', $_)) for @notice;
490 92 @notice = ();
491 92 ▶ $self->_say(' ' . $self->_ink('2',
Branch: 1 branch
BranchTrueFalseTotal
length $self->history->legend ? : 12 80 92
492 join(', ', 'arrows to move', 'enter to play', 'p pass',
493 (length $self->history->legend ? $self->history->legend : ()),
494 'S save', '? for the keys')));
495  
496 92 my $key = $self->read_key;
497 92 ▶ return 0 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 92 92
Condition33%2/6
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
0092
not defined $key or $key eq "eof"
l!l&&r!l&&!r
0092
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
498  
499 92 ▶ if (my ($dx, $dy) = Game::Terminal::Kit::Steer::way($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = Game::Terminal::Kit::Steer::way($key)) 50 42 92
500 50 $col = Game::Terminal::Kit::Steer::ring($size, $col, $dx);
501 50 $row = Game::Terminal::Kit::Steer::ring($size, $row, $dy);
502 50 next;
503 }
504 42 ▶ if ($key eq 'home') { $col = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "home") 2 40 42
505 40 ▶ if ($key eq 'end') { $col = $size - 1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "end") 2 38 40
506  
507 38 ▶ if ($key eq 'enter' || $key eq ' ') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "enter" or $key eq " ") 6 32 38
Condition66%2/3
$key eq "enter" or $key eq " "
l!l&&r!l&&!r
6032
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
508 6 my $move = $game->play($who, $pt);
509 6 ▶ if (ref $move eq 'Game::Go::Error') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $move eq "Game::Go::Error") 0 6 6
510 0 @notice = ($move->message);
511 0 next;
512 }
513 6 $self->_say(sprintf(' you play %s%s.',
514 Game::Go::Notation::to_human($size, $col, $row),
515 $self->_took($move)));
516 6 return 1;
517 }
518  
519 32 ▶ if ($key eq 'p') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "p") 1 31 32
520 1 my $out = $game->pass($who);
521 1 ▶ return $self->_refused($out) if ref $out eq 'Game::Go::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $out eq "Game::Go::Error" 0 1 1
522 1 $self->_say(' you pass.');
523 1 return 1;
524 }
525  
526 31 ▶ if ($key eq 'u') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "u") 5 26 31
527 5 ▶ return 1 if $self->take_back;
Branch: 1 branch
BranchTrueFalseTotal
if $self->take_back 3 2 5
528 2 @notice = ('there is nothing to take back');
529 2 next;
530 }
531 26 ▶ if ($key eq 'r') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "r") 3 23 26
532 3 ▶ return 1 if $self->play_again;
Branch: 1 branch
BranchTrueFalseTotal
if $self->play_again 1 2 3
533 2 @notice = ('there is nothing to play again');
534 2 next;
535 }
536 23 ▶ if ($key eq 'q') { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "q") 20 3 23
537  
538 3 ▶ if ($key eq 'S') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "S") 1 2 3
539 1 my $file = Game::Terminal::Kit::Save::ask_file($self->keyboard, $self->screen,
540 default => $self->save_default,
541 head => [ '', $self->board_text($self->_since, to_play => $who), '' ]);
542 1 ▶ @notice = ($self->save($file)) if defined $file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 1 0 1
543 1 next;
544 }
545  
546 2 ▶ if ($key eq 't') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "t") 0 2 2
547 0 $self->picking(0);
548 0 $self->leave_raw;
549 0 return $self->_typed_turn($who);
550 }
551  
552 2 ▶ if ($key eq '?') { @notice = $self->pick_help; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "?") 1 1 2
553  
554 1 @notice = ('that key does nothing here. ? for the ones that do');
555 }
556 }
557  
558 1 ▶sub pick_help {
Subroutine pick_help: called CC=1 SCAR=0.0
Pod documented
559 return (
560 1 'arrows move the cursor, enter plays the point it is on.',
561 'the line under the board says what that move would do.',
562 'p passes, u takes your last turn back, r plays it again,',
563 'S saves the game, to carry on with --resume or watch with --replay,',
564 't goes back to typing, where resign gives up, q stops.',
565 );
566 }
567  
568 347 ▶sub _human_turn {
Subroutine _human_turn: called CC=4 SCAR=13.9
569 347 my ($self, $who) = @_;
570 347 my $game = $self->game;
571  
572 347 ▶ return $self->_human_marking($who) if $game->phase eq 'marking';
Branch: 1 branch
BranchTrueFalseTotal
if $game->phase eq "marking" 7 340 347
573  
574 340 ▶ if ($self->picking) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->picking) 18 322 340
575 18 ▶ return $self->pick_point($who) if $self->enter_raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->enter_raw 17 1 18
576 1 $self->picking(0);
577 }
578  
579 323 return $self->_typed_turn($who);
580 }
581  
582 323 ▶sub _typed_turn {
Subroutine _typed_turn: called CC=13 SCAR=25.7
583 323 my ($self, $who) = @_;
584 323 my $game = $self->game;
585  
586 323 $self->_show($self->_since);
587  
588 323 while (1) {
589 343 my $line = $self->_prompt('your move> ');
590 343 ▶ return 0 unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 9 334 343
591 334 $line =~ s/\A\s+|\s+\z//g;
592 334 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 334 334
593  
594 334 ▶ if ($line =~ /\Ahelp\z/i) { $self->_help; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Ahelp\z/i) 2 332 334
595 332 ▶ if ($line =~ /\Aboard\z/i) { $self->_show($self->_since); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Aboard\z/i) 1 331 332
596 331 ▶ if ($line =~ /\Alibs\s+(\S+)\z/i) { $self->_libs($1); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Alibs\s+(\S+)\z/i) 2 329 331
597 329 ▶ if ($line =~ /\A(?:resign|quit)\z/i) { $game->resign($who); return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A(?:resign|quit)\z/i) 22 307 329
598 307 ▶ if (defined(my $moved = $self->_history_word($line))) { return 1 if $moved; next }
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $moved = $self->_history_word($line))) 18 289 307
if $moved 5 13 18
599  
600 289 ▶ if ($line =~ /\Apass\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Apass\z/i) 262 27 289
601 262 my $out = $game->pass($who);
602 262 ▶ return $self->_refused($out) if ref $out eq 'Game::Go::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $out eq "Game::Go::Error" 0 262 262
603 262 $self->_say(' you pass.');
604 262 return 1;
605 }
606  
607 27 my ($col, $row) = Game::Go::Notation::from_human($game->size, $line);
608 27 ▶ unless (defined $col) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $col) 1 26 27
609 1 $self->_say(" '$line' is not a point on this board. Try D4, or help.");
610 1 next;
611 }
612  
613 26 my $move = $game->play($who, $game->point($col, $row));
614 26 ▶ if (ref $move eq 'Game::Go::Error') { $self->_say(' ' . $move->message); next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $move eq "Game::Go::Error") 1 25 26
615  
616 25 $self->_say(sprintf(' you play %s%s.', uc $line, $self->_took($move)));
617 25 return 1;
618 }
619 }
620  
621 296 ▶sub _bot_turn {
Subroutine _bot_turn: called CC=10 SCAR=24.6
622 296 my ($self, $who) = @_;
623 296 my $game = $self->game;
624  
625 296 my $move = $self->bot->choose($game, $who);
626 0 ▶ unless ($move) { $self->_say(' the bot has nothing to play.'); return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($move) 0 296 296
627  
628 296 my $name = Game::Go::Rules::colour_name($who);
629  
630 296 ▶ if ($move->kind eq 'pass') {
Branch: 1 branch
BranchTrueFalseTotal
if ($move->kind eq "pass") 6 290 296
631 6 $game->pass($who);
632 6 $self->_say(" $name passes.");
633 6 return 1;
634 }
635 290 ▶ if ($move->kind eq 'play') {
Branch: 1 branch
BranchTrueFalseTotal
if ($move->kind eq "play") 288 2 290
636 288 my $out = $game->play($who, $move->point);
637 288 ▶ return $self->_refused($out) if ref $out eq 'Game::Go::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $out eq "Game::Go::Error" 0 288 288
638 288 my ($col, $row) = $game->col_row($move->point);
639 288 $self->_say(sprintf(' %s plays %s%s.', $name,
640 Game::Go::Notation::to_human($game->size, $col, $row), $self->_took($out)));
641 288 return 1;
642 }
643  
644 2 ▶ my $answer =
Branch: 4 branches
BranchTrueFalseTotal
$move->kind eq 'mark' ? : 0 2 2
$move->kind eq 'done' ? : 0 2 2
$move->kind eq 'accept' ? : 2 0 2
$move->kind eq 'dispute' ? : 0 0 0
645 $move->kind eq 'mark' ? $game->mark($who, $move->point)
646 : $move->kind eq 'done' ? $game->done($who)
647 : $move->kind eq 'accept' ? $game->accept($who)
648 : $move->kind eq 'dispute' ? $game->dispute($who)
649 : undef;
650 2 ▶ return $self->_refused($answer) if ref $answer eq 'Game::Go::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $answer eq "Game::Go::Error" 0 2 2
651  
652 2 $self->_say(" $name: " . $self->_marking_words($move->kind));
653 2 return 1;
654 }
655  
656 319 ▶sub _took {
Subroutine _took: called CC=3 SCAR=17.3
657 319 my ($self, $move) = @_;
658 319 ▶ return '' unless ref $move eq 'Game::Go::Move' && $move->captured;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $move eq "Game::Go::Move" and $move->captured 319 0 319
Condition33%1/3
ref $move eq "Game::Go::Move" and $move->captured
!ll&&!rl&&r
03190
MC/DC0%0/2
ref $move eq "Game::Go::Move" and $move->captured
ref $move eq "Game::Go::Move" $move->captured
Truth table33%1/3
A and B
A= ref $move eq "Game::Go::Move"B= $move->captured
ABresult
0X0
100
111
659 0 my $game = $self->game;
660 my @names = map {
661 0 Game::Go::Notation::to_human($game->size, $game->col_row($_))
662 0 } @{ $move->caps };
663 0 return sprintf(', taking %s', join ' ', @names);
664 }
665  
666 501 ▶sub _last_point {
Subroutine _last_point: called CC=3 SCAR=11.0
667 501 my ($self) = @_;
668 501 for my $e (reverse @{ $self->game->log }) {
669 585 ▶ return $e->{payload}{pt} if $e->{kind} eq 'play';
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"kind"} eq "play" 353 232 585
670 }
671 148 return undef;
672 }
673  
674 470 ▶sub _last_took {
Subroutine _last_took: called CC=4 SCAR=13.9
675 470 my ($self) = @_;
676 470 for my $e (reverse @{ $self->game->log }) {
677 554 ▶ return $e->{payload}{caps} || [] if $e->{kind} eq 'play';
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"kind"} eq "play" 346 208 554
Condition50%1/2
$e->{'payload'}{'caps'} || []
l!l
3460
MC/DC0%0/1
$e->{'payload'}{'caps'} || []
$e->{'payload'}{'caps'}
Truth table50%1/2
A
A= $e->{'payload'}{'caps'}
Aresult
11
00
678 }
679 124 return [];
680 }
681  
682 470 ▶sub _since {
Subroutine _since: called CC=1 SCAR=0.0
683 470 my ($self) = @_;
684 470 return (last => $self->_last_point, took => $self->_last_took);
685 }
686  
687 0 ▶sub _refused {
Subroutine _refused: not called CC=2 SCAR=17.9
688 0 my ($self, $out) = @_;
689 0 ▶ $self->_say(' ' . $out->message) if ref $out eq 'Game::Go::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $out eq "Game::Go::Error" 0 0 0
690 0 return 0;
691 }
692  
693 2 ▶sub _libs {
Subroutine _libs: called CC=3 SCAR=11.1
694 2 my ($self, $name) = @_;
695 2 my $game = $self->game;
696 2 my ($col, $row) = Game::Go::Notation::from_human($game->size, $name);
697 0 ▶ unless (defined $col) { $self->_say(" '$name' is not a point."); return }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $col) 0 2 2
698  
699 2 my $board = $game->board;
700 2 my $at = $board->at($col, $row);
701 2 ▶ if ($at == Game::Go::Rules::EMPTY) { $self->_say(' ' . uc($name) . ' is empty.'); return }
Branch: 1 branch
BranchTrueFalseTotal
if ($at == 0) 1 1 2
702  
703 1 $self->_say(sprintf(' %s is a %s group of %d, with %d liberties.',
704 uc $name, Game::Go::Rules::colour_name($at),
705 $board->chain_size($col, $row), $board->libs($col, $row)));
706 1 return;
707 }
708  
709 2 ▶sub _help {
Subroutine _help: called CC=1 SCAR=0.0
710 2 my ($self) = @_;
711 2 $self->_say(
712 '',
713 ' D4 play there. Columns are A to T with I left out,',
714 ' and rows are numbered from the bottom.',
715 ' pass pass. Two passes in a row stop play.',
716 ' board draw the board again.',
717 ' libs D4 how many liberties that group has.',
718 " undo take your last turn back, and the bot's reply with it.",
719 ' redo play a turn taken back again.',
720 ' save save the game to carry on with --resume; save FILE',
721 ' saves it to that file.',
722 ' resign give up.',
723 '',
724 );
725 2 return;
726 }
727  
728 2 ▶sub _marking_words {
Subroutine _marking_words: called CC=6 SCAR=22.8
729 2 my ($self, $kind) = @_;
730 2 ▶ return 'marks a group as dead' if $kind eq 'mark';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "mark" 0 2 2
731 2 ▶ return 'unmarks a group' if $kind eq 'unmark';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "unmark" 0 2 2
732 2 ▶ return 'offers that as the count' if $kind eq 'done';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "done" 0 2 2
733 2 ▶ return 'agrees, and the game is over' if $kind eq 'accept';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "accept" 2 0 2
734 0 ▶ return 'disagrees, so play resumes' if $kind eq 'dispute';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "dispute" 0 0 0
735 0 return $kind;
736 }
737  
738 7 ▶sub _human_marking {
Subroutine _human_marking: called CC=17 SCAR=33.8
739 7 my ($self, $who) = @_;
740 7 my $game = $self->game;
741 7 my $m = $game->marking;
742  
743 7 $self->leave_raw;
744  
745 7 ▶ unless ($self->_shown) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_shown) 7 0 7
746 7 $self->_say(
747 '',
748 ' Both players passed, so play has STOPPED. The game is not over yet:',
749 ' before it can be counted you have to agree which stones are dead.',
750 );
751 7 $self->_shown(1);
752 }
753  
754 7 $self->_show($self->_since);
755  
756 7 ▶ if (!$m->proposed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($m->proposed) 6 1 7
757 6 $self->_say(
758 sprintf(' It is your count to offer. Marked dead so far: %s.',
759 $self->_dead_words),
760 ' Type a point to mark that group dead, or "done" to offer the count.',
761 ' "undo" takes your last turn back.',
762 );
763 6 while (1) {
764 505 my $line = $self->_prompt('mark> ');
765 505 ▶ return 0 unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 2 503 505
766 503 $line =~ s/\A\s+|\s+\z//g;
767 503 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 503 503
768 503 ▶ if ($line =~ /\Adone\z/i) { $game->done($who); return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Adone\z/i) 2 501 503
769 0 ▶ if ($line =~ /\Aboard\z/i) { $self->_show($self->_since); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Aboard\z/i) 0 501 501
770 0 ▶ if (defined(my $moved = $self->_history_word($line))) { return 1 if $moved; next }
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $moved = $self->_history_word($line))) 2 499 501
if $moved 2 0 2
771  
772 499 my ($col, $row) = Game::Go::Notation::from_human($game->size, $line);
773 499 ▶ unless (defined $col) { $self->_say(" '$line' is not a point."); next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $col) 499 0 499
774 0 my $out = $game->mark($who, $game->point($col, $row));
775 0 ▶ if (ref $out eq 'Game::Go::Error') { $self->_say(' ' . $out->message); next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $out eq "Game::Go::Error") 0 0 0
776 0 $self->_say(sprintf(' %s: %s', uc $line, $self->_marking_words($out->kind)));
777 0 $self->_say(' Marked dead: ' . $self->_dead_words);
778 }
779 }
780  
781 $self->_say(
782 1 sprintf(' The bot offers this count. Marked dead: %s.', $self->_dead_words),
783 ' Type "accept" to agree and finish, or "dispute" to put it back on the',
784 ' board and play it out. Disputing costs you the move: your opponent',
785 ' plays first. "undo" takes your last turn back.',
786 );
787 1 while (1) {
788 1 my $line = $self->_prompt('accept or dispute> ');
789 1 ▶ return 0 unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 1 1
790 1 $line =~ s/\A\s+|\s+\z//g;
791 0 ▶ if ($line =~ /\Aaccept\z/i) { $game->accept($who); return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Aaccept\z/i) 0 1 1
792 0 ▶ if (defined(my $moved = $self->_history_word($line))) { return 1 if $moved; next }
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $moved = $self->_history_word($line))) 0 1 1
if $moved 0 0 0
793 1 ▶ if ($line =~ /\Adispute\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Adispute\z/i) 1 0 1
794 1 my $out = $game->dispute($who);
795 0 ▶ if (ref $out eq 'Game::Go::Error') { $self->_say(' ' . $out->message); next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $out eq "Game::Go::Error") 0 1 1
796 1 $self->_shown(0);
797 1 $self->_say(' Back to the board, and your opponent has the move.');
798 1 return 1;
799 }
800 0 $self->_say(' "accept", "dispute" or "undo".');
801 }
802 }
803  
804 7 ▶sub _dead_words {
Subroutine _dead_words: called CC=3 SCAR=12.0
805 7 my ($self) = @_;
806 7 my $game = $self->game;
807 7 ▶ my $m = $game->marking or return 'nothing';
Branch: 1 branch
BranchTrueFalseTotal
my $m = $game->marking or return "nothing" 7 0 7
808 7 my @points = @{ $m->dead_points };
809 7 ▶ return 'nothing' unless @points;
Branch: 1 branch
BranchTrueFalseTotal
unless @points 7 0 7
810 return join ' ', map {
811 0 Game::Go::Notation::to_human($game->size, $game->col_row($_))
812 } @points;
813 }
814  
815  
816 43 ▶sub _finish {
Subroutine _finish: called CC=10 SCAR=23.9
817 43 my ($self) = @_;
818 43 my $game = $self->game;
819 43 $self->_show($self->_since);
820  
821 43 my $r = $game->outcome;
822 43 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 41 2 43
823 41 ▶ $self->_say('', ' ' . ($game->result || 'unfinished') . '.');
Condition100%2/2
$game->result || 'unfinished'
l!l
2219
MC/DC100%1/1
$game->result || 'unfinished'
$game->result
Truth table100%2/2
A
A= $game->result
Aresult
11
00
824 41 return;
825 }
826  
827 2 my $t = $r->territory;
828 2 my $p = $r->prisoners;
829 $self->_say(
830 '',
831 sprintf(' black %3d territory -%3d prisoners%s = %s',
832 $t->{$B} // 0, $p->{$W} // 0, ' ' x 12, $r->scores->{$B}),
833 sprintf(' white %3d territory -%3d prisoners + %s komi = %s',
834 2 ▶ $t->{$W} // 0, $p->{$B} // 0, $r->komi, $r->scores->{$W}),
Condition50%4/8
$t->{$B} // 0
l!l
20
$p->{$W} // 0
l!l
20
$t->{$W} // 0
l!l
20
$p->{$B} // 0
l!l
20
MC/DC0%0/1
$t->{$B} // 0
$t->{$B}
MC/DC0%0/1
$p->{$W} // 0
$p->{$W}
MC/DC0%0/1
$t->{$W} // 0
$t->{$W}
MC/DC0%0/1
$p->{$B} // 0
$p->{$B}
Truth table50%1/2
A
A= $t->{$B}
Aresult
11
00
Truth table50%1/2
A
A= $p->{$W}
Aresult
11
00
Truth table50%1/2
A
A= $t->{$W}
Aresult
11
00
Truth table50%1/2
A
A= $p->{$B}
Aresult
11
00
835 '',
836 ' ' . $r->stringify . '.',
837 );
838  
839 2 ▶ $self->_say(' The count was not agreed, so it was scored by area.')
Branch: 1 branch
BranchTrueFalseTotal
if ($r->scored_by || "") eq "area" 0 2 2
Condition50%1/2
$r->scored_by || ''
l!l
20
MC/DC0%0/1
$r->scored_by || ''
$r->scored_by
Truth table50%1/2
A
A= $r->scored_by
Aresult
11
00
840 if ($r->scored_by || '') eq 'area';
841  
842 $self->_say(' A negative score means the game was long past resigning.')
843 2 ▶ if grep { $_ < 0 } values %{ $r->scores };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ < 0;} values %{$r->scores;} 0 2 2
844  
845 2 return;
846 }
847  
848 13 ▶sub _usage {
Subroutine _usage: called CC=1 SCAR=0.0
849 13 return <<'USAGE';
850 go - play Go against the bot
851  
852 go [options]
853  
854 --size N 9, 13 or 19 (default 9)
855 --level N 1 to 5 (default 2)
856 --colour C black or white (default black)
857 --komi N a multiple of 0.5 (default 6.5, or 0.5 with a handicap)
858 --handicap N 2 to 9 on 19x19, 2 to 5 on the smaller boards
859 --seed S the seed the bot plays from
860 --ascii X and O rather than stones
861 --no-pick type the points out instead of pointing at them
862 --save FILE where S, or "save", writes the game: FILE, else the file
863 it was resumed from, else go.save
864 --resume FILE carry on a saved game, with its undo and redo
865 --replay FILE watch a saved game a turn at a time; enter plays on
866 --help
867  
868 Columns are A to T with I left out, and rows are numbered from the bottom, so
869 the bottom left point is A1. Two passes STOP play; the game is not over until
870 both players have agreed which stones are dead.
871  
872 On a terminal the arrow keys walk a cursor over the board and the point under
873 it is bracketed, showing the stone you would play there. The line under the
874 board says what that move would do: what it takes, how many liberties it
875 would have, or why it cannot be played. Enter plays it, p passes, u takes your
876 last turn back with the bot's reply, r plays it again, S saves the game, t
877 goes back to typing (where resign gives up) and ? lists the keys. Needs
878 Term::ReadKey; without it, or off a terminal, the points are typed, and undo,
879 redo and save are typed too.
880  
881 The last move is a ringed stone and a point a capture has just emptied is an
882 x, so both are visible with --ascii and with colour off.
883  
884 Exit status is 0 for a win, 1 for a loss, 2 for a bad option.
885 USAGE
886 }
887  
888 12 ▶sub settings {
Subroutine settings: called CC=2 SCAR=7.2
Pod documented
889 12 my ($self) = @_;
890 return {
891 12 ▶ size => $self->size, level => $self->level, colour => $self->colour,
Branch: 1 branch
BranchTrueFalseTotal
defined $self->komi ? : 0 12 12
892 handicap => $self->handicap, seed => $self->seed,
893 (defined $self->komi ? (komi => $self->komi) : ()),
894 };
895 }
896  
897 7 ▶sub save_default {
Subroutine save_default: called CC=2 SCAR=7.1
Pod documented
898 7 my ($self) = @_;
899 7 my $file = $self->history->file;
900 7 ▶ return defined $file ? $file : Game::Terminal::Kit::Save::default_file('go');
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 7 0 7
901 }
902  
903 12 ▶sub save {
Subroutine save: called CC=4 SCAR=13.9
Pod documented
904 12 my ($self, $file) = @_;
905 12 ▶ $file = $self->save_default unless defined $file && length $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and length $file 6 6 12
Condition66%2/3
defined $file and length $file
!ll&&!rl&&r
606
MC/DC50%1/2
defined $file and length $file
defined $file length $file
Truth table66%2/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
906 12 my $history = $self->history;
907 12 $history->settings($self->settings);
908 12 $history->version($VERSION);
909 12 my $path = eval { $history->saved($self->game)->write_file($file) };
910 12 ▶ return 'the game was not saved: ' . Game::Terminal::Kit::Save::why($@) . '.' unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 12 12
911 12 $history->file($path);
912 12 return "the game is saved to $path.";
913 }
914  
915 9 ▶sub read_save {
Subroutine read_save: called CC=1 SCAR=0.0
Pod documented
916 9 my ($class, $file) = @_;
917 9 return Game::Terminal::Kit::Save->read_game($file, 'go');
918 }
919  
920 3 ▶sub replay_lines {
Subroutine replay_lines: called CC=2 SCAR=6.9
Pod documented
921 3 my ($self, $game) = @_;
922 3 my $was = $self->game;
923 3 $self->game($game);
924 3 my @lines = eval {
925 3 my $p = $game->prisoners;
926 ($self->board_text($self->_since),
927 3 sprintf(' captures: black %d, white %d komi %s', $p->{$B}, $p->{$W}, $game->komi));
928 };
929 3 my $died = $@;
930 3 $self->game($was);
931 3 ▶ die $died unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 3 3
932 3 return @lines;
933 }
934  
935 2 ▶sub options {
Subroutine options: called CC=1 SCAR=0.0
Pod documented
936 return [
937 2 { name => 'size', type => 'enum', choices => [qw(9 13 19)], help => 'the board' },
938 { name => 'level', type => 'int', min => 1, max => 5, help => 'how hard the program plays' },
939 { name => 'colour', type => 'enum', choices => [qw(black white)], help => 'your stones' },
940 { name => 'handicap', type => 'int', min => 2, max => 9, help => 'stones for black; 2 to 5 on the smaller boards' },
941 { name => 'komi', type => 'str', help => 'a multiple of 0.5; 6.5 by default' },
942 { name => 'seed', type => 'str', help => 'the seed the bot plays from' },
943 ];
944 }
945  
946 30 ▶sub run {
Subroutine run: called CC=28 SCAR=35.8
Pod documented
947 30 my ($class, @argv) = @_;
948 30 my %default = (
949 size => 9,
950 level => 2,
951 colour => 'black',
952 handicap => 0,
953 seed => 'terminal',
954 );
955 30 my %opt;
956  
957 30 my $ok = eval {
958 30 ▶ local $SIG{__WARN__} = sub { print STDERR "go: $_[0]" };
Subroutine __ANON__: called CC=1 SCAR=0.0
959 30 Getopt::Long::GetOptionsFromArray(\@argv, \%opt,
960 'size=i', 'level=i', 'colour|color=s', 'komi=s',
961 'handicap=i', 'seed=s', 'ascii', 'pick!', 'help|h',
962 Game::Terminal::Kit::Save::flags(),
963 );
964 };
965 30 ▶ if (!$ok) { print STDERR _usage(); return 2 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 29 30
966 29 ▶ if ($opt{help}) { print _usage(); return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"help"}) 12 17 29
967 0 ▶ if (@argv) { print STDERR "go: not an option: $argv[0]\n", _usage(); return 2 }
Branch: 1 branch
BranchTrueFalseTotal
if (@argv) 0 17 17
968 17 ▶ if (my $why = Game::Terminal::Kit::Save::check_flags(\%opt)) { print STDERR "go: $why.\n"; return 2 }
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = Game::Terminal::Kit::Save::check_flags(\%opt)) 2 15 17
969  
970 15 ▶ my $from = defined $opt{resume} ? $opt{resume} : $opt{replay};
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'resume'} ? : 6 9 15
971 15 my $save;
972 15 ▶ if (defined $from) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $from) 8 7 15
973 8 ($save, my $why) = $class->read_save($from);
974 8 ▶ unless ($save) { print STDERR "go: $why.\n"; return 2 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($save) 2 6 8
975 6 my $settings = $save->settings;
976 defined $opt{$_} or $opt{$_} = $settings->{$_}
977 6 ▶ for grep { defined $settings->{$_} } qw(size level colour komi handicap seed);
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{$_} or $opt{$_} = $settings->{$_} 1 29 30
978 }
979 13 ▶ defined $opt{$_} or $opt{$_} = $default{$_} for keys %default;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{$_} or $opt{$_} = $default{$_} 44 21 65
980  
981 13 my $terminal = eval {
982 $class->new(
983 in => \*STDIN,
984 out => \*STDOUT,
985 size => $opt{size},
986 level => $opt{level},
987 colour => $opt{colour},
988 (defined $opt{komi} ? (komi => $opt{komi}) : ()),
989 handicap => $opt{handicap},
990 seed => $opt{seed},
991 ascii => ($opt{ascii} ? 1 : 0),
992 (defined $opt{save} ? (save_file => $opt{save}) : ()),
993 13 ▶ (defined $opt{pick} ? (picking => $opt{pick} ? 1 : 0) : ()),
Branch: 5 branches
BranchTrueFalseTotal
defined $opt{'komi'} ? : 0 13 13
$opt{'ascii'} ? : 0 13 13
defined $opt{'save'} ? : 6 7 13
defined $opt{'pick'} ? : 0 13 13
$opt{'pick'} ? : 0 0 0
994 );
995 };
996 13 ▶ if (!$terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($terminal) 0 13 13
997 0 ▶ my $why = $@ || "could not start\n";
Condition0%0/2
$@ || "could not start\n"
l!l
00
MC/DC0%0/1
$@ || "could not start\n"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
998 0 $why =~ s/\AGame::Go::Terminal: //;
999 0 print STDERR "go: $why";
1000 0 return 2;
1001 }
1002  
1003 13 ▶ if (defined $opt{replay}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"replay"}) 1 12 13
1004 my $replay = Game::Terminal::Kit::Replay->new(
1005 save => $save,
1006 3 ▶ load => sub { Game::Go->from_text($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1007 3 ▶ draw => sub { $terminal->replay_lines($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1008 1 ▶ head => [ 'Go, a replay of ' . $save->file
Branch: 1 branch
BranchTrueFalseTotal
defined $save->saved_at ? : 1 0 1
1009 . (defined $save->saved_at ? ', saved ' . $save->saved_at : ''), '' ],
1010 screen => $terminal->screen,
1011 );
1012 my ($event, $step) = Game::Terminal::Kit::Run::guard(
1013 1 ▶ sub { $replay->play($terminal->keyboard, $terminal->screen) }, $terminal->keyboard, $terminal->screen);
Subroutine __ANON__: called CC=1 SCAR=0.0
1014 1 ▶ return 0 unless $event eq 'chosen';
Branch: 1 branch
BranchTrueFalseTotal
unless $event eq "chosen" 1 0 1
1015 0 $save = $save->from_step($step);
1016 }
1017 12 ▶ if ($save) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save) 5 7 12
1018 5 my $history = _new_history();
1019 5 my $game = eval { $history->resume($save) };
1020 5 ▶ unless ($game) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game) 0 5 5
1021 0 print STDERR "go: '" . $save->file . "' cannot be carried on: " . Game::Terminal::Kit::Save::why($@) . ".\n";
1022 0 return 2;
1023 }
1024 5 ▶ $history->file($opt{save}) if defined $opt{save};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt{"save"} 1 4 5
1025 5 $terminal->history($history);
1026 5 $terminal->swap($game);
1027 }
1028  
1029 Game::Terminal::Kit::Run::guard(
1030 12 ▶ sub { $terminal->start }, $terminal->keyboard, $terminal->screen,
Subroutine __ANON__: called CC=1 SCAR=0.0
1031 );
1032  
1033 12 my $game = $terminal->game;
1034 12 ▶ return 0 unless defined $game->winner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $game->winner 0 12 12
1035  
1036 12 ▶ my $human = lc($opt{colour}) =~ /\Aw/ ? Game::Go::WHITE : Game::Go::BLACK;
Branch: 1 branch
BranchTrueFalseTotal
lc($opt{'colour'}) =~ /\Aw/ ? : 0 12 12
1037 12 ▶ return $game->winner == $human ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$game->winner == $human ? : 0 12 12
1038 }
1039  
1040  
1041 23 1;
1042  
1043 __END__
« blib/lib/Game/Go/GTP.pm ↑ Summary blib/lib/Game/Go.pm »