Backgammon/Terminal.pm

filter: Statementstmt 93.6% 370 / 395 Branchbran 82.1% 179 / 218 Conditioncond 68.6% 57 / 83 MC/DCmcdc 52.0% 26 / 50 Subroutinesub 93.9% 62 / 66 Podpod 93.3% 14 / 15 totaltotal 85.6% 708 / 827 CC 150 SCAR 24.5
CC
150
Cov
87%
run
44.6
_pick_turn
24.6
BUILD
21.7
CRAP 11.6
« Backgammon/Notation.pm ↑ Summary Backgammon.pm »
1 package Game::Backgammon::Terminal;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Game::Backgammon;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Game::Backgammon::Board ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Game::Backgammon::Bot;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Game::Terminal::Kit::History;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Game::Terminal::Kit::Keys;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Game::Terminal::Kit::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Game::Terminal::Kit::Picker;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Game::Terminal::Kit::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Game::Terminal::Kit::Screen;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 our $VERSION = '0.04';
20  
21 5 my %CHECKER = (
22 white => { ascii => 'O', wide => "\x{25CB}", colour => '1;37', ink => '1;38;5;231' },
23 black => { ascii => 'X', wide => "\x{25CF}", colour => '1;36', ink => '1;38;5;16' },
24 );
25  
26 5 my %GROUND = (
27 light => '48;5;180',
28 dark => '48;5;94',
29 from => '48;5;136',
30 to => '48;5;28',
31 hit => '48;5;124',
32 played => '48;5;24',
33 );
34  
35 5 ▶use constant ROWS => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 has game => (
38 is => 'rw',
39 isa => Object
40 5 );
41  
42 has out => (
43 is => 'ro',
44 isa => Any,
45 4 ▶ default => sub { \*STDOUT }
Subroutine __ANON__: called CC=1 SCAR=0.0
46 5 );
47  
48 has in => (
49 is => 'ro',
50 isa => Any,
51 25 ▶ default => sub { \*STDIN }
Subroutine __ANON__: called CC=1 SCAR=0.0
52 5 );
53  
54 has mode => (
55 is => 'ro',
56 isa => Str,
57 default => 'bot'
58 5 );
59  
60 has level => (
61 is => 'ro',
62 isa => Int,
63 default => 3
64 5 );
65  
66 has seat => (
67 is => 'ro',
68 isa => Str,
69 default => 'white'
70 5 );
71  
72 has view => (
73 is => 'rw',
74 isa => Str,
75 default => ''
76 5 );
77  
78 has ascii => (
79 is => 'rw',
80 isa => Bool,
81 default => 0
82 5 );
83  
84 has [qw/colour interactive picking/] => (
85 is => 'rw'
86 5 );
87  
88 has [qw/keyboard screen log picker/] => (
89 is => 'rw'
90 5 );
91  
92 has highlight => (
93 is => 'rw',
94 isa => HashRef,
95 35 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
96 5 );
97  
98 has keysource => (
99 is => 'rw',
100 isa => CodeRef
101 5 );
102  
103 has pending => (
104 is => 'rw',
105 isa => ArrayRef,
106 35 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
107 5 );
108  
109 has history => (
110 is => 'rw'
111 5 );
112  
113 35 ▶sub BUILD {
Subroutine BUILD: called CC=18 SCAR=30.8
Pod undocumented
114 35 my ($self) = @_;
115 35 ▶ $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->interactive 10 25 35
-t $self->in ? : 0 10 10
116 35 ▶ $self->colour($self->interactive && !Game::Terminal::Kit::Screen::no_colour() ? 1 : 0)
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->colour 10 25 35
$self->interactive && !Game::Terminal::Kit::Screen::no_colour() ? : 0 10 10
Condition33%1/3
$self->interactive and not Game::Terminal::Kit::Screen::no_colour()
!ll&&!rl&&r
1000
MC/DC0%0/2
$self->interactive and not Game::Terminal::Kit::Screen::no_colour()
$self->interactive not Game::Terminal::Kit::Screen::no_colour()
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not Game::Terminal::Kit::Screen::no_colour()
ABresult
0X0
100
111
117 unless defined $self->colour;
118 35 ▶ $self->keyboard(Game::Terminal::Kit::Keys->new(
Branch: 2 branches
BranchTrueFalseTotal
unless $self->keyboard 35 0 35
$self->keysource ? : 20 15 35
119 in => $self->in,
120 pending => $self->pending,
121 ($self->keysource ? (keysource => $self->keysource) : ()),
122 )) unless $self->keyboard;
123 35 ▶ $self->screen(Game::Terminal::Kit::Screen->new(
Branch: 4 branches
BranchTrueFalseTotal
unless $self->screen 35 0 35
$self->interactive ? : 0 35 35
$self->colour ? : 1 34 35
$self->ascii ? : 24 11 35
124 out => $self->out,
125 interactive => $self->interactive ? 1 : 0,
126 colour => $self->colour ? 1 : 0,
127 ascii => $self->ascii ? 1 : 0,
128 )) unless $self->screen;
129 35 ▶ $self->log(Game::Terminal::Kit::Log->new) unless $self->log;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->log 35 0 35
130 35 ▶ $self->picker(Game::Terminal::Kit::Picker->new(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->picker 35 0 35
131 window => 0,
132 log => $self->log,
133 screen => $self->screen,
134 )) unless $self->picker;
135 $self->history(Game::Terminal::Kit::History->new(
136 140 ▶ save => sub { $_[0]->to_text },
Subroutine __ANON__: called CC=1 SCAR=0.0
137 11 ▶ load => sub { Game::Backgammon->from_text($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
138 35 ▶ )) unless $self->history;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->history 35 0 35
139 35 ▶ $self->picking($self->interactive ? 1 : 0) unless defined $self->picking;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->picking 10 25 35
$self->interactive ? : 0 10 10
140 35 ▶ $self->picking(0) unless $self->_keys_available;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_keys_available 15 20 35
141 35 $self->screen->utf8->flush_on;
142 35 return;
143 }
144  
145 31035 ▶sub say_to { my ($self, @what) = @_; $self->screen->say(join '', @what); return }
Subroutine say_to: called CC=1 SCAR=0.0
Pod documented
146  
147 10435 ▶sub board_lines {
Subroutine board_lines: called CC=4 SCAR=14.0
Pod documented
148 10435 my ($self, $view) = @_;
149 10435 ▶ $view ||= $self->view || $self->game->turn;
Condition50%3/6
$view ||= $self->view || $self->game->turn
l!l&&r!l&&!r
1043320
$self->view || $self->game->turn
l!l&&r!l&&!r
020
MC/DC0%0/3
$view ||= $self->view || $self->game->turn
$view $self->view $self->game->turn
Truth table0%0/4
A ||= B || C
A= $viewB= $self->viewC= $self->game->turn
ABCresult
1XX1
01X1
0011
0000
150 10435 my $board = $self->game->board;
151 10435 my $other = Game::Backgammon::Board::other($view);
152  
153 10435 my @lines = (
154 $self->_border(13 .. 24),
155 $self->_half($view, [13 .. 24], 0),
156 ' |' . (' ' x 18) . '|' . $self->_label('BAR') . '|'
157 . (' ' x 18) . '|' . $self->_label('OFF') . '|',
158 $self->_half($view, [reverse 1 .. 12], 1),
159 $self->_border(reverse 1 .. 12)
160 );
161  
162 10435 $lines[1] .= sprintf ' %-5s %3d pips', ucfirst $other, $board->pip_count($other);
163 10435 $lines[11] .= sprintf ' %-5s %3d pips', ucfirst $view, $board->pip_count($view);
164 10435 ▶ if (my $last = $self->game->history->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $last = $self->game->history->[-1]) 10395 40 10435
165 10395 $lines[6] .= sprintf ' last: %s %s', $last->player, $last->notation;
166 }
167 10435 push @lines, sprintf ' the points are numbered from %s', $view;
168 10435 return \@lines;
169 }
170  
171 10287 ▶sub render {
Subroutine render: called CC=1 SCAR=0.0
Pod documented
172 10287 my ($self, $view) = @_;
173 10287 return join "\n", @{ $self->board_lines($view) };
174 }
175  
176 20870 ▶sub _border {
Subroutine _border: called CC=1 SCAR=0.0
177 20870 my ($self, @points) = @_;
178 20870 my @cell = map { my $c = sprintf '%2d-', $_; $c =~ s/\A /-/; $c } @points;
179 20870 return ' ' . $self->_label(
180 '+' . join('', @cell[0 .. 5]) . '+---+' . join('', @cell[6 .. 11]) . '+---+'
181 );
182 }
183  
184 20870 ▶sub _half {
Subroutine _half: called CC=8 SCAR=20.8
185 20870 my ($self, $view, $points, $bottom) = @_;
186 20870 my $board = $self->game->board;
187 20870 my $other = Game::Backgammon::Board::other($view);
188 20870 my @lines;
189 20870 for my $row (0 .. ROWS - 1) {
190 104350 ▶ my $edge = $bottom ? ROWS - 1 - $row : $row;
Branch: 1 branch
BranchTrueFalseTotal
$bottom ? : 52175 52175 104350
191 104350 ▶ my $middle = $bottom ? $row : ROWS - 1 - $row;
Branch: 1 branch
BranchTrueFalseTotal
$bottom ? : 52175 52175 104350
192 104350 my @cell;
193 104350 for my $n (@$points) {
194 1252200 my ($mine, $theirs) = $board->point_for($view, $n);
195 1252200 ▶ push @cell, $mine
Branch: 1 branch
BranchTrueFalseTotal
$mine ? : 183275 1068925 1252200
196 ? $self->_cell($view, $mine, $edge, $n)
197 : $self->_cell($other, $theirs, $edge, $n);
198 }
199 104350 ▶ my $bar = $bottom
Branch: 1 branch
BranchTrueFalseTotal
$bottom ? : 52175 52175 104350
200 ? $self->_cell($other, $board->bar($other), $middle)
201 : $self->_cell($view, $board->bar($view), $middle);
202 104350 ▶ my $off = $bottom
Branch: 1 branch
BranchTrueFalseTotal
$bottom ? : 52175 52175 104350
203 ? $self->_cell($view, $board->off($view), $edge)
204 : $self->_cell($other, $board->off($other), $edge);
205 104350 push @lines, ' ' . $self->_label('|') . join('', @cell[0 .. 5])
206 . $self->_label('|') . $bar . $self->_label('|')
207 . join('', @cell[6 .. 11]) . $self->_label('|') . $off
208 . $self->_label('|');
209 }
210 20870 return @lines;
211 }
212  
213 1460900 ▶sub _cell {
Subroutine _cell: called CC=8 SCAR=20.8
214 1460900 my ($self, $player, $count, $edge, $point) = @_;
215 1460900 ▶ return $self->_ground($point, ' ') unless $count && $edge < ROWS;
Branch: 1 branch
BranchTrueFalseTotal
unless $count and $edge < 5 1036090 424810 1460900
Condition66%2/3
$count and $edge < 5
!ll&&!rl&&r
10360900424810
MC/DC50%1/2
$count and $edge < 5
$count $edge < 5
Truth table66%2/3
A and B
A= $countB= $edge < 5
ABresult
0X0
100
111
216 424810 ▶ return $self->_ground(
Branch: 2 branches
BranchTrueFalseTotal
if $edge == 4 and $count > 5 20355 404455 424810
$count > 9 ? : 16401 3954 20355
Condition100%3/3
$edge == 4 and $count > 5
!ll&&!rl&&r
3398486460720355
MC/DC100%2/2
$edge == 4 and $count > 5
$edge == 4 $count > 5
Truth table100%3/3
A and B
A= $edge == 4B= $count > 5
ABresult
0X0
100
111
217 $point, $count > 9 ? "$count " : " $count ", $player
218 ) if $edge == ROWS - 1 && $count > ROWS;
219 404455 ▶ return $self->_ground($point, ' ') unless $edge < $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $edge < $count 233687 170768 404455
220 return $self->_ground(
221 170768 ▶ $point, ' ' . $CHECKER{$player}{$self->ascii ? 'ascii' : 'wide'} . ' ', $player
Branch: 1 branch
BranchTrueFalseTotal
$self->ascii ? : 164695 6073 170768
222 );
223 }
224  
225 1460900 ▶sub _ground {
Subroutine _ground: called CC=8 SCAR=20.8
226 1460900 my ($self, $point, $text, $player) = @_;
227 return $player
228 ? $self->_paint($text, $CHECKER{$player}{colour})
229 1460900 ▶ : $text
Branch: 2 branches
BranchTrueFalseTotal
unless $self->colour and defined $point 1460660 240 1460900
$player ? : 191063 1269597 1460660
Condition100%3/3
$self->colour and defined $point
!ll&&!rl&&r
146062040240
MC/DC100%2/2
$self->colour and defined $point
$self->colour defined $point
Truth table100%3/3
A and B
A= $self->colourB= defined $point
ABresult
0X0
100
111
230 unless $self->colour && defined $point;
231  
232 240 my $mark = $self->highlight->{$point};
233 240 ▶ $mark = $point % 2 ? 'dark' : 'light' unless $mark && $GROUND{$mark};
Branch: 2 branches
BranchTrueFalseTotal
unless $mark and $GROUND{$mark} 235 5 240
$point % 2 ? : 115 120 235
Condition66%2/3
$mark and $GROUND{$mark}
!ll&&!rl&&r
23505
MC/DC50%1/2
$mark and $GROUND{$mark}
$mark $GROUND{$mark}
Truth table66%2/3
A and B
A= $markB= $GROUND{$mark}
ABresult
0X0
100
111
234 240 my @code = ($GROUND{$mark});
235 240 ▶ push @code, $CHECKER{$player}{ink} if $player;
Branch: 1 branch
BranchTrueFalseTotal
if $player 60 180 240
236 240 return "\e[" . join(';', @code) . "m$text\e[0m";
237 }
238  
239 563490 ▶sub _label { my ($self, $text) = @_; return $self->_paint($text, '2') }
Subroutine _label: called CC=1 SCAR=0.0
240  
241 754553 ▶sub _paint {
Subroutine _paint: called CC=1 SCAR=0.0
242 754553 my ($self, $text, $code) = @_;
243 754553 return $self->screen->paint($text, $code);
244 }
245  
246 10286 ▶sub clear { my ($self) = @_; $self->screen->clear; return }
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
247  
248 10247 ▶sub raw { my ($self) = @_; return $self->keyboard->raw }
Subroutine raw: called CC=1 SCAR=0.0
Pod documented
249  
250 35 ▶sub _keys_available { my ($self) = @_; return $self->keyboard->keys_available }
Subroutine _keys_available: called CC=1 SCAR=0.0
251  
252 22 ▶sub _enter_raw { my ($self) = @_; return $self->keyboard->enter_raw ? $self : undef }
Subroutine _enter_raw: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$self->keyboard->enter_raw ? : 22 0 22
253  
254 0 ▶sub _leave_raw { my ($self) = @_; $self->keyboard->leave_raw; return $self }
Subroutine _leave_raw: not called CC=1 SCAR=6.9
255  
256 161 ▶sub _read_key { my ($self) = @_; return $self->keyboard->read_key }
Subroutine _read_key: called CC=1 SCAR=0.0
257  
258 10335 ▶sub step {
Subroutine step: called CC=13 SCAR=26.0
Pod documented
259 10335 my ($self) = @_;
260 10335 my $game = $self->game;
261 10335 ▶ return 0 if $game->status ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $game->status ne "active" 0 10335 10335
262  
263 10335 my $who = $game->turn;
264 10335 my $person = $self->_at_keys($who);
265 10335 ▶ my $picking = $self->picking && $self->raw && $person;
Condition83%5/6
$self->picking && $self->raw && $person
!ll&&!rl&&r
2161005762
$self->picking and $self->raw
!ll&&!rl&&r
216010119
MC/DC66%2/3
$self->picking && $self->raw && $person
$self->picking $self->raw $person
Truth table75%3/4
A and B && C
A= $self->pickingB= $self->rawC= $person
ABCresult
0XX0
10X0
1100
1111
266 10335 ▶ unless ($picking) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($picking) 10273 62 10335
267 10273 $self->clear;
268 10273 $self->say_to($self->render($who));
269 10273 $self->say_to(sprintf ' %s to play %s', $who, join '-', @{ $game->dice });
270 10273 $self->_say_notes;
271 }
272  
273 10335 my $turns = $game->legal_turns;
274 10335 ▶ if ($turns->[0]->is_forfeit && @$turns == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($turns->[0]->is_forfeit and @$turns == 1) 28 10307 10335
Condition66%2/3
$turns->[0]->is_forfeit and @$turns == 1
!ll&&!rl&&r
10307028
MC/DC50%1/2
$turns->[0]->is_forfeit and @$turns == 1
$turns->[0]->is_forfeit @$turns == 1
Truth table66%2/3
A and B
A= $turns->[0]->is_forfeitB= @$turns == 1
ABresult
0X0
100
111
275 28 ▶ if ($picking) {
Branch: 1 branch
BranchTrueFalseTotal
if ($picking) 1 27 28
276 1 $self->clear;
277 1 ▶ $self->say_to($self->render($self->view || $who));
Condition33%1/3
$self->view || $who
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->view || $who
$self->view $who
Truth table33%1/3
A || B
A= $self->viewB= $who
ABresult
1X1
011
000
278 1 $self->say_to(sprintf ' %s to play %s', $who, join '-', @{ $game->dice });
279 }
280 28 $self->say_to(' no play');
281 28 $game->play($turns->[0]);
282 28 return $self->_played;
283 }
284  
285 10307 ▶ $self->person_turn if $person;
Branch: 1 branch
BranchTrueFalseTotal
if $person 118 10189 10307
286 10307 my $turn = $self->_ask($who, $turns);
287 10307 ▶ return 0 unless $turn;
Branch: 1 branch
BranchTrueFalseTotal
unless $turn 9 10298 10307
288 10298 ▶ return 1 unless ref $turn;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $turn 10 10288 10298
289 0 ▶ $game->play($turn) or do { $self->say_to(' ' . $@->message); return 1 };
Branch: 1 branch
BranchTrueFalseTotal
$game->play($turn) or do { $self->say_to(' ' . $@->message); return 1 } 10288 0 10288
290 10288 $self->say_to(' ' . $turn->notation);
291 10288 return $self->_played;
292 }
293  
294 10335 ▶sub _at_keys {
Subroutine _at_keys: called CC=4 SCAR=13.9
295 10335 my ($self, $who) = @_;
296 10335 ▶ return 1 if $self->mode eq 'hotseat';
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode eq "hotseat" 5 10330 10335
297 10330 ▶ return $self->mode eq 'bot' && $who eq $self->seat ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->mode eq 'bot' && $who eq $self->seat ? : 123 10207 10330
Condition100%3/3
$self->mode eq "bot" and $who eq $self->seat
!ll&&!rl&&r
10089118123
MC/DC100%2/2
$self->mode eq "bot" and $who eq $self->seat
$self->mode eq "bot" $who eq $self->seat
Truth table100%3/3
A and B
A= $self->mode eq "bot"B= $who eq $self->seat
ABresult
0X0
100
111
298 }
299  
300 10316 ▶sub _played {
Subroutine _played: called CC=3 SCAR=11.0
301 10316 my ($self) = @_;
302 10316 ▶ return 1 if $self->game->status eq 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $self->game->status eq "active" 10312 4 10316
303 4 ▶ $self->person_turn unless $self->mode eq 'watch';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->mode eq "watch" 3 1 4
304 4 return 0;
305 }
306  
307 10274 ▶sub _say_notes {
Subroutine _say_notes: called CC=2 SCAR=6.9
308 10274 my ($self) = @_;
309 10274 $self->say_to(" $_") for $self->log->lines;
310 10274 $self->log->shown;
311 10274 return;
312 }
313  
314 121 ▶sub person_turn {
Subroutine person_turn: called CC=1 SCAR=0.0
Pod documented
315 121 my ($self) = @_;
316 121 $self->history->turn($self->game);
317 121 return $self;
318 }
319  
320 11 ▶sub take_back {
Subroutine take_back: called CC=2 SCAR=6.9
Pod documented
321 11 my ($self) = @_;
322 11 my $game = $self->history->undo;
323 11 ▶ return $self->_notify('There is nothing to take back.') unless $game;
Branch: 1 branch
BranchTrueFalseTotal
unless $game 3 8 11
324 8 $self->swap($game);
325 8 $self->_notify('Taken back.');
326 8 return 1;
327 }
328  
329 4 ▶sub play_again {
Subroutine play_again: called CC=2 SCAR=6.9
Pod documented
330 4 my ($self) = @_;
331 4 my $game = $self->history->redo;
332 4 ▶ return $self->_notify('There is nothing to play again.') unless $game;
Branch: 1 branch
BranchTrueFalseTotal
unless $game 1 3 4
333 3 $self->swap($game);
334 3 $self->_notify('Played again.');
335 3 return 1;
336 }
337  
338 11 ▶sub swap {
Subroutine swap: called CC=1 SCAR=0.0
Pod documented
339 11 my ($self, $game) = @_;
340 11 $self->game($game);
341 11 $self->highlight({});
342 11 $self->log->forget;
343 11 return $self;
344 }
345  
346 15 ▶sub _notify {
Subroutine _notify: called CC=1 SCAR=0.0
347 15 my ($self, $line) = @_;
348 15 $self->log->note($line);
349 15 return 0;
350 }
351  
352 10307 ▶sub _ask {
Subroutine _ask: called CC=17 SCAR=28.3
353 10307 my ($self, $who, $turns) = @_;
354 10307 ▶ return Game::Backgammon::Bot->new(level => $self->level)->choose($self->game)
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode eq "watch" or $self->mode eq "bot" and $who ne $self->seat 10189 118 10307
Condition100%6/6
$self->mode eq "watch" or $self->mode eq "bot" and $who ne $self->seat
l!l&&r!l&&!r
10071118118
$self->mode eq "bot" and $who ne $self->seat
!ll&&!rl&&r
5113118
MC/DC100%3/3
$self->mode eq "watch" or $self->mode eq "bot" and $who ne $self->seat
$self->mode eq "watch" $self->mode eq "bot" $who ne $self->seat
Truth table100%4/4
A or B and C
A= $self->mode eq "watch"B= $self->mode eq "bot"C= $who ne $self->seat
ABCresult
1XX1
0111
00X0
0100
355 if $self->mode eq 'watch'
356 || ($self->mode eq 'bot' && $who ne $self->seat);
357  
358 118 ▶ if ($self->picking && $self->raw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->picking and $self->raw) 61 57 118
Condition66%2/3
$self->picking and $self->raw
!ll&&!rl&&r
57061
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
359 61 my $turn = $self->_pick_turn($who, $turns);
360 61 $self->highlight({});
361 61 return $turn;
362 }
363  
364 57 $self->say_to($_) for @{ $self->offer_lines($turns) };
365 57 while (1) {
366 61 my $line = $self->keyboard->read_line(" $who> ", $self->out);
367 61 ▶ return undef unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 1 60 61
368 60 ▶ return undef if $line eq 'q' || $line eq 'quit';
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "q" or $line eq "quit" 6 54 60
Condition66%2/3
$line eq "q" or $line eq "quit"
l!l&&r!l&&!r
6054
MC/DC50%1/2
$line eq "q" or $line eq "quit"
$line eq "q" $line eq "quit"
Truth table66%2/3
A or B
A= $line eq "q"B= $line eq "quit"
ABresult
1X1
011
000
369 54 ▶ if ($line eq 'undo' || $line eq 'redo') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "undo" or $line eq "redo") 4 50 54
Condition100%3/3
$line eq "undo" or $line eq "redo"
l!l&&r!l&&!r
3150
MC/DC100%2/2
$line eq "undo" or $line eq "redo"
$line eq "undo" $line eq "redo"
Truth table100%3/3
A or B
A= $line eq "undo"B= $line eq "redo"
ABresult
1X1
011
000
370 4 ▶ return 'swapped' if $line eq 'undo' ? $self->take_back : $self->play_again;
Branch: 2 branches
BranchTrueFalseTotal
if $line eq "undo" ? $self->take_back : $self->play_again 3 1 4
$line eq 'undo' ? : 3 1 4
371 1 $self->_say_notes;
372 1 next;
373 }
374 50 ▶ return $turns->[ $line - 1 ] if $line =~ /\A\d+\z/ && $line >= 1 && $line <= @$turns;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\d+\z/ and $line >= 1 and $line <= @$turns 47 3 50
Condition100%6/6
$line =~ /\A\d+\z/ and $line >= 1 and $line <= @$turns
!ll&&!rl&&r
2147
$line =~ /\A\d+\z/ and $line >= 1
!ll&&!rl&&r
1148
MC/DC100%3/3
$line =~ /\A\d+\z/ and $line >= 1 and $line <= @$turns
$line =~ /\A\d+\z/ $line >= 1 $line <= @$turns
Truth table100%4/4
A and B and C
A= $line =~ /\A\d+\z/B= $line >= 1C= $line <= @$turns
ABCresult
0XX0
10X0
1100
1111
375 3 $self->say_to(' pick a number from the list, or q to stop');
376 }
377 }
378  
379 208 ▶sub _matching {
Subroutine _matching: called CC=5 SCAR=16.1
380 208 my ($self, $turns, $chosen) = @_;
381 208 my @match;
382 208 TURN: for my $turn (@$turns) {
383 2995 my $moves = $turn->moves;
384 2995 ▶ next TURN if @$moves < @$chosen;
Branch: 1 branch
BranchTrueFalseTotal
if @$moves < @$chosen 0 2995 2995
385 2995 for my $at (0 .. $#$chosen) {
386 2667 ▶ next TURN if $moves->[$at]->notation ne $chosen->[$at]->notation;
Branch: 1 branch
BranchTrueFalseTotal
if $moves->[$at]->notation ne $chosen->[$at]->notation 1628 1039 2667
387 }
388 1367 push @match, $turn;
389 }
390 208 return \@match;
391 }
392  
393 208 ▶sub _next_moves {
Subroutine _next_moves: called CC=4 SCAR=13.9
394 208 my ($self, $match, $chosen) = @_;
395 208 my (@move, %seen);
396 208 for my $turn (@$match) {
397 1450 ▶ my $move = $turn->moves->[ scalar @$chosen ] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $move = $turn->moves->[scalar @$chosen] or next 1391 59 1450
398 1391 ▶ next if $seen{ $move->notation }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$move->notation}++ 863 528 1391
399 528 push @move, $move;
400 }
401 208 return \@move;
402 }
403  
404 196 ▶sub _complete {
Subroutine _complete: called CC=3 SCAR=11.0
405 196 my ($self, $match, $chosen) = @_;
406 196 for my $turn (@$match) {
407 1117 ▶ return $turn if @{ $turn->moves } == @$chosen;
Branch: 1 branch
BranchTrueFalseTotal
if @{$turn->moves;} == @$chosen 58 1059 1117
408 }
409 138 return undef;
410 }
411  
412 147 ▶sub _move_marks {
Subroutine _move_marks: called CC=8 SCAR=20.8
413 147 my ($self, $view, $player, $chosen, $hover) = @_;
414 147 my %mark;
415 476 ▶ my $seen = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
416 476 my ($point) = @_;
417 476 ▶ return undef if $point eq 'bar' || $point eq 'off';
Branch: 1 branch
BranchTrueFalseTotal
if $point eq "bar" or $point eq "off" 51 425 476
Condition100%3/3
$point eq "bar" or $point eq "off"
l!l&&r!l&&!r
501425
MC/DC100%2/2
$point eq "bar" or $point eq "off"
$point eq "bar" $point eq "off"
Truth table100%3/3
A or B
A= $point eq "bar"B= $point eq "off"
ABresult
1X1
011
000
418 425 ▶ return $view eq $player ? $point : 25 - $point;
Branch: 1 branch
BranchTrueFalseTotal
$view eq $player ? : 423 2 425
419 147 };
420 147 for my $move (@$chosen) {
421 92 for my $end ($move->from, $move->to) {
422 184 ▶ my $point = $seen->($end) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $point = &$seen($end) or next 160 24 184
423 160 $mark{$point} = 'played';
424 }
425 }
426 147 ▶ if ($hover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hover) 146 1 147
427 146 ▶ if (my $to = $seen->($hover->to)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to = &$seen($hover->to)) 145 1 146
428 145 ▶ $mark{$to} = $hover->hit ? 'hit' : 'to';
Branch: 1 branch
BranchTrueFalseTotal
$hover->hit ? : 18 127 145
429 }
430 146 ▶ if (my $from = $seen->($hover->from)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $from = &$seen($hover->from)) 120 26 146
431 120 $mark{$from} = 'from';
432 }
433 }
434 147 return \%mark;
435 }
436  
437 138 ▶sub _move_items {
Subroutine _move_items: called CC=1 SCAR=0.0
438 138 my ($self, $next) = @_;
439 138 return [ map { { label => $_->notation, about => $self->_describe($_), value => $_ } } @$next ];
440 }
441  
442 66 ▶sub _pick_turn {
Subroutine _pick_turn: called CC=23 SCAR=32.0
443 66 my ($self, $who, $turns) = @_;
444 66 ▶ return undef unless $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->raw 0 66 66
445 66 ▶ my $view = $self->view || $who;
Condition33%1/3
$self->view || $who
l!l&&r!l&&!r
0660
MC/DC0%0/2
$self->view || $who
$self->view $who
Truth table33%1/3
A || B
A= $self->viewB= $who
ABresult
1X1
011
000
446 66 my $picker = $self->picker;
447 66 my $log = $self->log;
448 66 my (@chosen, $done);
449 66 my $fresh = 1;
450  
451 66 while (1) {
452 197 ▶ if ($fresh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fresh) 193 4 197
453 193 my $match = $self->_matching($turns, \@chosen);
454 193 my $next = $self->_next_moves($match, \@chosen);
455 193 $done = $self->_complete($match, \@chosen);
456 193 ▶ return $done if $done && !@$next;
Branch: 1 branch
BranchTrueFalseTotal
if $done and not @$next 55 138 193
Condition66%2/3
$done and not @$next
!ll&&!rl&&r
138055
MC/DC50%1/2
$done and not @$next
$done not @$next
Truth table66%2/3
A and not(B)
A= $doneB= not @$next
ABresult
0X0
100
111
457 138 $picker->reset($self->_move_items($next));
458 $picker->game_keys({
459 k => 'up', j => 'down', v => 'view', '?' => 'help',
460 138 ▶ %{ Game::Terminal::Kit::History->game_keys },
Branch: 1 branch
BranchTrueFalseTotal
$done ? : 0 138 138
461 ($done ? (f => 'finish') : ()),
462 });
463 138 $fresh = 0;
464 }
465  
466 $self->highlight(
467 142 $self->_move_marks($view, $who, \@chosen, $picker->current)
468 );
469 142 $self->_draw_choice($who, $view, $picker, \@chosen, $done);
470  
471 142 my ($event, $value) = $picker->step($self->_read_key);
472 142 ▶ if ($event eq 'quit') {
Branch: 1 branch
BranchTrueFalseTotal
if ($event eq "quit") 4 138 142
473 4 $self->highlight({});
474 4 return undef;
475 }
476 138 ▶ if ($event eq 'chosen') {
Branch: 1 branch
BranchTrueFalseTotal
if ($event eq "chosen") 125 13 138
477 125 push @chosen, $value;
478 125 $fresh = 1;
479 125 next;
480 }
481 13 ▶ if ($event eq 'back') {
Branch: 1 branch
BranchTrueFalseTotal
if ($event eq "back") 2 11 13
482 2 ▶ $log->note('nothing taken back: no move chosen yet') unless @chosen;
Branch: 1 branch
BranchTrueFalseTotal
unless @chosen 1 1 2
483 2 pop @chosen;
484 2 $fresh = 1;
485 2 next;
486 }
487 11 ▶ next unless $event eq 'key';
Branch: 1 branch
BranchTrueFalseTotal
unless $event eq "key" 1 10 11
488 10 ▶ return $done if $value eq 'finish';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "finish" 0 10 10
489 10 ▶ if ($value eq 'undo' || $value eq 'redo') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "undo" or $value eq "redo") 9 1 10
Condition100%3/3
$value eq "undo" or $value eq "redo"
l!l&&r!l&&!r
631
MC/DC100%2/2
$value eq "undo" or $value eq "redo"
$value eq "undo" $value eq "redo"
Truth table100%3/3
A or B
A= $value eq "undo"B= $value eq "redo"
ABresult
1X1
011
000
490 9 ▶ next unless $value eq 'undo' ? $self->take_back : $self->play_again;
Branch: 2 branches
BranchTrueFalseTotal
unless $value eq "undo" ? $self->take_back : $self->play_again 2 7 9
$value eq 'undo' ? : 6 3 9
491 7 ▶ $log->note('The moves chosen this turn were dropped.') if @chosen;
Branch: 1 branch
BranchTrueFalseTotal
if @chosen 1 6 7
492 7 return 'swapped';
493 }
494 1 ▶ $picker->move($value eq 'up' ? -1 : 1) if $value eq 'up' || $value eq 'down';
Branch: 2 branches
BranchTrueFalseTotal
if $value eq "up" or $value eq "down" 1 0 1
$value eq 'up' ? : 0 1 1
Condition33%1/3
$value eq "up" or $value eq "down"
l!l&&r!l&&!r
010
MC/DC0%0/2
$value eq "up" or $value eq "down"
$value eq "up" $value eq "down"
Truth table33%1/3
A or B
A= $value eq "up"B= $value eq "down"
ABresult
1X1
011
000
495 1 ▶ $self->view($view = Game::Backgammon::Board::other($view)) if $value eq 'view';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "view" 0 1 1
496 0 ▶ $log->note(@{ $self->_key_lines }) if $value eq 'help';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "help" 0 1 1
497 }
498 }
499  
500 0 ▶sub _key_lines {
Subroutine _key_lines: not called CC=1 SCAR=6.9
501 return [
502 0 'up and down choose a move, enter plays it',
503 'backspace or escape takes back the move chosen before it',
504 'a digit jumps to that move, v turns the board round',
505 'f finishes the turn where one can end, q stops the game',
506 'u takes back your last turn, r plays it again',
507 ];
508 }
509  
510 142 ▶sub _draw_choice {
Subroutine _draw_choice: called CC=3 SCAR=11.0
511 142 my ($self, $who, $view, $picker, $chosen, $done) = @_;
512 142 my $log = $self->log;
513 $self->screen->show([
514 142 @{ $self->board_lines($view) },
515 142 ▶ sprintf(' %s to play %s', $who, join '-', @{ $self->game->dice }),
Branch: 1 branch
BranchTrueFalseTotal
@$chosen ? : 70 72 142
516 (@$chosen
517 91 ? ' so far: ' . join ' ', map { $_->notation } @$chosen
518 : ' nothing chosen yet'),
519 '',
520 453 ▶ (map { " $_" } $picker->rows),
Branch: 1 branch
BranchTrueFalseTotal
$done ? : 0 142 142
521 ($done ? ('', ' f finishes the turn here') : ()),
522 142 (map { " $_" } $log->lines),
523 '',
524 ' up and down to choose, enter to play it, ? for the keys',
525 ]);
526 142 $log->shown;
527 142 return;
528 }
529  
530 436 ▶sub _describe {
Subroutine _describe: called CC=5 SCAR=16.1
531 436 my ($self, $move) = @_;
532 436 my @note;
533 436 ▶ push @note, 'from the bar' if $move->is_bar;
Branch: 1 branch
BranchTrueFalseTotal
if $move->is_bar 35 401 436
534 436 ▶ push @note, 'bears off' if $move->is_off;
Branch: 1 branch
BranchTrueFalseTotal
if $move->is_off 0 436 436
535 436 ▶ push @note, 'hits' if $move->hit;
Branch: 1 branch
BranchTrueFalseTotal
if $move->hit 52 384 436
536 436 ▶ push @note, sprintf 'with the %d', $move->die unless @note;
Branch: 1 branch
BranchTrueFalseTotal
unless @note 354 82 436
537 436 return join ', ', @note;
538 }
539  
540 59 ▶sub offer_lines {
Subroutine offer_lines: called CC=6 SCAR=17.9
Pod documented
541 59 my ($self, $turns) = @_;
542 59 my @item = map { sprintf '%2d) %s', $_ + 1, $turns->[$_]->notation } 0 .. $#$turns;
543 59 my $width = 0;
544 59 for my $item (@item) {
545 442 ▶ $width = length $item if length $item > $width;
Branch: 1 branch
BranchTrueFalseTotal
if length $item > $width 163 279 442
546 }
547 59 ▶ my $columns = int(74 / ($width + 2)) || 1;
Condition50%1/2
int 74 / ($width + 2) || 1
l!l
590
MC/DC0%0/1
int 74 / ($width + 2) || 1
int 74 / ($width + 2)
Truth table50%1/2
A
A= int 74 / ($width + 2)
Aresult
11
00
548 59 ▶ $columns = 4 if $columns > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $columns > 4 6 53 59
549 59 my @lines;
550 59 ▶ while (@item) {
Branch: 1 branch
BranchTrueFalseTotal
if (@item) 149 59 208
551 149 my @row = splice @item, 0, $columns;
552 149 my $line = ' ' . join ' ', map { sprintf '%-*s', $width, $_ } @row;
553 149 $line =~ s/\s+\z//;
554 149 push @lines, $line;
555 }
556 59 return \@lines;
557 }
558  
559 12 ▶sub start {
Subroutine start: called CC=6 SCAR=18.0
Pod documented
560 12 my ($self) = @_;
561 12 ▶ $self->game(Game::Backgammon->new(seed => $self->_seed)) unless $self->game;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->game 0 12 12
562 12 $self->history->start($self->game);
563 12 ▶ $self->picking(0) if $self->picking && !$self->_enter_raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->picking and not $self->_enter_raw 0 12 12
Condition66%2/3
$self->picking and not $self->_enter_raw
!ll&&!rl&&r
1020
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
564  
565 12 ▶ Game::Terminal::Kit::Run::guard(sub { $self->_turns }, $self->keyboard, $self->screen);
Subroutine __ANON__: called CC=1 SCAR=0.0
566  
567 12 $self->clear;
568 12 $self->highlight({});
569 12 ▶ $self->say_to($self->render($self->mode eq 'bot' ? $self->seat : undef));
Branch: 1 branch
BranchTrueFalseTotal
$self->mode eq 'bot' ? : 10 2 12
570 12 my $r = $self->game->result;
571 12 ▶ $self->say_to($r ? $r->stringify : 'stopped');
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 4 8 12
572 12 return $r;
573 }
574  
575 12 ▶sub _turns {
Subroutine _turns: called CC=3 SCAR=11.0
576 12 my ($self) = @_;
577 12 my $guard = 0;
578 12 ▶ while ($self->step) { last if ++$guard > 10_000 }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->step) 10301 11 10312
if ++$guard > 10000 1 10300 10301
579 12 return;
580 }
581  
582 0 ▶sub _seed {
Subroutine _seed: not called CC=3 SCAR=24.8
583 0 require Digest::SHA;
584 0 ▶ open my $ur, '<:raw', '/dev/urandom' or return Digest::SHA::sha256(rand() . $$ . time);
Branch: 1 branch
BranchTrueFalseTotal
open my $ur, "<:raw", "/dev/urandom" or return &Digest::SHA::sha256((rand()) . $$ . time) 0 0 0
585 0 read $ur, my $bytes, 32;
586 0 close $ur;
587 0 ▶ return length($bytes) == 32 ? $bytes : Digest::SHA::sha256(rand() . $$ . time);
Branch: 1 branch
BranchTrueFalseTotal
length $bytes == 32 ? : 0 0 0
588 }
589  
590 9 ▶sub _usage {
Subroutine _usage: called CC=1 SCAR=0.0
591 9 return <<'USAGE';
592 backgammon [--mode bot|hotseat|watch] [--level 1-3] [--seat white|black]
593 [--view white|black] [--ascii] [--no-colour] [--no-pick]
594  
595 bot play the computer (the default)
596 hotseat two people at one keyboard
597 watch the computer against itself
598  
599 --view pin the board to one side's numbering. By default it is drawn
600 from the side on roll, because a turn is written in the mover's
601 own numbers and the board should agree with the list.
602 --ascii O and X instead of the round checkers.
603 --no-pick choose a whole turn by number from the list, as 0.01 did, rather
604 than one checker at a time with the keys.
605 --help this
606  
607 The board is the usual one: your home board is the bottom right quarter and
608 you run into it anticlockwise, the bar is the middle column and the tray the
609 one on the right.
610  
611 On a terminal a turn is built one checker at a time: the moves you can make
612 with the dice you have left are listed, up and down choose one and enter plays
613 it, backspace or escape takes the last one back, and the board shows where the checker
614 under the cursor is going. A roll that can be played three hundred ways is
615 still only a handful of choices at each step. v turns the board round, u takes
616 back your last turn and r plays it again, and q stops. Without a terminal, or
617 with --no-pick, every legal turn is numbered and you pick one, or type undo or
618 redo.
619  
620 Exit status is 0 when the game ended or was stopped, 2 for an option the game
621 will not take.
622 USAGE
623 }
624  
625 2 ▶sub options {
Subroutine options: called CC=1 SCAR=0.0
Pod documented
626 return [
627 2 { name => 'mode', type => 'enum', choices => [qw(bot hotseat watch)], help => 'you against the program, two people at one keyboard, or two programs' },
628 { name => 'level', type => 'int', min => 1, max => 3, help => 'how hard the program plays' },
629 { name => 'seat', type => 'enum', choices => [qw(white black)], help => 'your side' },
630 ];
631 }
632  
633 9 ▶sub run {
Subroutine run: called CC=11 SCAR=38.0
Pod documented
634 9 my ($class, @argv) = @_;
635 9 my %o = (mode => 'bot', level => 3, seat => 'white', view => '', ascii => 0);
636 9 my ($colour, $pick, $help);
637  
638 9 my $ok = eval {
639 9 ▶ local $SIG{__WARN__} = sub { print STDERR "backgammon: $_[0]" };
Subroutine __ANON__: called CC=1 SCAR=0.0
640 Getopt::Long::GetOptionsFromArray(\@argv,
641 'mode=s' => \$o{mode},
642 'level=i' => \$o{level},
643 'seat=s' => \$o{seat},
644 'view=s' => \$o{view},
645 'ascii' => \$o{ascii},
646 9 'colour!' => \$colour,
647 'pick!' => \$pick,
648 'help' => \$help,
649 );
650 };
651 9 ▶ if (!$ok) { print STDERR _usage(); return 2 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 8 9
652 8 ▶ if ($help) { print _usage(); return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 8 0 8
653 0 ▶ if (@argv) { print STDERR "backgammon: not an option: $argv[0]\n", _usage(); return 2 }
Branch: 1 branch
BranchTrueFalseTotal
if (@argv) 0 0 0
654  
655 0 my %refused = (
656 mode => [ qr/\A(?:bot|hotseat|watch)\z/, 'bot, hotseat or watch' ],
657 seat => [ qr/\A(?:white|black)\z/, 'white or black' ],
658 view => [ qr/\A(?:white|black|)\z/, 'white or black' ],
659 level => [ qr/\A[123]\z/, '1 to 3' ],
660 );
661 0 for my $k (qw(mode seat view level)) {
662 0 ▶ next if $o{$k} =~ $refused{$k}[0];
Branch: 1 branch
BranchTrueFalseTotal
if $o{$k} =~ /$refused{$k}[0]/ 0 0 0
663 0 print STDERR "backgammon: --$k takes $refused{$k}[1], not '$o{$k}'\n", _usage();
664 0 return 2;
665 }
666  
667 0 ▶ my $terminal = $class->new(
Branch: 2 branches
BranchTrueFalseTotal
defined $colour ? : 0 0 0
defined $pick ? : 0 0 0
668 %o,
669 (defined $colour ? (colour => $colour) : ()),
670 (defined $pick ? (picking => $pick) : ()),
671 );
672  
673 my $result = Game::Terminal::Kit::Run::guard(
674 0 ▶ sub { $terminal->start }, $terminal->keyboard, $terminal->screen,
Subroutine __ANON__: not called CC=1 SCAR=6.9
675 );
676 0 ▶ return 1 if $result && $terminal->mode eq 'bot' && $result->winner ne $terminal->seat;
Branch: 1 branch
BranchTrueFalseTotal
if $result and $terminal->mode eq "bot" and $result->winner ne $terminal->seat 0 0 0
Condition0%0/6
$result and $terminal->mode eq "bot" and $result->winner ne $terminal->seat
!ll&&!rl&&r
000
$result and $terminal->mode eq "bot"
!ll&&!rl&&r
000
MC/DC0%0/3
$result and $terminal->mode eq "bot" and $result->winner ne $terminal->seat
$result $terminal->mode eq "bot" $result->winner ne $terminal->seat
Truth table0%0/4
A and B and C
A= $resultB= $terminal->mode eq "bot"C= $result->winner ne $terminal->seat
ABCresult
0XX0
10X0
1100
1111
677 0 return 0;
678 }
679  
680 5 1;
681  
682 __END__
« Backgammon/Notation.pm ↑ Summary Backgammon.pm »