blib/lib/Game/Senet/Terminal.pm

filter: Statementstmt 94.0% 692 / 736 Branchbran 83.5% 381 / 456 Conditioncond 69.1% 130 / 188 MC/DCmcdc 49.5% 55 / 111 Subroutinesub 97.8% 92 / 94 Podpod 96.1% 25 / 26 totaltotal 85.3% 1375 / 1611 CC 307 SCAR 28.8
CC
307
Cov
87%
command
88.0
BUILD
35.3
run
26.0
CRAP 17.8
« blib/lib/Game/Senet.pm ↑ Summary blib/lib/Game/Senet/Result.pm »
1 package Game::Senet::Terminal;
2  
3 75 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 75 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 75 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 75 ▶use Carp ();
Subroutine __ANON__: called CC=1 SCAR=0.0
8 75 ▶use Digest::SHA ();
Subroutine __ANON__: called CC=1 SCAR=0.0
9 75 ▶use Getopt::Long ();
Subroutine __ANON__: called CC=1 SCAR=0.0
10 75 ▶use Object::Proto::Sugar;
Subroutine __ANON__: called CC=1 SCAR=0.0
11  
12 75 ▶use Game::Terminal::Kit::Frame;
Subroutine __ANON__: called CC=1 SCAR=0.0
13 75 ▶use Game::Terminal::Kit::History;
Subroutine __ANON__: called CC=1 SCAR=0.0
14 75 ▶use Game::Terminal::Kit::Keys;
Subroutine __ANON__: called CC=1 SCAR=0.0
15 75 ▶use Game::Terminal::Kit::Replay;
Subroutine __ANON__: called CC=1 SCAR=0.0
16 75 ▶use Game::Terminal::Kit::Run;
Subroutine __ANON__: called CC=1 SCAR=0.0
17 75 ▶use Game::Terminal::Kit::Save;
Subroutine __ANON__: called CC=1 SCAR=0.0
18 75 ▶use Game::Terminal::Kit::Screen;
Subroutine __ANON__: called CC=1 SCAR=0.0
19 75 ▶use Game::Terminal::Kit::Steer;
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 75 ▶use Game::Senet;
Subroutine __ANON__: called CC=1 SCAR=0.0
22 75 ▶use Game::Senet::Bot;
Subroutine __ANON__: called CC=1 SCAR=0.0
23 75 ▶use Game::Senet::Variant;
Subroutine __ANON__: called CC=1 SCAR=0.0
24 75 ▶use Game::Senet::Notation ();
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 75 our $VERSION = '0.03';
27  
28 75 my (%STYLE, %GLYPH, %SIGN, %OTHER, %ROW_OF, %COL_OF);
29 75 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
30 75 %STYLE = (
31 title => '1;38;5;220',
32 grid => '38;5;241',
33 label => '38;5;245',
34 sign => '1;38;5;205',
35 light => '1;38;5;229',
36 dark => '1;38;5;39',
37 cursor => '1;38;5;16;48;5;220',
38 target => '1;38;5;16;48;5;114',
39 from => '1;38;5;231;48;5;160',
40 recent => '38;5;250',
41 face => '1;38;5;229',
42 back => '38;5;240',
43 key => '1;38;5;214',
44 good => '1;38;5;114',
45 bad => '1;38;5;203',
46 quiet => '38;5;245',
47 );
48  
49 75 %GLYPH = (
50 wide => {
51 light => "\x{25CF}", dark => "\x{25CB}", face => "\x{25AF}", back => "\x{25AE}",
52 h => "\x{2500}", v => "\x{2502}", tl => "\x{250C}", tr => "\x{2510}", bl => "\x{2514}",
53 br => "\x{2518}", td => "\x{252C}", tu => "\x{2534}", lt => "\x{251C}", rt => "\x{2524}",
54 x => "\x{253C}", ankh => "\x{2625}", turn_a => "\x{2500}\x{2510}", turn_b => "\x{2502}",
55 turn_c => "\x{2500}\x{2518}", turn_d => "\x{250C}\x{2500}", turn_e => "\x{2502}",
56 turn_f => "\x{2514}\x{2500}", into => "\x{25B6}", from => "\x{25C0}",
57 },
58 ascii => {
59 light => 'O', dark => '@', face => '|', back => '#',
60 h => '-', v => '|', tl => '+', tr => '+', bl => '+', br => '+', td => '+', tu => '+',
61 lt => '+', rt => '+', x => '+', ankh => '+', turn_a => '-.', turn_b => '|', turn_c => "-'",
62 turn_d => '.-', turn_e => '|', turn_f => "'-", into => '>', from => '<',
63 },
64 );
65  
66 75 %SIGN = (26 => 'X', 27 => '~', 28 => 'III', 29 => 'II', 30 => 'I');
67 75 %OTHER = (light => 'dark', dark => 'light');
68 75 for my $h (1 .. 30) {
69 2250 my $row = int(($h - 1) / 10);
70 2250 $ROW_OF{$h} = $row;
71 2250 ▶ $COL_OF{$h} = $row == 1 ? 20 - $h : ($h - 1) % 10;
Branch: 1 branch
BranchTrueFalseTotal
$row == 1 ? : 750 1500 2250
72 }
73 }
74  
75 75 has game => (is => 'rw');
76  
77 75 has [qw/in out/] => (is => 'rw');
78  
79 75 has [qw/interactive colour unicode picking/] => (is => 'rw');
80  
81 75 has mode => (is => 'rw', default => 'bot');
82  
83 75 has side => (is => 'rw', default => 'light');
84  
85 75 has level => (is => 'rw');
86  
87 75 has rules => (is => 'rw', default => 'kendall');
88  
89 75 has pieces => (is => 'rw', default => 5);
90  
91 75 has first => (is => 'rw', default => 'light');
92  
93 75 has seed => (is => 'rw');
94  
95 75 has pace => (is => 'rw');
96  
97 75 has save_file => (is => 'rw');
98  
99 75 has record => (is => 'rw');
100  
101 75 has keysource => (is => 'rw');
102  
103 75 has history => (is => 'rw');
104  
105 75 has sleeper => (is => 'rw');
106  
107 75 has [qw/_keyboard _screen/] => (is => 'rw');
108  
109 75 has _events => (is => 'rw', private => 1);
110  
111 75 has _told => (is => 'rw', private => 1);
112  
113 75 has _cursor => (is => 'rw', private => 1);
114  
115 75 has _note => (is => 'rw', private => 1);
116  
117 927 ▶sub BUILD {
Subroutine BUILD: called CC=34 SCAR=35.6
Pod undocumented
118 927 my ($self) = @_;
119 927 ▶ $self->in(\*STDIN) unless $self->in;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in 62 865 927
120 927 ▶ $self->out(\*STDOUT) unless $self->out;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out 62 865 927
121 927 ▶ $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->interactive 62 865 927
-t $self->in ? : 0 62 62
122 927 ▶ $self->colour($self->interactive && !Game::Terminal::Kit::Screen::no_colour() ? 1 : 0) unless defined $self->colour;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->colour 51 876 927
$self->interactive && !Game::Terminal::Kit::Screen::no_colour() ? : 0 51 51
Condition33%1/3
$self->interactive and not Game::Terminal::Kit::Screen::no_colour()
!ll&&!rl&&r
5100
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
123 927 ▶ $self->unicode($self->interactive ? 1 : 0) unless defined $self->unicode;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->unicode 52 875 927
$self->interactive ? : 0 52 52
124 927 ▶ $self->_keyboard(Game::Terminal::Kit::Keys->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->keysource ? : 40 887 927
125 in => $self->in,
126 ($self->keysource ? (keysource => $self->keysource) : ()),
127 ));
128 927 ▶ $self->_screen(Game::Terminal::Kit::Screen->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->unicode ? : 406 521 927
129 out => $self->out,
130 interactive => $self->interactive,
131 colour => $self->colour,
132 ascii => $self->unicode ? 0 : 1,
133 ));
134 927 ▶ $self->picking($self->interactive ? 1 : 0) unless defined $self->picking;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->picking 53 874 927
$self->interactive ? : 0 53 53
135 927 ▶ $self->picking(0) unless $self->_keyboard->keys_available;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_keyboard->keys_available 887 40 927
136 927 ▶ $self->pace($self->interactive && !$self->keysource ? 1 : 0) unless defined $self->pace;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->pace 51 876 927
$self->interactive && !$self->keysource ? : 0 51 51
Condition33%1/3
$self->interactive and not $self->keysource
!ll&&!rl&&r
5100
MC/DC0%0/2
$self->interactive and not $self->keysource
$self->interactive not $self->keysource
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not $self->keysource
ABresult
0X0
100
111
137  
138 927 ▶ Carp::croak("Game::Senet::Terminal: mode is bot, hotseat or watch, not '" . $self->mode . "'")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->mode =~ /\A(?:bot|hotseat|watch)\z/ 1 926 927
139 unless $self->mode =~ /\A(?:bot|hotseat|watch)\z/;
140 926 ▶ Carp::croak("Game::Senet::Terminal: side is light or dark, not '" . $self->side . "'")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->side =~ /\A(?:light|dark)\z/ 1 925 926
141 unless $self->side =~ /\A(?:light|dark)\z/;
142 925 ▶ Carp::croak("Game::Senet::Terminal: first is light or dark, not '" . $self->first . "'")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->first =~ /\A(?:light|dark)\z/ 1 924 925
143 unless $self->first =~ /\A(?:light|dark)\z/;
144 924 ▶ Carp::croak('Game::Senet::Terminal: pieces is 5 or 7')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->pieces =~ /\A[57]\z/ 1 923 924
145 unless $self->pieces =~ /\A[57]\z/;
146 923 ▶ Carp::croak('Game::Senet::Terminal: pace is a number of seconds, 0 or more')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->pace =~ /\A\d+(?:\.\d+)?\z/ 2 921 923
147 unless $self->pace =~ /\A\d+(?:\.\d+)?\z/;
148  
149 921 ▶ my $variant = $self->game ? $self->game->variant : $self->_variant;
Branch: 1 branch
BranchTrueFalseTotal
$self->game ? : 856 65 921
150 920 my @levels = Game::Senet::Bot->levels($variant);
151 920 ▶ $self->level($levels[-1]) unless defined $self->level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->level 900 20 920
152 920 ▶ Carp::croak('Game::Senet::Terminal: level is a whole number from 1')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->level =~ /\A[1-9][0-9]*\z/ 1 919 920
153 unless $self->level =~ /\A[1-9][0-9]*\z/;
154 919 ▶ $self->level($levels[-1]) if $self->level > $levels[-1];
Branch: 1 branch
BranchTrueFalseTotal
if $self->level > $levels[-1] 2 917 919
155  
156 919 ▶ $self->seed($self->_system_seed) unless defined $self->seed;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->seed 816 103 919
157 919 $self->_events([]);
158 919 $self->_told(0);
159 919 $self->_cursor(0);
160 919 ▶ if ($self->game) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->game) { } 856 63 919
161 856 $self->_told(scalar @{ $self->game->log });
162 }
163 else {
164 63 $self->game($self->_fresh_game);
165 }
166 919 ▶ $self->history($self->_new_history) unless $self->history;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->history 912 7 919
167 919 ▶ $self->history->name('senet') unless defined $self->history->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->history->name 0 919 919
168 919 $self->history->version($VERSION);
169 919 $self->history->start($self->game);
170 919 ▶ $self->save_file($self->record) if defined $self->record && !defined $self->save_file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->record and not defined $self->save_file 1 918 919
Condition66%2/3
defined $self->record and not defined $self->save_file
!ll&&!rl&&r
91801
MC/DC50%1/2
defined $self->record and not defined $self->save_file
defined $self->record not defined $self->save_file
Truth table66%2/3
A and not(B)
A= defined $self->recordB= not defined $self->save_file
ABresult
0X0
100
111
171 919 ▶ $self->history->file($self->save_file) if defined $self->save_file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->save_file 14 905 919
172  
173 919 $self->_screen->utf8->flush_on;
174 919 return;
175 }
176  
177 816 ▶sub _system_seed {
Subroutine _system_seed: called CC=3 SCAR=11.3
178 816 my $bytes = '';
179 816 ▶ if (open my $fh, '<:raw', '/dev/urandom') {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<:raw", "/dev/urandom") 816 0 816
180 816 read $fh, $bytes, 16;
181 816 close $fh;
182 }
183 816 ▶ return length $bytes == 16 ? $bytes : Digest::SHA::sha256(join '|', 'senet', $$, time, rand);
Branch: 1 branch
BranchTrueFalseTotal
length $bytes == 16 ? : 816 0 816
184 }
185  
186 129 ▶sub _variant {
Subroutine _variant: called CC=2 SCAR=7.0
187 129 my ($self) = @_;
188 129 my $rules = $self->rules;
189 129 ▶ return $rules if ref $rules;
Branch: 1 branch
BranchTrueFalseTotal
if ref $rules 0 129 129
190 129 return Game::Senet::Variant->named($rules, pieces => $self->pieces);
191 }
192  
193 918 ▶sub _new_history {
Subroutine _new_history: called CC=1 SCAR=0.0
194 return Game::Terminal::Kit::History->new(
195 name => 'senet',
196 version => $VERSION,
197 1181 ▶ save => sub { $_[0]->to_text },
Subroutine __ANON__: called CC=1 SCAR=0.0
198 9 ▶ load => sub { Game::Senet->from_text($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
199 918 );
200 }
201  
202 64 ▶sub _fresh_game {
Subroutine _fresh_game: called CC=1 SCAR=0.0
203 64 my ($self) = @_;
204 64 return Game::Senet->new(seed => $self->seed, rules => $self->_variant, first => $self->first);
205 }
206  
207 311988 ▶sub _paint {
Subroutine _paint: called CC=2 SCAR=7.1
208 311988 my ($self, $text, $style) = @_;
209 311988 ▶ return $text unless defined $style;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $style 0 311988 311988
210 311988 return $self->_screen->paint($text, $STYLE{$style});
211 }
212  
213 2434 ▶sub _raw { $_[0]->_keyboard->raw }
Subroutine _raw: called CC=1 SCAR=0.0
214  
215 136026 ▶sub _glyph { $GLYPH{ $_[0]->unicode ? 'wide' : 'ascii' }{ $_[1] } }
Subroutine _glyph: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->unicode ? : 55377 80649 136026
216  
217 1300 ▶sub _event {
Subroutine _event: called CC=1 SCAR=0.0
218 1300 my ($self, $side, $text) = @_;
219 1300 push @{ $self->_events }, { side => $side, text => $text };
220 1300 return;
221 }
222  
223 3 ▶sub events { [ map { $_->{text} } @{ $_[0]->_events } ] }
Subroutine events: called CC=1 SCAR=0.0
Pod documented
224  
225 2492 ▶sub _person {
Subroutine _person: called CC=4 SCAR=13.9
226 2492 my ($self, $side) = @_;
227 2492 ▶ return 0 if $self->mode eq 'watch';
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode eq "watch" 1820 672 2492
228 672 ▶ return 1 if $self->mode eq 'hotseat';
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode eq "hotseat" 113 559 672
229 559 ▶ return $side eq $self->side ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$side eq $self->side ? : 283 276 559
230 }
231  
232 4216 ▶sub _who {
Subroutine _who: called CC=3 SCAR=11.0
233 4216 my ($self, $side) = @_;
234 4216 ▶ return ucfirst $side if $self->mode ne 'bot';
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode ne "bot" 3513 703 4216
235 703 ▶ return $side eq $self->side ? 'You' : ucfirst $side;
Branch: 1 branch
BranchTrueFalseTotal
$side eq $self->side ? : 367 336 703
236 }
237  
238 2939 ▶sub sticks_text {
Subroutine sticks_text: called CC=3 SCAR=11.0
Pod documented
239 2939 my ($self, $sticks) = @_;
240 2939 ▶ return '[ ' . join(' ', map { $self->_paint($self->_glyph($_ ? 'face' : 'back'), $_ ? 'face' : 'back') } @$sticks) . ' ]';
Branch: 2 branches
BranchTrueFalseTotal
$_ ? : 5880 5796 11676
$_ ? : 5880 5796 11676
241 }
242  
243 2935 ▶sub roll_words {
Subroutine roll_words: called CC=4 SCAR=13.9
Pod documented
244 2935 my ($self, $roll, $again, $bound) = @_;
245 2935 ▶ my $words = $roll == 5 ? 'no light face: a roll of 5' : "a roll of $roll";
Branch: 1 branch
BranchTrueFalseTotal
$roll == 5 ? : 215 2720 2935
246 2935 ▶ $words .= ', and throws again' if $again;
Branch: 1 branch
BranchTrueFalseTotal
if $again 1128 1807 2935
247 2935 ▶ $words .= ', for the piece on 26' if $bound;
Branch: 1 branch
BranchTrueFalseTotal
if $bound 1 2934 2935
248 2935 return $words;
249 }
250  
251 1272 ▶sub _what_it_does {
Subroutine _what_it_does: called CC=7 SCAR=19.5
252 1272 my ($self, $entry, $rules) = @_;
253 1272 my @does;
254 1272 ▶ push @does, 'a backward move: nothing can go forward' if $entry->{back};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"back"} 67 1205 1272
255 1272 ▶ push @does, 'swaps with ' . $OTHER{ $entry->{side} } if $entry->{swap};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"swap"} 254 1018 1272
256 1272 ▶ if ($entry->{walk}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"walk"}) 15 1257 1272
257 15 my ($from, $to) = split /-/, $entry->{move};
258 15 ▶ push @does, ($from == 26 ? 'into the House of Water' : 'out of the water') . ": back to $to";
Branch: 1 branch
BranchTrueFalseTotal
$from == 26 ? : 11 4 15
259 }
260 1272 ▶ push @does, 'bears off' if $entry->{off};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"off"} 31 1241 1272
261 1272 my (undef, $to) = split /-/, $entry->{move};
262 1272 ▶ push @does, 'onto the House of Happiness' if $to eq '26';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq 26 48 1224 1272
263 1272 return @does;
264 }
265  
266 1235 ▶sub _briefly {
Subroutine _briefly: called CC=7 SCAR=19.5
267 1235 my ($self, $entry) = @_;
268 1235 my ($from, $to) = split /-/, $entry->{move};
269 1235 my @does;
270 1235 ▶ push @does, 'back' if $entry->{back};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"back"} 66 1169 1235
271 1235 ▶ push @does, 'swaps' if $entry->{swap};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"swap"} 216 1019 1235
272 1235 ▶ push @does, ($from == 26 ? 'into the water' : 'out of the water') . ", to $to" if $entry->{walk};
Branch: 2 branches
BranchTrueFalseTotal
if $entry->{"walk"} 24 1211 1235
$from == 26 ? : 16 8 24
273 1235 ▶ push @does, 'bears off' if $entry->{off};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"off"} 63 1172 1235
274 1235 ▶ push @does, 'onto the House of Happiness' if $to eq '26';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq 26 85 1150 1235
275 1235 return @does;
276 }
277  
278 1299 ▶sub _tell {
Subroutine _tell: called CC=10 SCAR=23.1
279 1299 my ($self, $pause) = @_;
280 1299 my $game = $self->game;
281 1299 my $log = $game->log;
282 1299 my $told = $self->_told;
283 1299 ▶ while ($told < @$log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($told < @$log) 1256 1299 2555
284 1256 my $entry = $log->[ $told++ ];
285 1256 $self->_event($entry->{side}, $self->_describe($entry));
286 1256 $self->_told($told);
287 1256 ▶ my $slow = !defined $entry->{move} || !$self->_person($entry->{side});
Condition100%3/3
defined $entry->{'move'} && $self->_person($entry->{'side'})
!ll&&!rl&&r
351048173
MC/DC100%2/2
defined $entry->{'move'} && $self->_person($entry->{'side'})
defined $entry->{'move'} $self->_person($entry->{'side'})
Truth table100%3/3
A && B
A= defined $entry->{'move'}B= $self->_person($entry->{'side'})
ABresult
0X0
100
111
288 1256 ▶ if ($pause && $slow && $self->_raw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pause and $slow and $self->_raw) 140 1116 1256
Condition83%5/6
$pause and $slow and $self->_raw
!ll&&!rl&&r
173943140
$pause and $slow
!ll&&!rl&&r
01731083
MC/DC66%2/3
$pause and $slow and $self->_raw
$pause $slow $self->_raw
Truth table75%3/4
A and B and C
A= $pauseB= $slowC= $self->_raw
ABCresult
0XX0
10X0
1100
1111
289 140 $self->show('wait');
290 140 $self->_wait;
291 }
292 }
293 1299 my $turn = $game->turn;
294 1299 ▶ if ($turn && $turn->{bound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($turn and $turn->{"bound"}) 17 1282 1299
Condition100%3/3
$turn and $turn->{"bound"}
!ll&&!rl&&r
11127117
MC/DC100%2/2
$turn and $turn->{"bound"}
$turn $turn->{"bound"}
Truth table100%3/3
A and B
A= $turnB= $turn->{"bound"}
ABresult
0X0
100
111
295 17 my $last = $self->_events->[-1];
296 $self->_event($turn->{side}, $self->_who($turn->{side}) . ' throws again for the piece on 26.')
297 17 ▶ unless $last && $last->{text} =~ /for the piece on 26/;
Branch: 1 branch
BranchTrueFalseTotal
unless $last and $last->{"text"} =~ /for the piece on 26/ 17 0 17
Condition33%1/3
$last and $last->{"text"} =~ /for the piece on 26/
!ll&&!rl&&r
0170
MC/DC0%0/2
$last and $last->{"text"} =~ /for the piece on 26/
$last $last->{"text"} =~ /for the piece on 26/
Truth table33%1/3
A and B
A= $lastB= $last->{"text"} =~ /for the piece on 26/
ABresult
0X0
100
111
298 }
299 1299 $self->_told($told);
300 1299 return;
301 }
302  
303 1270 ▶sub _describe {
Subroutine _describe: called CC=6 SCAR=17.9
304 1270 my ($self, $entry) = @_;
305 1270 my $who = $self->_who($entry->{side});
306 1270 ▶ if (!defined $entry->{move}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $entry->{"move"}) 35 1235 1270
307 return "$who threw " . (defined $entry->{sticks} ? $self->_plain_sticks($entry->{sticks}) . " (a $entry->{roll})" : "a $entry->{roll}")
308 35 ▶ . ' and could not move' . ($entry->{again} ? ': throws again.' : '.');
Branch: 2 branches
BranchTrueFalseTotal
defined $entry->{'sticks'} ? : 34 1 35
$entry->{'again'} ? : 13 22 35
309 }
310 1235 my @does = $self->_briefly($entry);
311 return "$who played " . Game::Senet::Notation::format_display({ %$entry, from => (split /-/, $entry->{move})[0],
312 to => (split /-/, $entry->{move})[1] }, 0)
313 . (@does ? ', ' . join(', ', @does) : '')
314 1235 ▶ . ($entry->{again} ? '; throws again.' : '.');
Branch: 2 branches
BranchTrueFalseTotal
@does ? : 444 791 1235
$entry->{'again'} ? : 470 765 1235
315 }
316  
317 34 ▶sub _plain_sticks {
Subroutine _plain_sticks: called CC=3 SCAR=11.1
318 34 my ($self, $sticks) = @_;
319 34 ▶ return defined $sticks ? join('', map { $_ ? $self->_glyph('face') : $self->_glyph('back') } split //, $sticks) : '';
Branch: 2 branches
BranchTrueFalseTotal
defined $sticks ? : 34 0 34
$_ ? : 71 65 136
320 }
321  
322 273 ▶sub _wait {
Subroutine _wait: called CC=3 SCAR=12.7
323 273 my ($self) = @_;
324 273 my $pace = $self->pace;
325 273 ▶ return unless $pace > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $pace > 0 0 273 273
326 273 ▶ return $self->sleeper->($pace) if $self->sleeper;
Branch: 1 branch
BranchTrueFalseTotal
if $self->sleeper 273 0 273
327 0 select undef, undef, undef, $pace;
328 0 return;
329 }
330  
331 56910 ▶sub candidates {
Subroutine candidates: called CC=1 SCAR=0.0
Pod documented
332 56910 my ($self) = @_;
333 56910 return $self->game->legal;
334 }
335  
336 169983 ▶sub place_of {
Subroutine place_of: called CC=1 SCAR=0.0
Pod documented
337 169983 my ($class, $house) = @_;
338 169983 return ($COL_OF{$house}, $ROW_OF{$house});
339 }
340  
341 55243 ▶sub steer {
Subroutine steer: called CC=9 SCAR=22.0
Pod documented
342 55243 my ($self, $key) = @_;
343 55243 my @moves = $self->candidates;
344 55243 ▶ return $self->_cursor unless @moves;
Branch: 1 branch
BranchTrueFalseTotal
unless @moves 0 55243 55243
345 55243 my $at = $self->_cursor;
346 55243 ▶ $at = $#moves if $at > $#moves;
Branch: 1 branch
BranchTrueFalseTotal
if $at > $#moves 175 55068 55243
347  
348 55243 ▶ if ($key eq 'tab') { $at = Game::Terminal::Kit::Steer::ring(scalar @moves, $at, 1) }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "tab") 8 55235 55243
349 55243 ▶ if ($key eq 'back_tab' || $key eq 'backtab') { $at = Game::Terminal::Kit::Steer::ring(scalar @moves, $at, -1) }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "back_tab" or $key eq "backtab") 1 55242 55243
Condition66%2/3
$key eq "back_tab" or $key eq "backtab"
l!l&&r!l&&!r
0155242
MC/DC50%1/2
$key eq "back_tab" or $key eq "backtab"
$key eq "back_tab" $key eq "backtab"
Truth table66%2/3
A or B
A= $key eq "back_tab"B= $key eq "backtab"
ABresult
1X1
011
000
350 55243 ▶ if ($key =~ /\A[1-7]\z/ && $key <= @moves) { $at = $key - 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\A[1-7]\z/ and $key <= @moves) 3250 51993 55243
Condition100%3/3
$key =~ /\A[1-7]\z/ and $key <= @moves
!ll&&!rl&&r
5199213250
MC/DC100%2/2
$key =~ /\A[1-7]\z/ and $key <= @moves
$key =~ /\A[1-7]\z/ $key <= @moves
Truth table100%3/3
A and B
A= $key =~ /\A[1-7]\z/B= $key <= @moves
ABresult
0X0
100
111
351  
352 55243 ▶ if (my ($dx, $dy) = Game::Terminal::Kit::Steer::way($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = Game::Terminal::Kit::Steer::way($key)) 51983 3260 55243
353 51983 my @points = map { [ $self->place_of($_->from) ] } @moves;
354 51983 $at = Game::Terminal::Kit::Steer::axis(\@points, $at, $dx, $dy);
355 }
356 55243 $self->_cursor($at);
357 55243 return $at;
358 }
359  
360 2983 ▶sub _cells_after {
Subroutine _cells_after: called CC=7 SCAR=19.5
361 2983 my ($self, $move) = @_;
362 2983 my $game = $self->game;
363 2983 my (%cell, %home, %mark);
364 2983 $cell{$_} = $game->at($_) for 1 .. 30;
365 2983 $home{$_} = $game->home($_) for qw(light dark);
366 2983 ▶ return (\%cell, \%home, \%mark) unless $move;
Branch: 1 branch
BranchTrueFalseTotal
unless $move 1868 1115 2983
367  
368 1115 my $side = $move->side;
369 1115 $cell{ $move->from } = undef;
370 1115 ▶ if ($move->off) {
Branch: 1 branch
BranchTrueFalseTotal
if ($move->off) { } 34 1081 1115
371 34 $home{$side}++;
372 34 $mark{"home $side"} = 'target';
373 }
374 else {
375 1081 ▶ if ($move->swap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($move->swap) 191 890 1081
376 191 $cell{ $move->from } = $OTHER{$side};
377 191 $mark{ $move->from } = 'from';
378 }
379 1081 $cell{ $move->to } = $side;
380 1081 $mark{ $move->to } = 'target';
381 }
382 1115 ▶ $mark{ $move->from } //= 'cursor';
Condition100%2/2
$mark{$move->from} //= "cursor"
l!l
191924
MC/DC100%1/1
$mark{$move->from} //= "cursor"
$mark{$move->from}
Truth table100%2/2
A
A= $mark{$move->from}
Aresult
11
00
383 1115 return (\%cell, \%home, \%mark);
384 }
385  
386 89524 ▶sub _marked {
Subroutine _marked: called CC=4 SCAR=13.9
387 89524 my ($self, $text, $mark) = @_;
388 89524 ▶ my ($open, $close) = Game::Terminal::Kit::Frame::brackets($mark // 'plain');
Condition100%2/2
$mark // "plain"
l!l
707782447
MC/DC100%1/1
$mark // "plain"
$mark
Truth table100%2/2
A
A= $mark
Aresult
11
00
389 89524 ▶ return $self->_paint($open . $text . $close, $mark) if $mark && $mark ne 'recent';
Branch: 1 branch
BranchTrueFalseTotal
if $mark and $mark ne "recent" 2230 87294 89524
Condition100%3/3
$mark and $mark ne "recent"
!ll&&!rl&&r
8244748472230
MC/DC100%2/2
$mark and $mark ne "recent"
$mark $mark ne "recent"
Truth table100%3/3
A and B
A= $markB= $mark ne "recent"
ABresult
0X0
100
111
390 87294 return $open . $text . $close;
391 }
392  
393 89490 ▶sub _house_top {
Subroutine _house_top: called CC=3 SCAR=11.0
394 89490 my ($self, $h) = @_;
395 89490 ▶ my $sign = $h == 15 ? $self->_glyph('ankh') : $SIGN{$h} // '';
Branch: 1 branch
BranchTrueFalseTotal
$h == 15 ? : 2983 86507 89490
Condition100%2/2
$SIGN{$h} // ""
l!l
1491571592
MC/DC100%1/1
$SIGN{$h} // ""
$SIGN{$h}
Truth table100%2/2
A
A= $SIGN{$h}
Aresult
11
00
396 89490 my $number = sprintf '%-2s ', $h;
397 89490 my $pad = 3 - length $sign;
398 89490 return $self->_paint($number, 'label') . $self->_paint($sign, 'sign') . (' ' x $pad);
399 }
400  
401 89490 ▶sub _house_piece {
Subroutine _house_piece: called CC=4 SCAR=13.9
402 89490 my ($self, $who, $mark) = @_;
403 89490 ▶ my $painted = $mark && $mark ne 'recent';
Condition100%3/3
$mark && $mark ne 'recent'
!ll&&!rl&&r
8244748472196
MC/DC100%2/2
$mark && $mark ne 'recent'
$mark $mark ne 'recent'
Truth table100%3/3
A && B
A= $markB= $mark ne 'recent'
ABresult
0X0
100
111
404 89490 ▶ my $inside = !defined $who ? ' ' : $painted ? $self->_glyph($who) : $self->_paint($self->_glyph($who), $who);
Branch: 2 branches
BranchTrueFalseTotal
!defined($who) ? : 64006 25484 89490
$painted ? : 1272 24212 25484
405 89490 return ' ' . $self->_marked($inside, $mark) . ' ';
406 }
407  
408 11932 ▶sub _border {
Subroutine _border: called CC=1 SCAR=0.0
409 11932 my ($self, $left, $mid, $right) = @_;
410 11932 ▶ my $g = sub { $self->_glyph($_[0]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
411 11932 return $self->_paint($g->($left) . join($g->($mid), ($g->('h') x 6) x 10) . $g->($right), 'grid');
412 }
413  
414 8949 ▶sub _row_houses {
Subroutine _row_houses: called CC=3 SCAR=11.0
415 8949 my ($row) = @_;
416 8949 ▶ return $row == 0 ? (1 .. 10) : $row == 1 ? (reverse 11 .. 20) : (21 .. 30);
Branch: 2 branches
BranchTrueFalseTotal
$row == 0 ? : 2983 5966 8949
$row == 1 ? : 2983 2983 5966
417 }
418  
419 5966 ▶sub _home_line {
Subroutine _home_line: called CC=4 SCAR=13.9
420 5966 my ($self, $side, $home, $mark) = @_;
421 5966 my @shown = map { $self->_paint($self->_glyph($side), $side) } 1 .. $home->{$side};
422 $shown[-1] = $self->_marked($self->_glyph($side), 'target')
423 5966 ▶ if @shown && $mark->{"home $side"};
Branch: 1 branch
BranchTrueFalseTotal
if @shown and $$mark{"home $side"} 34 5932 5966
Condition100%3/3
@shown and $$mark{"home $side"}
!ll&&!rl&&r
2195373734
MC/DC100%2/2
@shown and $$mark{"home $side"}
@shown $$mark{"home $side"}
Truth table100%3/3
A and B
A= @shownB= $$mark{"home $side"}
ABresult
0X0
100
111
424 5966 ▶ return sprintf ' %s home: %s', $self->_paint(sprintf('%-5s', $side), $side),
Branch: 1 branch
BranchTrueFalseTotal
@shown ? : 3771 2195 5966
425 @shown ? join(' ', @shown) : $self->_paint('none', 'quiet');
426 }
427  
428 2983 ▶sub board_lines {
Subroutine board_lines: called CC=8 SCAR=20.8
Pod documented
429 2983 my ($self, $move) = @_;
430 2983 my $game = $self->game;
431 2983 my ($cell, $home, $mark) = $self->_cells_after($move);
432 2983 my %recent;
433 2983 for my $entry (@{ $game->log }) {
434 294013 ▶ next unless defined $entry->{move};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry->{"move"} 3207 290806 294013
435 290806 my (undef, $to) = split /-/, $entry->{move};
436 290806 $recent{ $entry->{side} } = $to;
437 }
438 2983 for my $side (keys %recent) {
439 5683 my $to = $recent{$side};
440 5683 ▶ next if $to eq 'off';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "off" 315 5368 5683
441 5368 ▶ $mark->{$to} //= 'recent' if defined $cell->{$to} && $cell->{$to} eq $side;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cell->{$to} and $cell->{$to} eq $side 4853 515 5368
Condition100%5/5
defined $cell->{$to} and $cell->{$to} eq $side
!ll&&!rl&&r
3331824853
$mark->{$to} //= "recent"
l!l
64847
MC/DC100%2/2
defined $cell->{$to} and $cell->{$to} eq $side
defined $cell->{$to} $cell->{$to} eq $side
MC/DC100%1/1
$mark->{$to} //= "recent"
$mark->{$to}
Truth table100%3/3
A and B
A= defined $cell->{$to}B= $cell->{$to} eq $side
ABresult
0X0
100
111
Truth table100%2/2
A
A= $mark->{$to}
Aresult
11
00
442 }
443  
444 2983 my $v = $self->_paint($self->_glyph('v'), 'grid');
445 8949 ▶ my $row_lines = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
446 8949 my ($row) = @_;
447 8949 my @houses = _row_houses($row);
448 8949 my $top = $v . join($v, map { $self->_house_top($_) } @houses) . $v;
449 8949 my $low = $v . join($v, map { $self->_house_piece($cell->{$_}, $mark->{$_}) } @houses) . $v;
450 8949 return ($top, $low);
451 2983 };
452 2983 my ($r0a, $r0b) = $row_lines->(0);
453 2983 my ($r1a, $r1b) = $row_lines->(1);
454 2983 my ($r2a, $r2b) = $row_lines->(2);
455 2983 ▶ my $g = sub { $self->_paint($self->_glyph($_[0]), 'grid') };
Subroutine __ANON__: called CC=1 SCAR=0.0
456 2983 my $sp = ' ';
457  
458 return [
459 2983 $self->_home_line('dark', $home, $mark),
460 '',
461 $sp . $self->_border('tl', 'td', 'tr'),
462 $sp . $r0a,
463 $sp . $r0b . $g->('into') . $g->('turn_a'),
464 $sp . $self->_border('lt', 'x', 'rt') . ' ' . $g->('turn_b'),
465 ' ' . $g->('turn_d') . $g->('from') . $r1a . $g->('from') . $g->('turn_c'),
466 ' ' . $g->('turn_e') . ' ' . $r1b,
467 ' ' . $g->('turn_e') . ' ' . $self->_border('lt', 'x', 'rt'),
468 ' ' . $g->('turn_f') . $g->('into') . $r2a . $g->('into') . $self->_paint('off', 'grid'),
469 $sp . $r2b,
470 $sp . $self->_border('bl', 'tu', 'br'),
471 '',
472 $self->_home_line('light', $home, $mark),
473 ];
474 }
475  
476 2947 ▶sub _shield_lines {
Subroutine _shield_lines: called CC=15 SCAR=27.1
477 2947 my ($self) = @_;
478 2947 my $game = $self->game;
479 2947 my $variant = $game->variant;
480 2947 my @lines;
481 2947 for my $side (qw(light dark)) {
482 5894 my (@runs, $run);
483 5894 for my $h (1 .. 30) {
484 176820 ▶ if (($game->at($h) // '') eq $side) { push @{ $run //= [] }, $h; next }
Branch: 1 branch
BranchTrueFalseTotal
if (($game->at($h) // "") eq $side) 25341 151479 176820
Condition100%4/4
$game->at($h) // ""
l!l
50682126138
$run //= []
l!l
594619395
MC/DC100%1/1
$game->at($h) // ""
$game->at($h)
MC/DC100%1/1
$run //= []
$run
Truth table100%2/2
A
A= $game->at($h)
Aresult
11
00
Truth table100%2/2
A
A= $run
Aresult
11
00
485 151479 ▶ push @runs, $run if $run;
Branch: 1 branch
BranchTrueFalseTotal
if $run 19359 132120 151479
486 151479 undef $run;
487 }
488 5894 ▶ push @runs, $run if $run;
Branch: 1 branch
BranchTrueFalseTotal
if $run 36 5858 5894
489 5894 my (@kept, @blocks);
490 5894 for my $r (grep { @$_ >= 2 } @runs) {
491 4621 ▶ push @kept, $variant->protect eq 'run' ? @$r : $variant->protect eq 'ends' ? ($r->[0], $r->[-1]) : ();
Branch: 2 branches
BranchTrueFalseTotal
$variant->protect eq 'run' ? : 625 3996 4621
$variant->protect eq 'ends' ? : 3996 0 3996
492 4621 ▶ push @blocks, "$r->[0]-$r->[-1]" if $variant->blockade && @$r >= $variant->blockade;
Branch: 1 branch
BranchTrueFalseTotal
if $variant->blockade and @$r >= $variant->blockade 4208 413 4621
Condition66%2/3
$variant->blockade and @$r >= $variant->blockade
!ll&&!rl&&r
04134208
MC/DC50%1/2
$variant->blockade and @$r >= $variant->blockade
$variant->blockade @$r >= $variant->blockade
Truth table66%2/3
A and B
A= $variant->blockadeB= @$r >= $variant->blockade
ABresult
0X0
100
111
493 }
494 5894 ▶ my @said = ((@kept ? 'protected ' . join(' ', @kept) : 'nothing protected'),
Branch: 2 branches
BranchTrueFalseTotal
@kept ? : 3748 2146 5894
@blocks ? : 3464 2430 5894
495 (@blocks ? 'blockades ' . join(' ', @blocks) : ()));
496 5894 push @lines, ' ' . $self->_paint(sprintf('%-5s ', $side) . join('; ', @said), 'quiet');
497 }
498 2947 return @lines;
499 }
500  
501 2947 ▶sub _sticks_line {
Subroutine _sticks_line: called CC=4 SCAR=13.9
502 2947 my ($self) = @_;
503 2947 my $game = $self->game;
504 2947 ▶ return () if $game->is_over || !defined $game->roll;
Branch: 1 branch
BranchTrueFalseTotal
if $game->is_over or not defined $game->roll 18 2929 2947
Condition100%3/3
$game->is_over or not defined $game->roll
l!l&&r!l&&!r
1622929
MC/DC100%2/2
$game->is_over or not defined $game->roll
$game->is_over not defined $game->roll
Truth table100%3/3
A or not(B)
A= $game->is_overB= not defined $game->roll
ABresult
1X1
011
000
505 2929 my $turn = $game->turn;
506 return (sprintf(' %s threw %d %s %s', $self->_who($game->side), $game->throw,
507 $self->sticks_text($game->sticks), $self->roll_words($game->roll, $turn->{extra})),
508 2929 ▶ ($turn->{bound} ? ' ' . $self->_paint('This throw is for the piece on 26: it alone may move.', 'key') : ()));
Branch: 1 branch
BranchTrueFalseTotal
$turn->{'bound'} ? : 209 2720 2929
509 }
510  
511 2947 ▶sub _result_line {
Subroutine _result_line: called CC=4 SCAR=14.0
512 2947 my ($self) = @_;
513 2947 ▶ my $result = $self->game->result or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $result = $self->game->result or return () 16 2931 2947
514 16 ▶ return ' ' . $self->_paint('The game ran its full length with no end. It is drawn.', 'bad') if $result->is_draw;
Branch: 1 branch
BranchTrueFalseTotal
if $result->is_draw 0 16 16
515 16 my $winner = $result->winner;
516 16 ▶ return ' ' . $self->_paint(sprintf('%s won: %s resigned.', ucfirst $winner, $result->loser), 'good')
Branch: 1 branch
BranchTrueFalseTotal
if $result->how eq "resign" 0 16 16
517 if $result->how eq 'resign';
518 16 my $home = $result->home;
519 return ' ' . $self->_paint(sprintf('%s won, all %d home to %d, in %d plies.',
520 16 ucfirst $winner, $home->{$winner}, $home->{ $result->loser }, $result->plies), 'good');
521 }
522  
523 2939 ▶sub _event_lines {
Subroutine _event_lines: called CC=3 SCAR=11.0
524 2939 my ($self) = @_;
525 2939 my @recent = @{ $self->_events };
526 2939 ▶ @recent = @recent[ -4 .. -1 ] if @recent > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @recent > 4 405 2534 2939
527 2939 ▶ return map { ' ' . $self->_paint($_->{text}, $_->{side} || 'quiet') } @recent;
Condition100%2/2
$_->{'side'} || 'quiet'
l!l
170125
MC/DC100%1/1
$_->{'side'} || 'quiet'
$_->{'side'}
Truth table100%2/2
A
A= $_->{'side'}
Aresult
11
00
528 }
529  
530 1272 ▶sub readout {
Subroutine readout: called CC=2 SCAR=6.9
Pod documented
531 1272 my ($self, $move) = @_;
532 1272 my %entry = (side => $move->side, move => Game::Senet::Notation::format_move($move),
533 back => $move->back, swap => $move->swap, walk => $move->walk, off => $move->off);
534 1272 my @does = $self->_what_it_does(\%entry);
535 1272 ▶ return $self->_paint(Game::Senet::Notation::format_display($move, 0), 'key') . (@does ? ' ' . join(', ', @does) : '');
Branch: 1 branch
BranchTrueFalseTotal
@does ? : 409 863 1272
536 }
537  
538 2040 ▶sub _legend {
Subroutine _legend: called CC=4 SCAR=13.9
539 2040 my ($self, $mode) = @_;
540 2040 ▶ my $k = sub { $self->_paint($_[0], 'key') };
Subroutine __ANON__: called CC=1 SCAR=0.0
541 2040 ▶ return ' ' . join(' ', $k->('enter') . ' leave', $k->('n') . ' new game', $k->('u') . ' take back',
Branch: 2 branches
BranchTrueFalseTotal
if $mode eq "ended" 5 2035 2040
$self->history->can_redo ? : 0 5 5
542 ($self->history->can_redo ? $k->('r') . ' play again' : ()), $k->('S') . ' save') if $mode eq 'ended';
543 2035 ▶ return ' ' . $self->_paint('...', 'quiet') if $mode eq 'wait';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "wait" 938 1097 2035
544 1097 return ' ' . join(' ', $k->('arrows') . ' choose', $k->('enter') . ' move',
545 $k->('u') . ' back', $k->('r') . ' again', $k->('S') . ' save', $k->('?') . ' help', $k->('q') . ' leave');
546 }
547  
548 2939 ▶sub screen {
Subroutine screen: called CC=13 SCAR=25.9
Pod documented
549 2939 my ($self, $mode) = @_;
550 2939 ▶ $mode = 'plain' unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 2939 2939
551 2939 my $game = $self->game;
552 2939 my $variant = $game->variant;
553 2939 ▶ my @lines = (
Branch: 2 branches
BranchTrueFalseTotal
$self->mode eq 'bot' ? : 425 2514 2939
$self->mode eq 'hotseat' ? : 2508 6 2514
554 ' ' . $self->_paint('Senet', 'title') . ' '
555 . $self->_paint(join(', ', $variant->describe,
556 ($self->mode eq 'bot' ? 'you are ' . $self->side . ', against level ' . $self->level
557 : $self->mode eq 'hotseat' ? 'two players' : 'level ' . $self->level . ' against itself')), 'quiet'),
558 '',
559 );
560 2939 ▶ if ($mode eq 'help') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "help") 0 2939 2939
561 0 push @lines, map { " $_" } @{ $self->help_lines };
562 0 return \@lines;
563 }
564 2939 ▶ my @moves = $mode eq 'pick' ? $self->candidates : ();
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 'pick' ? : 1097 1842 2939
565 2939 my $at = $self->_cursor;
566 2939 ▶ $at = $#moves if $at > $#moves;
Branch: 1 branch
BranchTrueFalseTotal
if $at > $#moves 1842 1097 2939
567 2939 ▶ my $move = @moves ? $moves[$at] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@moves ? : 1097 1842 2939
568  
569 2939 push @lines, @{ $self->board_lines($move) }, $self->_shield_lines, '';
570 2939 push @lines, $self->_sticks_line, $self->_result_line;
571 2939 ▶ push @lines, ' ' . $self->readout($move) if $move;
Branch: 1 branch
BranchTrueFalseTotal
if $move 1097 1842 2939
572 2939 push @lines, '';
573 2939 push @lines, $self->_event_lines;
574 2939 ▶ push @lines, ' ' . $self->_paint($self->_note, 'bad') if defined $self->_note;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_note 7 2932 2939
575 2939 ▶ push @lines, '', $self->_legend($mode) if $mode eq 'pick' || $mode eq 'ended' || $mode eq 'wait';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "pick" or $mode eq "ended" or $mode eq "wait" 2040 899 2939
Condition100%6/6
$mode eq "pick" or $mode eq "ended" or $mode eq "wait"
l!l&&r!l&&!r
1102938899
$mode eq "pick" or $mode eq "ended"
l!l&&r!l&&!r
109751837
MC/DC100%3/3
$mode eq "pick" or $mode eq "ended" or $mode eq "wait"
$mode eq "pick" $mode eq "ended" $mode eq "wait"
Truth table100%4/4
A or B or C
A= $mode eq "pick"B= $mode eq "ended"C= $mode eq "wait"
ABCresult
1XX1
01X1
0011
0000
576 2939 return \@lines;
577 }
578  
579 442 ▶sub show {
Subroutine show: called CC=1 SCAR=0.0
Pod documented
580 442 my ($self, $mode) = @_;
581 442 $self->_screen->show($self->screen($mode));
582 442 return $self;
583 }
584  
585 0 ▶sub help_lines {
Subroutine help_lines: not called CC=1 SCAR=6.9
Pod documented
586 return [
587 0 'A move is a piece. The sticks say how far it goes, so choosing the piece is',
588 'the whole move. A roll of 1, 4 or 5 throws again.',
589 '',
590 ' arrows, tab walk the pieces that can move',
591 ' 1 to 7 go straight to one of them',
592 ' enter, space move it',
593 ' u take back your last turn and every reply to it',
594 ' r play a turn taken back again',
595 ' n a new game',
596 ' S save the game, to carry on with --resume or watch with --replay',
597 ' q leave (asked twice)',
598 ' enter, q leave, once the game is over',
599 '',
600 'The board shows what the move would leave: [ ] the house the piece leaves,',
601 '< > where it lands, ( ) the house a swapped piece goes back to, and { } the',
602 'last move each side made.',
603 '',
604 'Typing instead: a number from the list, or a move such as 12-15 or 26-off;',
605 'and undo, redo, new, moves, save [FILE], level N, help, quit.',
606 ];
607 }
608  
609 9 ▶sub _enter_raw {
Subroutine _enter_raw: called CC=4 SCAR=14.6
610 9 my ($self) = @_;
611 9 ▶ return 1 if $self->_raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_raw 0 9 9
612 9 ▶ return 0 unless $self->_keyboard->enter_raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_keyboard->enter_raw 0 9 9
613 9 ▶ $self->_screen->hide_cursor->clear unless $self->keysource;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keysource 0 9 9
614 9 return 1;
615 }
616  
617 151 ▶sub pick {
Subroutine pick: called CC=16 SCAR=28.6
Pod documented
618 151 my ($self) = @_;
619 151 my $leaving = 0;
620 151 ▶ $self->_cursor(0) if $self->_cursor > $self->candidates - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_cursor > $self->candidates - 1 0 151 151
621 151 while (1) {
622 164 $self->show('pick');
623 164 my $key = $self->_keyboard->read_key;
624 164 ▶ return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $key or $key eq "eof" or $key eq "interrupt" 2 162 164
Condition66%4/6
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
20162
not defined $key or $key eq "eof"
l!l&&r!l&&!r
20162
MC/DC33%1/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key $key eq "eof" $key eq "interrupt"
Truth table50%2/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
ABCresult
1XX1
01X1
0011
0000
625 162 $self->_note(undef);
626 162 ▶ if ($key eq 'q' || $key eq 'escape') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "q" or $key eq "escape") 11 151 162
Condition66%2/3
$key eq "q" or $key eq "escape"
l!l&&r!l&&!r
110151
MC/DC50%1/2
$key eq "q" or $key eq "escape"
$key eq "q" $key eq "escape"
Truth table66%2/3
A or B
A= $key eq "q"B= $key eq "escape"
ABresult
1X1
011
000
627 11 ▶ return 'quit' if $leaving;
Branch: 1 branch
BranchTrueFalseTotal
if $leaving 5 6 11
628 6 $leaving = 1;
629 6 $self->_note('Press q again to leave the game, or any other key to stay.');
630 6 next;
631 }
632 151 $leaving = 0;
633 151 ▶ if ($key eq 'enter' || $key eq ' ') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "enter" or $key eq " ") 140 11 151
Condition100%3/3
$key eq "enter" or $key eq " "
l!l&&r!l&&!r
139111
MC/DC100%2/2
$key eq "enter" or $key eq " "
$key eq "enter" $key eq " "
Truth table100%3/3
A or B
A= $key eq "enter"B= $key eq " "
ABresult
1X1
011
000
634 140 my @moves = $self->candidates;
635 140 ▶ next unless @moves;
Branch: 1 branch
BranchTrueFalseTotal
unless @moves 0 140 140
636 140 return Game::Senet::Notation::format_move($moves[ $self->_cursor ]);
637 }
638 11 ▶ return 'undo' if $key eq 'u';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "u" 1 10 11
639 10 ▶ return 'redo' if $key eq 'r';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "r" 0 10 10
640 10 ▶ return 'new' if $key eq 'n';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "n" 0 10 10
641 10 ▶ return 'save' if $key eq 'S';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "S" 3 7 10
642 7 ▶ if ($key eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "?") 0 7 7
643 0 $self->show('help');
644 0 $self->_keyboard->read_key;
645 0 next;
646 }
647 7 $self->steer($key);
648 }
649 }
650  
651 5 ▶sub _ended_key {
Subroutine _ended_key: called CC=12 SCAR=27.6
652 5 my ($self) = @_;
653 5 while (1) {
654 5 $self->show('ended');
655 5 my $key = $self->_keyboard->read_key;
656 5 ▶ return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $key or $key eq "eof" or $key eq "interrupt" 0 5 5
Condition33%2/6
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
005
not defined $key or $key eq "eof"
l!l&&r!l&&!r
005
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
657 5 ▶ return 'new' if $key eq 'n';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "n" 1 4 5
658 4 ▶ return 'undo' if $key eq 'u';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "u" 0 4 4
659 4 ▶ return 'redo' if $key eq 'r';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "r" 0 4 4
660 4 ▶ return 'save' if $key eq 'S';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "S" 0 4 4
661 4 ▶ return 'quit' if $key eq 'q' || $key eq 'escape' || $key eq 'enter' || $key eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "q" or $key eq "escape" or $key eq "enter" or $key eq " " 4 0 4
Condition77%7/9
$key eq "q" or $key eq "escape" or $key eq "enter" or $key eq " "
l!l&&r!l&&!r
310
$key eq "q" or $key eq "escape" or $key eq "enter"
l!l&&r!l&&!r
211
$key eq "q" or $key eq "escape"
l!l&&r!l&&!r
202
MC/DC0%0/4
$key eq "q" or $key eq "escape" or $key eq "enter" or $key eq " "
$key eq "q" $key eq "escape" $key eq "enter" $key eq " "
Truth table60%3/5
A or B or C or D
A= $key eq "q"B= $key eq "escape"C= $key eq "enter"D= $key eq " "
ABCDresult
1XXX1
01XX1
001X1
00011
00000
662 }
663 }
664  
665 168 ▶sub _say {
Subroutine _say: called CC=2 SCAR=7.1
666 168 my ($self, @lines) = @_;
667 168 ▶ $self->_screen->say(@lines) if @lines;
Branch: 1 branch
BranchTrueFalseTotal
if @lines 168 0 168
668 168 return;
669 }
670  
671 78 ▶sub _read_line {
Subroutine _read_line: called CC=4 SCAR=14.0
672 78 my ($self) = @_;
673 78 my $game = $self->game;
674 78 my $out = $self->out;
675 78 $self->_say(@{ $self->screen('plain') });
676 78 ▶ if (!$game->is_over) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game->is_over) 78 0 78
677 78 my @moves = $self->candidates;
678 78 $self->_say(map { sprintf ' %s %s', $self->_paint($_ + 1, 'key'), $self->readout($moves[$_]) } 0 .. $#moves);
679 }
680 78 ▶ my $line = $self->_keyboard->read_line(
Branch: 1 branch
BranchTrueFalseTotal
$game->is_over ? : 0 78 78
681 $game->is_over ? 'new, undo, or enter to leave> ' : $game->side . ' (' . $game->roll . ')> ', $out);
682 78 ▶ print {$out} "\n" unless $self->interactive;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->interactive 78 0 78
683 78 return $line;
684 }
685  
686 245 ▶sub command {
Subroutine command: called CC=33 SCAR=44.8
Pod documented
687 245 my ($self, $line) = @_;
688 245 my $game = $self->game;
689 245 $self->_note(undef);
690 245 ▶ return 0 unless defined $line && length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and length $line 0 245 245
Condition33%1/3
defined $line and length $line
!ll&&!rl&&r
00245
MC/DC0%0/2
defined $line and length $line
defined $line length $line
Truth table33%1/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
691 245 my ($word, $rest) = split ' ', $line, 2;
692 245 $word = lc $word;
693  
694 245 ▶ return 1 if $word eq 'quit' || $word eq 'q' || $word eq 'exit';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "quit" or $word eq "q" or $word eq "exit" 54 191 245
Condition66%4/6
$word eq "quit" or $word eq "q" or $word eq "exit"
l!l&&r!l&&!r
540191
$word eq "quit" or $word eq "q"
l!l&&r!l&&!r
540191
MC/DC33%1/3
$word eq "quit" or $word eq "q" or $word eq "exit"
$word eq "quit" $word eq "q" $word eq "exit"
Truth table50%2/4
A or B or C
A= $word eq "quit"B= $word eq "q"C= $word eq "exit"
ABCresult
1XX1
01X1
0011
0000
695 191 ▶ if ($word eq 'help' || $word eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "help" or $word eq "?") 0 191 191
Condition33%1/3
$word eq "help" or $word eq "?"
l!l&&r!l&&!r
00191
MC/DC0%0/2
$word eq "help" or $word eq "?"
$word eq "help" $word eq "?"
Truth table33%1/3
A or B
A= $word eq "help"B= $word eq "?"
ABresult
1X1
011
000
696 0 $self->_say(map { " $_" } @{ $self->help_lines });
697 0 return 0;
698 }
699 191 ▶ if ($word eq 'new' || $word eq 'n') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "new" or $word eq "n") 1 190 191
Condition66%2/3
$word eq "new" or $word eq "n"
l!l&&r!l&&!r
10190
MC/DC50%1/2
$word eq "new" or $word eq "n"
$word eq "new" $word eq "n"
Truth table66%2/3
A or B
A= $word eq "new"B= $word eq "n"
ABresult
1X1
011
000
700 1 $self->seed(Digest::SHA::sha256($self->seed . 'next'));
701 1 $self->game($self->_fresh_game);
702 1 $self->_events([]);
703 1 $self->_told(0);
704 1 $self->_cursor(0);
705 1 $self->history->start($self->game);
706 1 return 0;
707 }
708 190 ▶ if ($word eq 'undo' || $word eq 'u') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "undo" or $word eq "u") 3 187 190
Condition66%2/3
$word eq "undo" or $word eq "u"
l!l&&r!l&&!r
30187
MC/DC50%1/2
$word eq "undo" or $word eq "u"
$word eq "undo" $word eq "u"
Truth table66%2/3
A or B
A= $word eq "undo"B= $word eq "u"
ABresult
1X1
011
000
709 3 $self->take_back;
710 3 return 0;
711 }
712 187 ▶ if ($word eq 'redo' || $word eq 'r') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "redo" or $word eq "r") 0 187 187
Condition33%1/3
$word eq "redo" or $word eq "r"
l!l&&r!l&&!r
00187
MC/DC0%0/2
$word eq "redo" or $word eq "r"
$word eq "redo" $word eq "r"
Truth table33%1/3
A or B
A= $word eq "redo"B= $word eq "r"
ABresult
1X1
011
000
713 0 $self->play_again;
714 0 return 0;
715 }
716 187 ▶ if ($word eq 'moves') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "moves") 2 185 187
717 $self->_say(map {
718 ' ' . (defined $_->{move}
719 ? Game::Senet::Notation::format_display({ %$_, from => (split /-/, $_->{move})[0], to => (split /-/, $_->{move})[1] }, $_->{again})
720 5 ▶ : Game::Senet::Notation::format_forfeit($_->{roll}, $_->{again}))
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'move'} ? : 5 0 5
721 2 } @{ $game->log });
722 2 return 0;
723 }
724 185 ▶ if ($word eq 'save' || $word eq 'record') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "save" or $word eq "record") 12 173 185
Condition66%2/3
$word eq "save" or $word eq "record"
l!l&&r!l&&!r
120173
MC/DC50%1/2
$word eq "save" or $word eq "record"
$word eq "save" $word eq "record"
Truth table66%2/3
A or B
A= $word eq "save"B= $word eq "record"
ABresult
1X1
011
000
725 12 ▶ my $file = defined $rest && length $rest ? $rest : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $rest && length $rest ? : 1 11 12
Condition66%2/3
defined $rest and length $rest
!ll&&!rl&&r
1101
MC/DC50%1/2
defined $rest and length $rest
defined $rest length $rest
Truth table66%2/3
A and B
A= defined $restB= length $rest
ABresult
0X0
100
111
726 12 ▶ if (!defined $file && $self->_raw) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $file and $self->_raw) 3 9 12
Condition100%3/3
not defined $file and $self->_raw
!ll&&!rl&&r
183
MC/DC100%2/2
not defined $file and $self->_raw
not defined $file $self->_raw
Truth table100%3/3
not(A) and B
A= not defined $fileB= $self->_raw
ABresult
0X0
100
111
727 3 $file = Game::Terminal::Kit::Save::ask_file($self->_keyboard, $self->_screen,
728 default => $self->save_default, head => $self->screen('plain'));
729 3 ▶ return 0 unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 1 2 3
730 }
731 11 $self->save($file);
732 11 return 0;
733 }
734 173 ▶ if ($word eq 'level') {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "level") 0 173 173
735 0 my @levels = Game::Senet::Bot->levels($game->variant);
736 0 ▶ if (defined $rest && $rest =~ /\A\d+\z/ && $rest >= 1 && $rest <= $levels[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1 and $rest <= $levels[-1]) { } 0 0 0
Condition0%0/9
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1 and $rest <= $levels[-1]
!ll&&!rl&&r
000
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1
!ll&&!rl&&r
000
defined $rest and $rest =~ /\A\d+\z/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1 and $rest <= $levels[-1]
defined $rest $rest =~ /\A\d+\z/ $rest >= 1 $rest <= $levels[-1]
Truth table0%0/5
A and B and C and D
A= defined $restB= $rest =~ /\A\d+\z/C= $rest >= 1D= $rest <= $levels[-1]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
737 0 $self->level($rest);
738 0 $self->_event(undef, "The program now plays at level $rest.");
739 }
740 0 else { $self->_note('A level is a number from 1 to ' . $levels[-1] . '.') }
741 0 return 0;
742 }
743 173 ▶ if ($game->is_over) {
Branch: 1 branch
BranchTrueFalseTotal
if ($game->is_over) 0 173 173
744 0 $self->_note('The game is over. Type new, undo or quit.');
745 0 return 0;
746 }
747  
748 173 my $move = $line;
749 173 ▶ if ($line =~ /\A[1-7]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A[1-7]\z/) 35 138 173
750 35 my @moves = $self->candidates;
751 35 ▶ if ($line > @moves) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line > @moves) 0 35 35
752 0 $self->_note('There are only ' . scalar(@moves) . ' moves to choose from.');
753 0 return 0;
754 }
755 35 $move = $moves[ $line - 1 ];
756 }
757 173 ▶ if ($game->play($move)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($game->play($move)) { } 173 0 173
758 173 $self->_cursor(0);
759 173 $self->_tell(1);
760 }
761 else {
762 0 my $error = $game->error;
763 0 ▶ $self->_note($error->code eq 'bad_move'
Branch: 1 branch
BranchTrueFalseTotal
$error->code eq 'bad_move' ? : 0 0 0
764 ? "I do not know '$line'. A move is two houses, like 12-15 or 26-off, or its number in the list."
765 : ucfirst($error->message) . '.');
766 }
767 173 return 0;
768 }
769  
770 4 ▶sub take_back {
Subroutine take_back: called CC=2 SCAR=7.3
Pod documented
771 4 my ($self) = @_;
772 4 $self->_keep;
773 4 my $game = $self->history->undo;
774 4 ▶ unless ($game) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game) 0 4 4
775 0 $self->_note('There is nothing to take back.');
776 0 return 0;
777 }
778 4 $self->swap($game);
779 4 $self->_event(undef, 'Taken back.');
780 4 return 1;
781 }
782  
783 0 ▶sub play_again {
Subroutine play_again: not called CC=2 SCAR=17.9
Pod documented
784 0 my ($self) = @_;
785 0 $self->_keep;
786 0 my $game = $self->history->redo;
787 0 ▶ unless ($game) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game) 0 0 0
788 0 $self->_note('There is nothing to play again.');
789 0 return 0;
790 }
791 0 $self->swap($game);
792 0 $self->_event(undef, 'Played again.');
793 0 return 1;
794 }
795  
796 4 ▶sub _keep {
Subroutine _keep: called CC=2 SCAR=7.1
797 4 my ($self) = @_;
798 4 ▶ $self->history->record($self->game) if $self->mode ne 'watch';
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode ne "watch" 4 0 4
799 4 return;
800 }
801  
802 4 ▶sub swap {
Subroutine swap: called CC=1 SCAR=0.0
Pod documented
803 4 my ($self, $game) = @_;
804 4 $self->game($game);
805 4 $self->_told(scalar @{ $game->log });
806 4 $self->_cursor(0);
807 4 $self->_note(undef);
808 4 return $self;
809 }
810  
811 244 ▶sub person_turn {
Subroutine person_turn: called CC=1 SCAR=0.0
Pod documented
812 244 my ($self) = @_;
813 244 $self->history->turn($self->game);
814 244 return $self;
815 }
816  
817 15 ▶sub settings {
Subroutine settings: called CC=2 SCAR=7.0
Pod documented
818 15 my ($self) = @_;
819 15 my $variant = $self->game->variant;
820 return {
821 mode => $self->mode,
822 side => $self->side,
823 level => $self->level,
824 first => $self->first,
825 pieces => $variant->pieces,
826 15 ▶ ((grep { $_ eq $variant->exits } Game::Senet::Variant->names) ? (rules => $variant->exits) : ()),
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $variant->exits;} 'Game::Senet::Variant'->names) ? : 15 0 15
827 };
828 }
829  
830 15 ▶sub save_default {
Subroutine save_default: called CC=2 SCAR=6.9
Pod documented
831 15 my ($self) = @_;
832 15 my $file = $self->history->file;
833 15 ▶ return defined $file ? $file : Game::Terminal::Kit::Save::default_file('senet');
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 14 1 15
834 }
835  
836 15 ▶sub save {
Subroutine save: called CC=4 SCAR=13.9
Pod documented
837 15 my ($self, $file) = @_;
838 15 ▶ $file = $self->save_default unless defined $file && length $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and length $file 8 7 15
Condition66%2/3
defined $file and length $file
!ll&&!rl&&r
807
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
839 15 my $history = $self->history;
840 15 $history->settings($self->settings);
841 15 $history->version($VERSION);
842 15 my $path = eval { $history->saved($self->game)->write_file($file) };
843 15 ▶ unless ($path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path) 1 14 15
844 1 $self->_note('The game was not saved: ' . _plain($@) . '.');
845 1 return 0;
846 }
847 14 $history->file($path);
848 14 $self->_event(undef, "The game is saved to $path.");
849 14 return 1;
850 }
851  
852 20 ▶sub _plain {
Subroutine _plain: called CC=3 SCAR=11.6
853 20 my ($why) = @_;
854 20 ▶ $why = 'it failed without a reason' unless defined $why && length $why;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $why and length $why 0 20 20
Condition33%1/3
defined $why and length $why
!ll&&!rl&&r
0020
MC/DC0%0/2
defined $why and length $why
defined $why length $why
Truth table33%1/3
A and B
A= defined $whyB= length $why
ABresult
0X0
100
111
855 20 $why =~ s/ at \S+ line \d+\.?\s*\z//;
856 20 $why =~ s/\A(?:Game::Terminal::Kit::\w+|Game::Senet(?:::\w+)*): //;
857 20 $why =~ s/\.?\s*\z//;
858 20 return $why;
859 }
860  
861 8 ▶sub replay_lines {
Subroutine replay_lines: called CC=4 SCAR=13.9
Pod documented
862 8 my ($self, $game) = @_;
863 8 my $was = $self->game;
864 8 $self->game($game);
865 8 my @lines = eval {
866 8 my @log = @{ $game->log };
867 8 ▶ @log = @log[ -4 .. -1 ] if @log > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @log > 4 0 8 8
868 8 ▶ (@{ $self->board_lines }, $self->_shield_lines, '', $self->_sticks_line, $self->_result_line,
Branch: 1 branch
BranchTrueFalseTotal
@log ? : 6 2 8
869 8 (@log ? '' : ()), map { ' ' . $self->_paint($self->_describe($_), $_->{side}) } @log);
870 };
871 8 my $died = $@;
872 8 $self->game($was);
873 8 ▶ die $died unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 8 8
874 8 return @lines;
875 }
876  
877 18 ▶sub read_save {
Subroutine read_save: called CC=16 SCAR=28.2
Pod documented
878 18 my ($class, $file, %option) = @_;
879 18 my $save = eval { Game::Terminal::Kit::Save->read_file($file, game => 'senet') };
880 18 ▶ return $save if $save;
Branch: 1 branch
BranchTrueFalseTotal
if $save 7 11 18
881 11 my $why = _plain($@);
882 11 ▶ return (undef, $why) unless $why =~ /is not a saved game\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $why =~ /is not a saved game\z/ 5 6 11
883  
884 # Not a save: a record, as --record wrote before saves were kept.
885 6 ▶ open my $fh, '<', $file or return (undef, "I could not read '$file'");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return undef, "I could not read '${file}'" 6 0 6
886 6 my $text = do { local $/; <$fh> };
887 6 close $fh;
888 6 my ($game, $error) = Game::Senet->replay($text);
889 6 ▶ unless ($game) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game) 2 4 6
890 2 my $detail = $error->detail;
891 return (undef, "'$file' is not a game I can replay: " . $error->message
892 2 ▶ . (defined $detail->{line} ? " (line $detail->{line})" : defined $detail->{ply} ? ' (ply ' . ($detail->{ply} + 1) . ')' : ''));
Branch: 2 branches
BranchTrueFalseTotal
defined $detail->{'line'} ? : 1 1 2
defined $detail->{'ply'} ? : 1 0 1
893 }
894 4 my $current = $game->to_text;
895 4 my @steps;
896 4 ▶ if (($option{steps} || '') eq 'ply') {
Branch: 1 branch
BranchTrueFalseTotal
if (($option{"steps"} || "") eq "ply") 2 2 4
Condition100%2/2
$option{'steps'} || ''
l!l
31
MC/DC100%1/1
$option{'steps'} || ''
$option{'steps'}
Truth table100%2/2
A
A= $option{'steps'}
Aresult
11
00
897 2 my ($record) = Game::Senet::Notation::parse_record($text);
898 2 ▶ my @plies = @{ $record->{plies} || [] };
Condition50%1/2
$record->{'plies'} || []
l!l
20
MC/DC0%0/1
$record->{'plies'} || []
$record->{'plies'}
Truth table50%1/2
A
A= $record->{'plies'}
Aresult
11
00
899 2 for my $n (0 .. $#plies) {
900 7 my ($before) = Game::Senet->replay({ %{$record}, plies => [ @plies[0 .. $n - 1] ], result => undef });
901 7 ▶ next unless $before;
Branch: 1 branch
BranchTrueFalseTotal
unless $before 0 7 7
902 7 my $step = $before->to_text;
903 7 ▶ push @steps, $step unless @steps && $steps[-1] eq $step;
Branch: 1 branch
BranchTrueFalseTotal
unless @steps and $steps[-1] eq $step 7 0 7
Condition66%2/3
@steps and $steps[-1] eq $step
!ll&&!rl&&r
250
MC/DC0%0/2
@steps and $steps[-1] eq $step
@steps $steps[-1] eq $step
Truth table66%2/3
A and B
A= @stepsB= $steps[-1] eq $step
ABresult
0X0
100
111
904 }
905 2 ▶ pop @steps while @steps && $steps[-1] eq $current;
Branch: 1 branch
BranchTrueFalseTotal
@steps and $steps[-1] eq $current and do { pop @steps } 0 2 2
Condition33%1/3
@steps and $steps[-1] eq $current
!ll&&!rl&&r
020
MC/DC0%0/2
@steps and $steps[-1] eq $current
@steps $steps[-1] eq $current
Truth table33%1/3
A and B
A= @stepsB= $steps[-1] eq $current
ABresult
0X0
100
111
906 }
907 4 $save = Game::Terminal::Kit::Save->new(name => 'senet', past => \@steps, current => $current);
908 4 $save->file($file);
909 4 return $save;
910 }
911  
912 1048 ▶sub _bot_move {
Subroutine _bot_move: called CC=4 SCAR=13.9
913 1048 my ($self) = @_;
914 1048 my $game = $self->game;
915 1048 my $bot = Game::Senet::Bot->new(level => $self->level);
916 1048 ▶ my $move = $bot->choose($game) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $move = $bot->choose($game) or return 1048 0 1048
917 1048 ▶ if ($self->_raw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_raw) 133 915 1048
918 133 my @moves = $self->candidates;
919 133 my ($at) = grep { $moves[$_] == $move } 0 .. $#moves;
920 133 ▶ $self->_cursor($at // 0);
Condition50%1/2
$at // 0
l!l
1330
MC/DC0%0/1
$at // 0
$at
Truth table50%1/2
A
A= $at
Aresult
11
00
921 133 $self->show('pick');
922 133 $self->_wait;
923 }
924 1048 $game->play_or_die($move);
925 1048 $self->_cursor(0);
926 1048 $self->_tell(1);
927 1048 return;
928 }
929  
930 61 ▶sub _turns {
Subroutine _turns: called CC=14 SCAR=26.8
931 61 my ($self) = @_;
932 61 $self->_tell(1);
933 61 while (1) {
934 1282 my $game = $self->game;
935 1282 ▶ my $picking = $self->picking && $self->_raw;
Condition66%2/3
$self->picking && $self->_raw
!ll&&!rl&&r
9990283
MC/DC50%1/2
$self->picking && $self->_raw
$self->picking $self->_raw
Truth table66%2/3
A && B
A= $self->pickingB= $self->_raw
ABresult
0X0
100
111
936 1282 ▶ if ($game->is_over) {
Branch: 1 branch
BranchTrueFalseTotal
if ($game->is_over) 11 1271 1282
937 11 ▶ last if $self->mode eq 'watch' && !$self->interactive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode eq "watch" and not $self->interactive 6 5 11
Condition66%2/3
$self->mode eq "watch" and not $self->interactive
!ll&&!rl&&r
506
MC/DC50%1/2
$self->mode eq "watch" and not $self->interactive
$self->mode eq "watch" not $self->interactive
Truth table66%2/3
A and not(B)
A= $self->mode eq "watch"B= not $self->interactive
ABresult
0X0
100
111
938 5 ▶ my $line = $picking ? $self->_ended_key : $self->_read_line;
Branch: 1 branch
BranchTrueFalseTotal
$picking ? : 5 0 5
939 5 ▶ last unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 5 5
940 5 ▶ last if !$picking && $line eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not $picking and $line eq "" 0 5 5
Condition33%1/3
not $picking and $line eq ""
!ll&&!rl&&r
500
MC/DC0%0/2
not $picking and $line eq ""
not $picking $line eq ""
Truth table33%1/3
not(A) and B
A= not $pickingB= $line eq ""
ABresult
0X0
100
111
941 5 ▶ last if $self->command($line);
Branch: 1 branch
BranchTrueFalseTotal
if $self->command($line) 4 1 5
942 1 $self->_tell(1);
943 1 next;
944 }
945 1271 ▶ if (!$self->_person($game->side)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_person($game->side)) 1048 223 1271
946 1048 $self->_bot_move;
947 1048 next;
948 }
949 223 $self->person_turn;
950 223 ▶ my $line = $picking ? $self->pick : $self->_read_line;
Branch: 1 branch
BranchTrueFalseTotal
$picking ? : 145 78 223
951 223 ▶ last unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 1 222 223
952 222 ▶ last if $self->command($line);
Branch: 1 branch
BranchTrueFalseTotal
if $self->command($line) 50 172 222
953 }
954 61 return;
955 }
956  
957 61 ▶sub start {
Subroutine start: called CC=9 SCAR=22.2
Pod documented
958 61 my ($self) = @_;
959 61 ▶ $self->picking(0) if $self->picking && !$self->_enter_raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->picking and not $self->_enter_raw 0 61 61
Condition66%2/3
$self->picking and not $self->_enter_raw
!ll&&!rl&&r
5290
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
960  
961 61 ▶ Game::Terminal::Kit::Run::guard(sub { $self->_turns }, $self->_keyboard, $self->_screen);
Subroutine __ANON__: called CC=1 SCAR=0.0
962  
963 61 ▶ $self->_say(@{ $self->screen('plain') }) if $self->mode eq 'watch' || $self->game->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode eq "watch" or $self->game->is_over 10 51 61
Condition100%3/3
$self->mode eq "watch" or $self->game->is_over
l!l&&r!l&&!r
6451
MC/DC100%2/2
$self->mode eq "watch" or $self->game->is_over
$self->mode eq "watch" $self->game->is_over
Truth table100%3/3
A or B
A= $self->mode eq "watch"B= $self->game->is_over
ABresult
1X1
011
000
964 61 my $result = $self->game->result;
965 61 ▶ return 1 if $self->mode eq 'bot' && $result && defined $result->winner && $result->winner ne $self->side;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mode eq "bot" and $result and defined $result->winner and $result->winner ne $self->side 1 60 61
Condition77%7/9
$self->mode eq "bot" and $result and defined $result->winner and $result->winner ne $self->side
!ll&&!rl&&r
6001
$self->mode eq "bot" and $result and defined $result->winner
!ll&&!rl&&r
6001
$self->mode eq "bot" and $result
!ll&&!rl&&r
37231
MC/DC50%2/4
$self->mode eq "bot" and $result and defined $result->winner and $result->winner ne $self->side
$self->mode eq "bot" $result defined $result->winner $result->winner ne $self->side
Truth table60%3/5
A and B and C and D
A= $self->mode eq "bot"B= $resultC= defined $result->winnerD= $result->winner ne $self->side
ABCDresult
0XXX0
10XX0
110X0
11100
11111
966 60 return 0;
967 }
968  
969 5 ▶sub _usage {
Subroutine _usage: called CC=1 SCAR=0.0
970 5 return <<'USAGE';
971 senet - Senet, the race game of ancient Egypt, in a terminal
972  
973 senet [options]
974  
975 --mode HOW bot (the default): you against the program
976 hotseat: two people at one keyboard
977 watch: the program against itself
978 --rules NAME kendall (the default) or skyruk
979 --pieces N 5 (the default) or 7 a side
980 --level N how well the program plays, 1 upward; the top by default,
981 and above the top plays the top
982 --side WHICH light (the default) or dark: your side against the program
983 --first WHO light (the default) or dark: who throws first
984 --seed HEX hexadecimal; the same seed throws the same sticks
985 --pace SECONDS how long a lost turn and the program's move stay up
986 --save FILE where S, or save, writes the game: FILE, else the file it
987 was resumed from, else senet.save
988 --resume FILE carry on a saved game, with its undo and redo
989 --replay FILE watch a saved game a step at a time; enter plays on from there
990 --record FILE the old name for --save
991 --ascii plain letters and lines, for a terminal with no Unicode
992 --unicode line and shape characters, where they are not the default
993 --no-colour no colour; nothing is lost without it
994 --no-pick type moves instead of choosing them with the arrow keys
995 --version the version, and stop
996 --help this, and stop
997  
998 In a terminal, the pieces that can move are walked with the arrow keys and the
999 board shows what each move would leave; press ? for the keys. Anywhere else,
1000 type a number from the list, a move such as 12-15 or 26-off, or help.
1001  
1002 A record written by --record before 0.03 can be given to --resume and
1003 --replay as it is.
1004 USAGE
1005 }
1006  
1007 1 ▶sub options {
Subroutine options: called CC=3 SCAR=11.0
Pod documented
1008 1 my $top = 0;
1009 1 for my $name (Game::Senet::Variant->names) {
1010 2 my @levels = Game::Senet::Bot->levels($name);
1011 2 ▶ $top = $levels[-1] if $levels[-1] > $top;
Branch: 1 branch
BranchTrueFalseTotal
if $levels[-1] > $top 1 1 2
1012 }
1013 return [
1014 1 { name => 'mode', type => 'enum', choices => [qw(bot hotseat watch)],
1015 help => 'you against the program, two people, or the program against itself' },
1016 { name => 'rules', type => 'enum', choices => [ Game::Senet::Variant->names ], help => 'the rules' },
1017 { name => 'pieces', type => 'enum', choices => [qw(5 7)], help => 'pieces a side' },
1018 { name => 'level', type => 'int', min => 1, max => $top, help => 'how well the program plays; the top by default' },
1019 { name => 'side', type => 'enum', choices => [qw(light dark)], help => 'your side against the program' },
1020 { name => 'first', type => 'enum', choices => [qw(light dark)], help => 'who throws first' },
1021 { name => 'seed', type => 'str', help => 'hexadecimal; the same seed throws the same sticks' },
1022 ];
1023 }
1024  
1025 79 ▶sub run {
Subroutine run: called CC=26 SCAR=32.6
Pod documented
1026 79 my ($class, @argv) = @_;
1027  
1028 79 my $saved = Getopt::Long::Configure(qw(default no_ignore_case no_auto_abbrev));
1029 79 my %given;
1030 79 my $parsed = Getopt::Long::GetOptionsFromArray(
1031 \@argv, \%given,
1032 'mode=s', 'rules=s', 'pieces=i', 'level=i', 'side=s', 'first=s', 'seed=s', 'pace=s',
1033 Game::Terminal::Kit::Save::flags(), 'record=s',
1034 'ascii', 'unicode!', 'colour|color!', 'pick!', 'version', 'help',
1035 );
1036 79 Getopt::Long::Configure($saved);
1037  
1038 79 ▶ if (!$parsed || @argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $parsed or @argv) 3 76 79
Condition100%3/3
not $parsed or @argv
l!l&&r!l&&!r
2176
MC/DC100%2/2
not $parsed or @argv
not $parsed @argv
Truth table100%3/3
not(A) or B
A= not $parsedB= @argv
ABresult
1X1
011
000
1039 3 ▶ print STDERR "senet: I do not know '@argv'.\n" if $parsed && @argv;
Branch: 1 branch
BranchTrueFalseTotal
if $parsed and @argv 1 2 3
Condition66%2/3
$parsed and @argv
!ll&&!rl&&r
201
MC/DC50%1/2
$parsed and @argv
$parsed @argv
Truth table66%2/3
A and B
A= $parsedB= @argv
ABresult
0X0
100
111
1040 3 print STDERR _usage();
1041 3 return 2;
1042 }
1043 76 ▶ if ($given{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given{"help"}) 2 74 76
1044 2 print _usage();
1045 2 return 0;
1046 }
1047 74 ▶ if ($given{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given{"version"}) 3 71 74
1048 3 print "senet $Game::Senet::VERSION\n";
1049 3 return 0;
1050 }
1051 71 ▶ if (defined $given{record}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $given{"record"}) 2 69 71
1052 2 print STDERR "senet: --record is now --save, and the game is written when you save it: S, or save.\n";
1053 2 ▶ $given{save} = $given{record} unless defined $given{save};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $given{"save"} 2 0 2
1054 }
1055 71 ▶ if (my $why = Game::Terminal::Kit::Save::check_flags(\%given)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = Game::Terminal::Kit::Save::check_flags(\%given)) 2 69 71
1056 2 print STDERR "senet: $why.\n";
1057 2 return 2;
1058 }
1059  
1060 69 my %with;
1061 69 $with{$_} = $given{$_} for grep { defined $given{$_} } qw(mode rules pieces level side first pace);
1062 69 ▶ $with{save_file} = $given{save} if defined $given{save};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"save"} 9 60 69
1063 69 ▶ $with{colour} = $given{colour} if defined $given{colour};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"colour"} 11 58 69
1064 69 ▶ $with{picking} = $given{pick} if defined $given{pick};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"pick"} 9 60 69
1065 69 ▶ $with{unicode} = $given{unicode} if defined $given{unicode};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"unicode"} 1 68 69
1066 69 ▶ $with{unicode} = 0 if $given{ascii};
Branch: 1 branch
BranchTrueFalseTotal
if $given{"ascii"} 9 60 69
1067  
1068 69 ▶ if (defined $given{seed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $given{"seed"}) 49 20 69
1069 49 ▶ if ($given{seed} !~ /\A(?:[0-9a-fA-F]{2})+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($given{"seed"} =~ /\A(?:[0-9a-fA-F]{2})+\z/) 2 47 49
1070 2 print STDERR "senet: a seed is hexadecimal, two characters a byte.\n";
1071 2 return 2;
1072 }
1073 47 $with{seed} = pack 'H*', $given{seed};
1074 }
1075  
1076 67 ▶ my $from = defined $given{resume} ? $given{resume} : $given{replay};
Branch: 1 branch
BranchTrueFalseTotal
defined $given{'resume'} ? : 9 58 67
1077 67 ▶ return $class->_play(undef, %with) unless defined $from;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from 54 13 67
1078  
1079 13 ▶ my ($save, $why) = $class->read_save($from, steps => defined $given{replay} ? 'ply' : 'one');
Branch: 1 branch
BranchTrueFalseTotal
defined $given{'replay'} ? : 4 9 13
1080 13 ▶ unless ($save) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($save) 5 8 13
1081 5 print STDERR "senet: $why.\n";
1082 5 return 2;
1083 }
1084 # What the game was played with, unless the command line says otherwise.
1085 8 my $settings = $save->settings;
1086 8 for my $key (qw(mode side level first)) {
1087 32 ▶ $with{$key} = $settings->{$key} if !exists $with{$key} && defined $settings->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $with{$key} and defined $settings->{$key} 21 11 32
Condition100%3/3
not exists $with{$key} and defined $settings->{$key}
!ll&&!rl&&r
4721
MC/DC100%2/2
not exists $with{$key} and defined $settings->{$key}
not exists $with{$key} defined $settings->{$key}
Truth table100%3/3
not(A) and B
A= not exists $with{$key}B= defined $settings->{$key}
ABresult
0X0
100
111
1088 }
1089 8 ▶ return defined $given{replay} ? $class->_replay($save, %with) : $class->_play($save, %with);
Branch: 1 branch
BranchTrueFalseTotal
defined $given{'replay'} ? : 2 6 8
1090 }
1091  
1092 60 ▶sub _play {
Subroutine _play: called CC=5 SCAR=16.3
1093 60 my ($class, $save, %with) = @_;
1094 60 ▶ if ($save) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save) 6 54 60
1095 6 my $history = $class->_new_history;
1096 6 my $game = eval { $history->resume($save) };
1097 6 ▶ unless ($game) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game) 0 6 6
1098 0 print STDERR "senet: '" . $save->file . "' cannot be carried on: " . _plain($@) . ".\n";
1099 0 return 2;
1100 }
1101 6 $with{game} = $game;
1102 6 $with{history} = $history;
1103 6 $with{rules} = $game->variant;
1104 6 ▶ $with{seed} = $game->seed if defined $game->seed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $game->seed 6 0 6
1105 }
1106 60 my $terminal = eval { $class->new(%with) };
1107 60 ▶ if (!$terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($terminal) 8 52 60
1108 8 print STDERR "senet: " . _plain($@) . ".\n";
1109 8 return 2;
1110 }
1111 52 return $terminal->start;
1112 }
1113  
1114 2 ▶sub _replay {
Subroutine _replay: called CC=7 SCAR=21.8
1115 2 my ($class, $save, %with) = @_;
1116 2 my $first = eval { Game::Senet->from_text(($save->steps)[0]) };
1117 2 ▶ my $terminal = $first && eval {
Condition33%1/3
$first && eval { do { $class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ()) } }
!ll&&!rl&&r
002
MC/DC0%0/2
$first && eval { do { $class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ()) } }
$first eval { do { $class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ()) } }
Truth table33%1/3
A && B
A= $firstB= eval { do { $class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ()) } }
ABresult
0X0
100
111
1118 2 ▶ $class->new(%with, game => $first, rules => $first->variant,
Branch: 1 branch
BranchTrueFalseTotal
defined $first->seed ? : 2 0 2
1119 (defined $first->seed ? (seed => $first->seed) : ()));
1120 };
1121 2 ▶ unless ($terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($terminal) 0 2 2
1122 0 print STDERR "senet: '" . $save->file . "' cannot be watched: " . _plain($@) . ".\n";
1123 0 return 2;
1124 }
1125 my $replay = Game::Terminal::Kit::Replay->new(
1126 save => $save,
1127 7 ▶ load => sub { Game::Senet->from_text($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1128 7 ▶ draw => sub { $terminal->replay_lines($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1129 2 ▶ head => [ $terminal->screen('plain')->[0],
Branch: 2 branches
BranchTrueFalseTotal
defined $save->saved_at ? : 1 1 2
$terminal->pace > 0 ? : 0 2 2
1130 ' ' . $terminal->_paint('A replay of ' . $save->file
1131 . (defined $save->saved_at ? ', saved ' . $save->saved_at : ''), 'quiet'), '' ],
1132 screen => $terminal->_screen,
1133 ($terminal->pace > 0 ? (pace => $terminal->pace) : ()),
1134 );
1135 2 my ($event, $step) = $replay->play($terminal->_keyboard, $terminal->_screen);
1136 2 ▶ return 0 unless $event eq 'chosen';
Branch: 1 branch
BranchTrueFalseTotal
unless $event eq "chosen" 2 0 2
1137 0 return $class->_play($save->from_step($step), %with);
1138 }
1139  
1140 75 1;
1141  
1142 __END__
« blib/lib/Game/Senet.pm ↑ Summary blib/lib/Game/Senet/Result.pm »