blib/lib/Game/Durak/Terminal.pm

filter: Statementstmt 76.0% 321 / 422 Branchbran 62.2% 163 / 262 Conditioncond 54.1% 59 / 109 MC/DCmcdc 37.5% 24 / 64 Subroutinesub 88.0% 44 / 50 Podpod 97.0% 33 / 34 totaltotal 68.4% 644 / 941 CC 177 SCAR 36.7
CC
177
Cov
68%
pick_move
184.5
headline
56.0
close_screen
28.7
CRAP 39.1
↑ Summary blib/lib/Game/Durak/Table.pm »
1 package Game::Durak::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::Durak ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Game::Durak::Bot ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Game::Durak::Card qw(name_of long_name_of suit_of rank_of face_of);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Game::Durak::Table ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 our $VERSION = '0.02';
14  
15 5 my %SUIT = (
16 S => { wide => "\x{2660}", ascii => 'S', colour => '37' },
17 H => { wide => "\x{2665}", ascii => 'H', colour => '31' },
18 D => { wide => "\x{2666}", ascii => 'D', colour => '31' },
19 C => { wide => "\x{2663}", ascii => 'C', colour => '37' },
20 );
21  
22 5 my %SAID = (
23 attack => 'attack with',
24 beat => 'beat it with',
25 take => 'take the bout',
26 done => 'are done',
27 swap => 'exchange the trump six',
28 resign => 'give up',
29 );
30  
31 5 has game => (is => 'rw', isa => Any);
32 5 has out => (is => 'ro', isa => Any);
33 5 has in => (is => 'ro', isa => Any);
34 5 has seed => (is => 'ro', isa => Str);
35 5 has level => (is => 'ro', isa => Int);
36 5 has seat => (is => 'ro', isa => Int);
37 5 has ascii => (is => 'ro', isa => Any);
38 5 has colour => (is => 'ro', isa => Any);
39 5 has paint => (is => 'ro', isa => Any);
40 5 has width => (is => 'ro', isa => Int);
41 5 has height => (is => 'ro', isa => Int);
42 5 has _painting => (is => 'rw', isa => Any);
43  
44 5 has raw => (is => 'rw', isa => Any, default => 0);
45  
46 5 has keysource => (is => 'rw', isa => Any);
47  
48 16 ▶has pending => (is => 'rw', isa => ArrayRef, default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
49  
50 5 has _picking => (is => 'rw', isa => Any, init_arg => 'picking');
51  
52 5 our %SEQUENCE = (
53 'A' => 'up', 'B' => 'down', 'C' => 'right', 'D' => 'left',
54 'H' => 'home', 'F' => 'end',
55 '1~' => 'home', '4~' => 'end', '5~' => 'page_up', '6~' => 'page_down',
56 '7~' => 'home', '8~' => 'end',
57 );
58  
59 5 our %CONTROL = (
60 "\r" => 'enter', "\n" => 'enter', "\t" => 'tab',
61 "\x7f" => 'backspace', "\x08" => 'backspace',
62 "\x03" => 'interrupt', "\x04" => 'eof',
63 );
64 5 has _table => (is => 'rw', isa => Any);
65 5 has _said => (is => 'rw', isa => Any);
66  
67 373 ▶sub _out { return $_[0]->out || \*STDOUT }
Subroutine _out: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->out || \*STDOUT
l!l
35716
MC/DC100%1/1
$_[0]->out || \*STDOUT
$_[0]->out
Truth table100%2/2
A
A= $_[0]->out
Aresult
11
00
68 84 ▶sub _in { return $_[0]->in || \*STDIN }
Subroutine _in: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->in || \*STDIN
l!l
804
MC/DC100%1/1
$_[0]->in || \*STDIN
$_[0]->in
Truth table100%2/2
A
A= $_[0]->in
Aresult
11
00
69 4 ▶sub _level { return defined $_[0]->level ? $_[0]->level : 3 }
Subroutine _level: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->level ? : 4 0 4
70 4 ▶sub _seat { return defined $_[0]->seat ? $_[0]->seat : 1 }
Subroutine _seat: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->seat ? : 3 1 4
71 1239 ▶sub _ascii { return $_[0]->ascii ? 1 : 0 }
Subroutine _ascii: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->ascii ? : 1217 22 1239
72 0 ▶sub _them { return 3 - $_[0]->_seat }
Subroutine _them: not called CC=1 SCAR=6.9
73  
74 16 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
75 16 my ($self) = @_;
76 16 ▶ binmode $self->_out, ':encoding(UTF-8)' unless $self->_ascii;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_ascii 2 14 16
77 16 my $previous = select $self->_out;
78 16 $| = 1;
79 16 select $previous;
80 16 return $self;
81 }
82  
83 1417 ▶sub _colour {
Subroutine _colour: called CC=6 SCAR=18.6
84 1417 my ($self) = @_;
85 1417 my $on = $self->_painting;
86 1417 ▶ return $on if defined $on;
Branch: 1 branch
BranchTrueFalseTotal
if defined $on 1406 11 1417
87 $on = defined $self->colour ? ($self->colour ? 1 : 0)
88 11 ▶ : ((eval { -t $self->_out } && !$ENV{NO_COLOR}) ? 1 : 0);
Branch: 3 branches
BranchTrueFalseTotal
defined $self->colour ? : 9 2 11
$self->colour ? : 0 9 9
eval { do { -t $self->_out } } && !$ENV{'NO_COLOR'} ? : 0 2 2
Condition33%1/3
eval { do { -t $self->_out } } and not $ENV{"NO_COLOR"}
!ll&&!rl&&r
200
MC/DC0%0/2
eval { do { -t $self->_out } } and not $ENV{"NO_COLOR"}
eval { do { -t $self->_out } } not $ENV{"NO_COLOR"}
Truth table33%1/3
A and not(B)
A= eval { do { -t $self->_out } }B= not $ENV{"NO_COLOR"}
ABresult
0X0
100
111
89 11 $self->_painting($on);
90 11 return $on;
91 }
92  
93 214 ▶sub _paint {
Subroutine _paint: called CC=3 SCAR=11.1
94 214 my ($self) = @_;
95 214 ▶ return $self->paint ? 1 : 0 if defined $self->paint;
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->paint 21 193 214
$self->paint ? : 0 21 21
96 193 return $self->_colour;
97 }
98  
99 0 ▶sub table_of {
Subroutine table_of: not called CC=4 SCAR=30.0
Pod documented
100 0 my ($self) = @_;
101 0 my $table = $self->_table;
102 0 ▶ return $table if $table;
Branch: 1 branch
BranchTrueFalseTotal
if $table 0 0 0
103 0 ▶ $table = Game::Durak::Table->new(
Condition0%0/4
$self->width || 80
l!l
00
$self->height || 24
l!l
00
MC/DC0%0/1
$self->width || 80
$self->width
MC/DC0%0/1
$self->height || 24
$self->height
Truth table0%0/2
A
A= $self->width
Aresult
11
00
Truth table0%0/2
A
A= $self->height
Aresult
11
00
104 width => $self->width || 80,
105 height => $self->height || 24,
106 ascii => $self->ascii,
107 );
108 0 $self->_table($table);
109 0 return $table;
110 }
111  
112 0 ▶sub frame {
Subroutine frame: not called CC=2 SCAR=17.9
Pod documented
113 0 my ($self, $view, %o) = @_;
114 0 my $table = $self->table_of;
115 0 my $grid = $table->screen($view, %o);
116 0 ▶ return $self->_colour ? $table->paint($grid) : $table->lines($grid);
Branch: 1 branch
BranchTrueFalseTotal
$self->_colour ? : 0 0 0
117 }
118  
119 0 ▶sub headline {
Subroutine headline: not called CC=7 SCAR=40.3
Pod documented
120 0 my ($self, $room) = @_;
121 0 ▶ my @said = @{ $self->_said || [] };
Condition0%0/2
$self->_said || []
l!l
00
MC/DC0%0/1
$self->_said || []
$self->_said
Truth table0%0/2
A
A= $self->_said
Aresult
11
00
122 0 ▶ return '' unless @said;
Branch: 1 branch
BranchTrueFalseTotal
unless @said 0 0 0
123 0 my $line = '';
124 0 ▶ while (@said) {
Branch: 1 branch
BranchTrueFalseTotal
if (@said) 0 0 0
125 0 my $next = pop @said;
126 0 ▶ my $grown = length $line ? "$next, $line" : $next;
Branch: 1 branch
BranchTrueFalseTotal
length $line ? : 0 0 0
127 0 ▶ last if length $grown > $room;
Branch: 1 branch
BranchTrueFalseTotal
if length $grown > $room 0 0 0
128 0 $line = $grown;
129 }
130 0 ▶ $line = substr((pop @{ $self->_said }), 0, $room) unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 0 0
131 0 return $line;
132 }
133  
134 0 ▶sub show {
Subroutine show: not called CC=4 SCAR=30.0
Pod documented
135 0 my ($self, $view, %o) = @_;
136 0 my $handle = $self->_out;
137 0 my $table = $self->table_of;
138 0 ▶ my $footer = defined $o{footer} ? $o{footer} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'footer'} ? : 0 0 0
139 my $lines = $self->frame($view,
140 header => (defined $o{header} ? $o{header} : $self->headline($table->width - 2)),
141 footer => $footer,
142 0 ▶ (defined $o{cursor} ? (cursor => $o{cursor}) : ()),
Branch: 2 branches
BranchTrueFalseTotal
defined $o{'header'} ? : 0 0 0
defined $o{'cursor'} ? : 0 0 0
143 );
144 0 print {$handle} "\e[H", join("\n", @$lines);
145 0 print {$handle} sprintf "\e[%d;%dH", $table->height, length($footer) + 3;
146 0 $self->_said([]);
147 0 return;
148 }
149  
150 119 ▶sub told {
Subroutine told: called CC=5 SCAR=21.7
Pod documented
151 119 my ($self, @lines) = @_;
152 119 ▶ return unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 119 119
153 119 ▶ if ($self->_paint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_paint) 0 119 119
154 0 ▶ my $said = $self->_said || [];
Condition0%0/2
$self->_said || []
l!l
00
MC/DC0%0/1
$self->_said || []
$self->_said
Truth table0%0/2
A
A= $self->_said
Aresult
11
00
155 0 push @$said, @lines;
156 0 $self->_said($said);
157 0 return;
158 }
159 119 $self->say(" $_") for @lines;
160 119 return;
161 }
162  
163 353 ▶sub say {
Subroutine say: called CC=1 SCAR=0.0
Pod documented
164 353 my ($self, @what) = @_;
165 353 my $handle = $self->_out;
166 353 print {$handle} @what, "\n";
167 353 return;
168 }
169  
170 1199 ▶sub card {
Subroutine card: called CC=4 SCAR=14.0
Pod documented
171 1199 my ($self, $id) = @_;
172 1199 ▶ return '--' unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 70 1129 1199
173 1129 my $suit = suit_of($id);
174 my $face = face_of($id)
175 1129 ▶ . ($self->_ascii ? $SUIT{$suit}{ascii} : $SUIT{$suit}{wide});
Branch: 1 branch
BranchTrueFalseTotal
$self->_ascii ? : 1113 16 1129
176 1129 ▶ return $face unless $self->_colour;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_colour 1129 0 1129
177 0 return "\e[$SUIT{$suit}{colour}m$face\e[0m";
178 }
179  
180 92 ▶sub hand_line {
Subroutine hand_line: called CC=3 SCAR=11.0
Pod documented
181 92 my ($self, $hand, $cursor) = @_;
182 92 my $n = 0;
183  
184 92 ▶ return join ' ', map { ++$n . ') ' . $self->card($_) } @$hand
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cursor 83 9 92
185 unless defined $cursor;
186  
187 return join ' ', map {
188 9 $n++;
189 40 ▶ ($cursor == $n ? '>' : ' ') . $n . ') ' . $self->card($_);
Branch: 1 branch
BranchTrueFalseTotal
$cursor == $n ? : 9 31 40
190 } @$hand;
191 }
192  
193 90 ▶sub bout_line {
Subroutine bout_line: called CC=3 SCAR=11.0
Pod documented
194 90 my ($self, $bout) = @_;
195 90 ▶ return 'nothing on the table' unless $bout && @{ $bout->{pairs} };
Branch: 1 branch
BranchTrueFalseTotal
unless $bout and @{$bout->{"pairs"};} 8 82 90
Condition66%2/3
$bout and @{$bout->{"pairs"};}
!ll&&!rl&&r
0882
MC/DC50%1/2
$bout and @{$bout->{"pairs"};}
$bout @{$bout->{"pairs"};}
Truth table66%2/3
A and B
A= $boutB= @{$bout->{"pairs"};}
ABresult
0X0
100
111
196 return join ' ', map {
197 $self->card($_->{attack}) . ' / ' . $self->card($_->{beat})
198 82 } @{ $bout->{pairs} };
199 }
200  
201 89 ▶sub table {
Subroutine table: called CC=2 SCAR=6.9
Pod documented
202 89 my ($self, $view, %o) = @_;
203  
204 89 my @lines;
205 89 push @lines, '';
206 push @lines, sprintf 'trump %s%s talon %d heap %d they hold %d',
207 $self->card_suit($view->{trump}),
208 (defined $view->{trump_card}
209 ? ' (' . $self->card($view->{trump_card}) . ' face up)' : ''),
210 $view->{talon}, $view->{discard},
211 89 ▶ $view->{counts}{ 3 - $view->{seat} };
Branch: 1 branch
BranchTrueFalseTotal
defined $view->{'trump_card'} ? : 68 21 89
212 89 push @lines, '';
213 89 push @lines, ' ' . $self->bout_line($view->{bout});
214 89 push @lines, '';
215 89 push @lines, ' ' . $self->hand_line($view->{hand}, $o{cursor});
216 89 return join "\n", @lines;
217 }
218  
219 94 ▶sub card_suit {
Subroutine card_suit: called CC=3 SCAR=11.1
Pod documented
220 94 my ($self, $suit) = @_;
221 94 ▶ my $face = $self->_ascii ? $SUIT{$suit}{ascii} : $SUIT{$suit}{wide};
Branch: 1 branch
BranchTrueFalseTotal
$self->_ascii ? : 90 4 94
222 94 ▶ return $self->_colour ? "\e[$SUIT{$suit}{colour}m$face\e[0m" : $face;
Branch: 1 branch
BranchTrueFalseTotal
$self->_colour ? : 0 94 94
223 }
224  
225 89 ▶sub playable {
Subroutine playable: called CC=3 SCAR=11.0
Pod documented
226 89 my ($self, $view) = @_;
227 250 my %card = map { $_->{card} => 1 }
228 89 grep { defined $_->{card} } @{ $view->{legal} };
229 89 my @at;
230 89 my $n = 0;
231 89 for my $held (@{ $view->{hand} }) {
232 920 $n++;
233 920 ▶ push @at, $n if $card{$held};
Branch: 1 branch
BranchTrueFalseTotal
if $card{$held} 250 670 920
234 }
235 89 return \@at;
236 }
237  
238 82 ▶sub prompt_for {
Subroutine prompt_for: called CC=5 SCAR=16.1
Pod documented
239 82 my ($self, $view) = @_;
240 82 my %kinds = map { $_->{kind} => 1 } @{ $view->{legal} };
241 82 my @what;
242  
243 82 my $playable = $self->playable($view);
244 82 ▶ push @what, '[' . join(' ', @$playable) . '] a card' if @$playable;
Branch: 1 branch
BranchTrueFalseTotal
if @$playable 82 0 82
245  
246 82 ▶ push @what, 't take' if $kinds{take};
Branch: 1 branch
BranchTrueFalseTotal
if $kinds{"take"} 62 20 82
247 82 ▶ push @what, 'd done' if $kinds{done};
Branch: 1 branch
BranchTrueFalseTotal
if $kinds{"done"} 13 69 82
248 82 ▶ push @what, 'x exchange' if $kinds{swap};
Branch: 1 branch
BranchTrueFalseTotal
if $kinds{"swap"} 1 81 82
249 82 push @what, 'r resign';
250 82 push @what, 'q quit';
251 82 return join ' ', @what;
252 }
253  
254 5 ▶sub keys_available {
Subroutine keys_available: called CC=4 SCAR=18.7
Pod documented
255 5 my ($self) = @_;
256 5 ▶ return 1 if $self->keysource;
Branch: 1 branch
BranchTrueFalseTotal
if $self->keysource 0 5 5
257 5 ▶ return 0 unless eval { -t $self->_in };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { -t $self->_in } } 5 0 5
258 0 ▶ return eval { require Term::ReadKey; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Term::ReadKey; 1 } } ? : 0 0 0
259 }
260  
261 159 ▶sub picking {
Subroutine picking: called CC=5 SCAR=16.1
Pod documented
262 159 my ($self, @set) = @_;
263 159 ▶ $self->_picking($set[0] ? 1 : 0) if @set;
Branch: 2 branches
BranchTrueFalseTotal
if @set 79 80 159
$set[0] ? : 0 79 79
264 159 ▶ return $self->_picking ? 1 : 0 if defined $self->_picking;
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->_picking 156 3 159
$self->_picking ? : 1 155 156
265 3 return $self->keys_available;
266 }
267  
268 5 ▶sub enter_raw {
Subroutine enter_raw: called CC=5 SCAR=20.4
Pod documented
269 5 my ($self) = @_;
270 5 ▶ return $self if $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->raw 0 5 5
271 5 ▶ if ($self->keysource) { $self->raw(1); return $self }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->keysource) 4 1 5
272 1 ▶ return undef unless $self->keys_available;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keys_available 1 0 1
273 0 ▶ return undef unless eval { Term::ReadKey::ReadMode(3, $self->_in); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { Term::ReadKey::ReadMode(3, $self->_in); 1 } } 0 0 0
274 0 $self->raw(1);
275 0 return $self;
276 }
277  
278 4 ▶sub leave_raw {
Subroutine leave_raw: called CC=3 SCAR=18.1
Pod documented
279 4 my ($self) = @_;
280 4 ▶ return $self unless $self->raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->raw 4 0 4
281 0 ▶ eval { Term::ReadKey::ReadMode(0, $self->_in) } unless $self->keysource;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keysource 0 0 0
282 0 $self->raw(0);
283 0 return $self;
284 }
285  
286 51 ▶sub read_char {
Subroutine read_char: called CC=6 SCAR=27.1
Pod documented
287 51 my ($self, $wait) = @_;
288 51 my $pending = $self->pending;
289 51 ▶ return shift @$pending if @$pending;
Branch: 1 branch
BranchTrueFalseTotal
if @$pending 2 49 51
290 49 ▶ return $self->keysource->($wait) if $self->keysource;
Branch: 1 branch
BranchTrueFalseTotal
if $self->keysource 49 0 49
291 0 ▶ my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->_in);
Branch: 1 branch
BranchTrueFalseTotal
$wait ? : 0 0 0
292 0 ▶ return $char if defined $char || $wait;
Branch: 1 branch
BranchTrueFalseTotal
if defined $char or $wait 0 0 0
Condition0%0/3
defined $char or $wait
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $char or $wait
defined $char $wait
Truth table0%0/3
A or B
A= defined $charB= $wait
ABresult
1X1
011
000
293 0 select undef, undef, undef, 0.05;
294 0 return Term::ReadKey::ReadKey(-1, $self->_in);
295 }
296  
297 27 ▶sub read_key {
Subroutine read_key: called CC=4 SCAR=13.9
Pod documented
298 27 my ($self) = @_;
299 27 my $char = $self->read_char(1);
300 27 ▶ return undef unless defined $char;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $char 1 26 27
301 26 ▶ return $CONTROL{$char} if $CONTROL{$char};
Branch: 1 branch
BranchTrueFalseTotal
if $Game::Durak::Terminal::CONTROL{$char} 5 21 26
302 21 ▶ return $self->read_sequence if $char eq "\e";
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "\e" 12 9 21
303 9 return $char;
304 }
305  
306 12 ▶sub read_sequence {
Subroutine read_sequence: called CC=8 SCAR=21.0
Pod documented
307 12 my ($self) = @_;
308 12 my $opener = $self->read_char(0);
309 12 ▶ return 'escape' unless defined $opener;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opener 0 12 12
310 12 ▶ unless ($opener eq '[' || $opener eq 'O') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opener eq "[" or $opener eq "O") 2 10 12
Condition100%3/3
$opener eq "[" or $opener eq "O"
l!l&&r!l&&!r
912
MC/DC100%2/2
$opener eq "[" or $opener eq "O"
$opener eq "[" $opener eq "O"
Truth table100%3/3
A or B
A= $opener eq "["B= $opener eq "O"
ABresult
1X1
011
000
311 2 unshift @{ $self->pending }, $opener;
312 2 return 'escape';
313 }
314 10 my $tail = '';
315 10 ▶ while (length $tail < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tail < 8) 12 0 12
316 12 my $char = $self->read_char(0);
317 12 ▶ last unless defined $char;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $char 0 12 12
318 12 $tail .= $char;
319 12 ▶ last if $char =~ /[A-Za-z~]/;
Branch: 1 branch
BranchTrueFalseTotal
if $char =~ /[A-Za-z~]/ 10 2 12
320 }
321 10 ▶ return $SEQUENCE{$tail} || 'escape';
Condition50%1/2
$Game::Durak::Terminal::SEQUENCE{$tail} || 'escape'
l!l
100
MC/DC0%0/1
$Game::Durak::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Durak::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Durak::Terminal::SEQUENCE{$tail}
Aresult
11
00
322 }
323  
324 11 ▶sub card_line {
Subroutine card_line: called CC=10 SCAR=27.8
Pod documented
325 11 my ($self, $view, $card) = @_;
326  
327 44 ▶ my ($move) = grep { defined $_->{card} && $_->{card} == $card }
Condition100%3/3
defined $_->{'card'} && $_->{'card'} == $card
!ll&&!rl&&r
82511
MC/DC100%2/2
defined $_->{'card'} && $_->{'card'} == $card
defined $_->{'card'} $_->{'card'} == $card
Truth table100%3/3
A && B
A= defined $_->{'card'}B= $_->{'card'} == $card
ABresult
0X0
100
111
328 11 @{ $view->{legal} };
329 11 ▶ return $self->card($card) . ': not one you can play' unless $move;
Branch: 1 branch
BranchTrueFalseTotal
unless $move 0 11 11
330  
331 11 ▶ my $trump = suit_of($card) eq $view->{trump} ? ', a trump' : '';
Branch: 1 branch
BranchTrueFalseTotal
suit_of($card) eq $view->{'trump'} ? : 1 10 11
332 11 my $bout = $view->{bout};
333  
334 11 ▶ if ($move->{kind} eq 'defend') {
Branch: 1 branch
BranchTrueFalseTotal
if ($move->{"kind"} eq "defend") 0 11 11
335 my $beats = defined $bout && defined $bout->{unbeaten}
336 0 ▶ ? ' the ' . $self->card($bout->{unbeaten}) : ' the attack';
Branch: 1 branch
BranchTrueFalseTotal
defined $bout && defined $bout->{'unbeaten'} ? : 0 0 0
Condition0%0/3
defined $bout and defined $bout->{"unbeaten"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $bout and defined $bout->{"unbeaten"}
defined $bout defined $bout->{"unbeaten"}
Truth table0%0/3
A and B
A= defined $boutB= defined $bout->{"unbeaten"}
ABresult
0X0
100
111
337 0 return $self->card($card) . ": beats$beats$trump";
338 }
339  
340 11 ▶ my $room = defined $bout ? ($bout->{cap} - $bout->{size}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $bout ? : 11 0 11
341 11 ▶ my $with = $room > 1 ? sprintf ', %d more could follow', $room - 1
Branch: 2 branches
BranchTrueFalseTotal
$room > 1 ? : 11 0 11
$room == 1 ? : 0 0 0
342 : $room == 1 ? ', the last this bout can hold' : '';
343  
344 11 return $self->card($card) . ": they must beat it$trump$with";
345 }
346  
347 8 ▶sub pick_keys {
Subroutine pick_keys: called CC=1 SCAR=0.0
Pod documented
348 8 return 'arrows to choose, enter to play, ? for the keys';
349 }
350  
351 0 ▶sub pick_help {
Subroutine pick_help: not called CC=1 SCAR=6.9
Pod documented
352 return (
353 0 'arrows walk the cards you may play, enter plays the one under the cursor',
354 'the line above says what it would do',
355 't take, d done, x exchange, r resign, q quit',
356 );
357 }
358  
359 4 ▶sub pick_move {
Subroutine pick_move: called CC=36 SCAR=52.2
Pod documented
360 4 my ($self, $view) = @_;
361  
362 4 my $at_list = $self->playable($view);
363 4 my @slot = @$at_list;
364  
365 4 my %by;
366 4 push @{ $by{ $_->{kind} } }, $_ for @{ $view->{legal} };
367  
368 4 my $at = 0;
369 4 my @notice;
370  
371 4 while (1) {
372 8 ▶ my $card = @slot ? $view->{hand}[ $slot[$at] - 1 ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@slot ? : 8 0 8
373  
374 8 ▶ $self->told(@notice) if @notice;
Branch: 1 branch
BranchTrueFalseTotal
if @notice 1 7 8
375 8 @notice = ();
376 8 ▶ $self->told($self->card_line($view, $card)) if defined $card;
Branch: 1 branch
BranchTrueFalseTotal
if defined $card 8 0 8
377  
378 8 ▶ $self->position($view,
Branch: 1 branch
BranchTrueFalseTotal
defined $card ? : 8 0 8
379 cursor => (defined $card ? $slot[$at] : undef),
380 footer => $self->pick_keys);
381  
382 8 my $key = $self->read_key;
383 8 ▶ return { kind => 'quit' }
Branch: 1 branch
BranchTrueFalseTotal
if not defined $key or $key eq "eof" or $key eq "interrupt" or $key eq "q" 3 5 8
Condition44%4/9
not defined $key or $key eq "eof" or $key eq "interrupt" or $key eq "q"
l!l&&r!l&&!r
035
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
008
not defined $key or $key eq "eof"
l!l&&r!l&&!r
008
MC/DC25%1/4
not defined $key or $key eq "eof" or $key eq "interrupt" or $key eq "q"
not defined $key $key eq "eof" $key eq "interrupt" $key eq "q"
Truth table40%2/5
not(A) or B or C or D
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"D= $key eq "q"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
384 if !defined $key || $key eq 'eof' || $key eq 'interrupt'
385 || $key eq 'q';
386  
387 5 ▶ if (@slot && ($key eq 'left' || $key eq 'up')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@slot and $key eq "left" || $key eq "up") 0 5 5
Condition33%2/6
@slot and $key eq "left" || $key eq "up"
!ll&&!rl&&r
050
$key eq "left" or $key eq "up"
l!l&&r!l&&!r
005
MC/DC0%0/3
@slot and $key eq "left" || $key eq "up"
@slot $key eq "left" $key eq "up"
Truth table25%1/4
A and B or C
A= @slotB= $key eq "left"C= $key eq "up"
ABCresult
0XX0
1000
11X1
1011
388 0 $at = ($at - 1) % @slot;
389 0 next;
390 }
391 5 ▶ if (@slot && ($key eq 'right' || $key eq 'down' || $key eq 'tab')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@slot and $key eq "right" || $key eq "down" || $key eq "tab") 3 2 5
Condition66%6/9
@slot and $key eq "right" || $key eq "down" || $key eq "tab"
!ll&&!rl&&r
023
$key eq "right" or $key eq "down" or $key eq "tab"
l!l&&r!l&&!r
302
$key eq "right" or $key eq "down"
l!l&&r!l&&!r
302
MC/DC25%1/4
@slot and $key eq "right" || $key eq "down" || $key eq "tab"
@slot $key eq "right" $key eq "down" $key eq "tab"
Truth table40%2/5
A and B or C or D
A= @slotB= $key eq "right"C= $key eq "down"D= $key eq "tab"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
392 3 $at = ($at + 1) % @slot;
393 3 next;
394 }
395 2 ▶ if (@slot && ($key eq 'home')) { $at = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@slot and $key eq "home") 0 2 2
Condition33%1/3
@slot and $key eq "home"
!ll&&!rl&&r
020
MC/DC0%0/2
@slot and $key eq "home"
@slot $key eq "home"
Truth table33%1/3
A and B
A= @slotB= $key eq "home"
ABresult
0X0
100
111
396 2 ▶ if (@slot && ($key eq 'end')) { $at = $#slot; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@slot and $key eq "end") 0 2 2
Condition33%1/3
@slot and $key eq "end"
!ll&&!rl&&r
020
MC/DC0%0/2
@slot and $key eq "end"
@slot $key eq "end"
Truth table33%1/3
A and B
A= @slotB= $key eq "end"
ABresult
0X0
100
111
397  
398 2 ▶ if (@slot && ($key eq 'enter' || $key eq ' ')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@slot and $key eq "enter" || $key eq " ") 0 2 2
Condition33%2/6
@slot and $key eq "enter" || $key eq " "
!ll&&!rl&&r
020
$key eq "enter" or $key eq " "
l!l&&r!l&&!r
002
MC/DC0%0/3
@slot and $key eq "enter" || $key eq " "
@slot $key eq "enter" $key eq " "
Truth table25%1/4
A and B or C
A= @slotB= $key eq "enter"C= $key eq " "
ABCresult
0XX0
1000
11X1
1011
399 0 ▶ my ($move) = grep { defined $_->{card} && $_->{card} == $card }
Condition0%0/3
defined $_->{'card'} && $_->{'card'} == $card
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->{'card'} && $_->{'card'} == $card
defined $_->{'card'} $_->{'card'} == $card
Truth table0%0/3
A && B
A= defined $_->{'card'}B= $_->{'card'} == $card
ABresult
0X0
100
111
400 0 @{ $view->{legal} };
401 0 ▶ return $move if $move;
Branch: 1 branch
BranchTrueFalseTotal
if $move 0 0 0
402 0 @notice = ('you cannot play that one');
403 0 next;
404 }
405  
406 2 ▶ if ($key eq 't' && $by{take}) { return $by{take}[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "t" and $by{"take"}) 1 1 2
Condition66%2/3
$key eq "t" and $by{"take"}
!ll&&!rl&&r
101
MC/DC50%1/2
$key eq "t" and $by{"take"}
$key eq "t" $by{"take"}
Truth table66%2/3
A and B
A= $key eq "t"B= $by{"take"}
ABresult
0X0
100
111
407 1 ▶ if ($key eq 'd' && $by{done}) { return $by{done}[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "d" and $by{"done"}) 0 1 1
Condition33%1/3
$key eq "d" and $by{"done"}
!ll&&!rl&&r
100
MC/DC0%0/2
$key eq "d" and $by{"done"}
$key eq "d" $by{"done"}
Truth table33%1/3
A and B
A= $key eq "d"B= $by{"done"}
ABresult
0X0
100
111
408 1 ▶ if ($key eq 'x' && $by{swap}) { return $by{swap}[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "x" and $by{"swap"}) 0 1 1
Condition33%1/3
$key eq "x" and $by{"swap"}
!ll&&!rl&&r
100
MC/DC0%0/2
$key eq "x" and $by{"swap"}
$key eq "x" $by{"swap"}
Truth table33%1/3
A and B
A= $key eq "x"B= $by{"swap"}
ABresult
0X0
100
111
409 1 ▶ if ($key eq 'r') { return { kind => 'resign' } }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "r") 0 1 1
410  
411 1 ▶ if ($key =~ /\A[1-9]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\A[1-9]\z/) 0 1 1
412 0 my ($found) = grep { $slot[$_] == $key } 0 .. $#slot;
413 0 ▶ if (defined $found) { $at = $found; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $found) 0 0 0
414 0 @notice = ("you cannot play card $key");
415 0 next;
416 }
417  
418 1 ▶ if ($key eq '?') { @notice = $self->pick_help; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "?") 0 1 1
419  
420 1 @notice = ('that key does nothing here');
421 }
422 }
423  
424 95 ▶sub move_for {
Subroutine move_for: called CC=16 SCAR=27.7
Pod documented
425 95 my ($self, $view, $said) = @_;
426  
427 95 ▶ return undef unless defined $said;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $said 1 94 95
428 94 $said =~ s/\A\s+|\s+\z//g;
429 94 ▶ return { kind => 'quit' } if lc $said eq 'q' || lc $said eq 'quit';
Branch: 1 branch
BranchTrueFalseTotal
if lc $said eq "q" or lc $said eq "quit" 6 88 94
Condition100%3/3
lc $said eq "q" or lc $said eq "quit"
l!l&&r!l&&!r
4288
MC/DC100%2/2
lc $said eq "q" or lc $said eq "quit"
lc $said eq "q" lc $said eq "quit"
Truth table100%3/3
A or B
A= lc $said eq "q"B= lc $said eq "quit"
ABresult
1X1
011
000
430  
431 88 my %by;
432 88 push @{ $by{ $_->{kind} } }, $_ for @{ $view->{legal} };
433  
434 88 ▶ return $by{take}[0] if lc $said eq 't' && $by{take};
Branch: 1 branch
BranchTrueFalseTotal
if lc $said eq "t" and $by{"take"} 5 83 88
Condition100%3/3
lc $said eq "t" and $by{"take"}
!ll&&!rl&&r
7855
MC/DC100%2/2
lc $said eq "t" and $by{"take"}
lc $said eq "t" $by{"take"}
Truth table100%3/3
A and B
A= lc $said eq "t"B= $by{"take"}
ABresult
0X0
100
111
435 83 ▶ return $by{done}[0] if lc $said eq 'd' && $by{done};
Branch: 1 branch
BranchTrueFalseTotal
if lc $said eq "d" and $by{"done"} 4 79 83
Condition100%3/3
lc $said eq "d" and $by{"done"}
!ll&&!rl&&r
7544
MC/DC100%2/2
lc $said eq "d" and $by{"done"}
lc $said eq "d" $by{"done"}
Truth table100%3/3
A and B
A= lc $said eq "d"B= $by{"done"}
ABresult
0X0
100
111
436 79 ▶ return $by{swap}[0] if lc $said eq 'x' && $by{swap};
Branch: 1 branch
BranchTrueFalseTotal
if lc $said eq "x" and $by{"swap"} 1 78 79
Condition100%3/3
lc $said eq "x" and $by{"swap"}
!ll&&!rl&&r
7081
MC/DC100%2/2
lc $said eq "x" and $by{"swap"}
lc $said eq "x" $by{"swap"}
Truth table100%3/3
A and B
A= lc $said eq "x"B= $by{"swap"}
ABresult
0X0
100
111
437 78 ▶ return { kind => 'resign' } if lc $said eq 'r';
Branch: 1 branch
BranchTrueFalseTotal
if lc $said eq "r" 1 77 78
438  
439 77 ▶ return undef unless $said =~ /\A[0-9]+\z/ && $said >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $said =~ /\A[0-9]+\z/ and $said >= 1 20 57 77
Condition100%3/3
$said =~ /\A[0-9]+\z/ and $said >= 1
!ll&&!rl&&r
19157
MC/DC100%2/2
$said =~ /\A[0-9]+\z/ and $said >= 1
$said =~ /\A[0-9]+\z/ $said >= 1
Truth table100%3/3
A and B
A= $said =~ /\A[0-9]+\z/B= $said >= 1
ABresult
0X0
100
111
440 57 my $card = $view->{hand}[ $said - 1 ];
441 57 ▶ return undef unless defined $card;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $card 2 55 57
442  
443 my ($move) = grep {
444 209 ▶ defined $_->{card} && $_->{card} == $card
Condition100%3/3
defined $_->{'card'} && $_->{'card'} == $card
!ll&&!rl&&r
4814120
MC/DC100%2/2
defined $_->{'card'} && $_->{'card'} == $card
defined $_->{'card'} $_->{'card'} == $card
Truth table100%3/3
A && B
A= defined $_->{'card'}B= $_->{'card'} == $card
ABresult
0X0
100
111
445 55 } @{ $view->{legal} };
446  
447 55 return $move;
448 }
449  
450 25 ▶sub cards {
Subroutine cards: called CC=2 SCAR=6.9
Pod documented
451 25 my ($self, $n) = @_;
452 25 ▶ return $n == 1 ? '1 card' : "$n cards";
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 5 20 25
453 }
454  
455 61 ▶sub narration {
Subroutine narration: called CC=17 SCAR=28.4
Pod documented
456 61 my ($self, $view, @events) = @_;
457 61 my $me = $view->{seat};
458 61 my @said;
459  
460 61 for my $event (@events) {
461 114 my $kind = $event->{kind};
462  
463 114 ▶ if ($SAID{$kind}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SAID{$kind}) 64 50 114
464 my $who = !defined $event->{seat} ? 'somebody'
465 64 ▶ : $event->{seat} == $me ? 'you' : 'they';
Branch: 2 branches
BranchTrueFalseTotal
!defined($event->{'seat'}) ? : 0 64 64
$event->{'seat'} == $me ? : 27 37 64
466 my $what = defined $event->{card}
467 64 ▶ ? ' ' . long_name_of($event->{card}) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $event->{'card'} ? : 53 11 64
468 64 push @said, "$who $SAID{$kind}$what";
469 64 next;
470 }
471  
472 50 ▶ if ($kind eq 'bout_end') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "bout_end") 23 27 50
473 23 ▶ if ($event->{taken}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{'taken'}) { } 11 12 23
474 11 my $took = 3 - $event->{next_attacker};
475 push @said, sprintf '%s pick up %s',
476 11 ▶ $took == $me ? 'you' : 'they', $self->cards($event->{cards});
Branch: 1 branch
BranchTrueFalseTotal
$took == $me ? : 10 1 11
477 }
478 else {
479 push @said, sprintf 'the bout is beaten off, %s',
480 12 $self->cards($event->{cards});
481 }
482 23 next;
483 }
484  
485 27 ▶ if ($kind eq 'refill') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "refill") 22 5 27
486 22 ▶ next unless $event->{drawn}{1} || $event->{drawn}{2};
Branch: 1 branch
BranchTrueFalseTotal
unless $event->{"drawn"}{1} or $event->{"drawn"}{2} 5 17 22
Condition100%3/3
$event->{"drawn"}{1} or $event->{"drawn"}{2}
l!l&&r!l&&!r
1165
MC/DC100%2/2
$event->{"drawn"}{1} or $event->{"drawn"}{2}
$event->{"drawn"}{1} $event->{"drawn"}{2}
Truth table100%3/3
A or B
A= $event->{"drawn"}{1}B= $event->{"drawn"}{2}
ABresult
1X1
011
000
487 push @said, sprintf 'you draw %d, they draw %d, %d left',
488 $event->{drawn}{$me}, $event->{drawn}{ 3 - $me },
489 17 $event->{talon};
490 17 next;
491 }
492  
493 5 ▶ if ($kind eq 'out') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "out") 2 3 5
494 2 ▶ push @said, $event->{seat} == $me ? 'you are out' : 'they are out';
Branch: 1 branch
BranchTrueFalseTotal
$event->{'seat'} == $me ? : 0 2 2
495 2 next;
496 }
497  
498 3 ▶ if ($kind eq 'game_end') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "game_end") 3 0 3
499 push @said, !defined $event->{fool} ? 'a draw, and no fool'
500 3 ▶ : $event->{fool} == $me ? 'you are the durak'
Branch: 2 branches
BranchTrueFalseTotal
!defined($event->{'fool'}) ? : 1 2 3
$event->{'fool'} == $me ? : 2 0 2
501 : 'they are the durak';
502 }
503 }
504  
505 61 return @said;
506 }
507  
508 2 ▶sub narrate {
Subroutine narrate: called CC=4 SCAR=14.1
Pod documented
509 2 my ($self, $view, @events) = @_;
510 2 my @said = $self->narration($view, @events);
511 2 ▶ return unless @said;
Branch: 1 branch
BranchTrueFalseTotal
unless @said 0 2 2
512 2 ▶ $self->say('') if grep { $_ =~ /durak|a draw/ } @said;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /durak|a draw/;} @said 2 0 2
513 2 $self->say(" $_") for @said;
514 2 return;
515 }
516  
517 4 ▶sub start {
Subroutine start: called CC=2 SCAR=7.0
Pod documented
518 4 my ($self) = @_;
519 4 my $game = Game::Durak->build(seed => $self->seed);
520 4 ▶ die $game->message . "\n" if ref $game eq 'Game::Durak::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $game eq "Game::Durak::Error" 0 4 4
521 4 $self->game($game);
522 4 return $game;
523 }
524  
525 4 ▶sub run {
Subroutine run: called CC=14 SCAR=27.7
Pod documented
526 4 my ($self) = @_;
527  
528 4 ▶ my $game = $self->game || $self->start;
Condition33%1/3
$self->game || $self->start
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->game || $self->start
$self->game $self->start
Truth table33%1/3
A || B
A= $self->gameB= $self->start
ABresult
1X1
011
000
529 4 my $me = $self->_seat;
530 4 ▶ my $bot = Game::Durak::Bot->new(
Condition50%1/2
$self->seed || ''
l!l
40
MC/DC0%0/1
$self->seed || ''
$self->seed
Truth table50%1/2
A
A= $self->seed
Aresult
11
00
531 level => Game::Durak::Bot->level_for($self->_level),
532 seed => ($self->seed || '') . ':bot',
533 );
534  
535 4 $self->open_screen($game);
536  
537 4 ▶ while (!$game->over) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game->over) 113 1 114
538 113 my $seat = $game->turn;
539 113 my $view = $game->view($seat);
540  
541 113 ▶ if ($seat != $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seat != $me) 34 79 113
542 34 my $move = $bot->choose($view);
543 34 ▶ last unless $move;
Branch: 1 branch
BranchTrueFalseTotal
unless $move 0 34 34
544 34 my @events = $game->apply($seat, $move);
545 34 ▶ last if ref $events[0] eq 'Game::Durak::Error';
Branch: 1 branch
BranchTrueFalseTotal
if ref $events[0] eq "Game::Durak::Error" 0 34 34
546 34 $self->told($self->narration($game->view($me), @events));
547 34 next;
548 }
549  
550 79 my $move;
551 79 ▶ if ($self->picking && $self->enter_raw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->picking and $self->enter_raw) { } 0 79 79
Condition66%2/3
$self->picking and $self->enter_raw
!ll&&!rl&&r
7810
MC/DC0%0/2
$self->picking and $self->enter_raw
$self->picking $self->enter_raw
Truth table66%2/3
A and B
A= $self->pickingB= $self->enter_raw
ABresult
0X0
100
111
552 0 $move = $self->pick_move($view);
553 0 ▶ last unless $move;
Branch: 1 branch
BranchTrueFalseTotal
unless $move 0 0 0
554 }
555 else {
556 79 $self->picking(0);
557 79 $self->position($view);
558  
559 79 my $handle = $self->_in;
560 79 my $said = <$handle>;
561 79 ▶ last unless defined $said;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $said 2 77 79
562  
563 77 $move = $self->move_for($view, $said);
564 77 ▶ unless ($move) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($move) 51 26 77
565 51 $self->told('that is not one of the answers');
566 51 next;
567 }
568 }
569  
570 26 ▶ last if $move->{kind} eq 'quit';
Branch: 1 branch
BranchTrueFalseTotal
if $move->{"kind"} eq "quit" 1 25 26
571  
572 25 my @events = $game->apply($seat, $move);
573 25 ▶ if (ref $events[0] eq 'Game::Durak::Error') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $events[0] eq "Game::Durak::Error") 0 25 25
574 0 $self->told($events[0]->message);
575 0 next;
576 }
577  
578 25 $self->told($self->narration($game->view($me), @events));
579 }
580  
581 4 $self->leave_raw;
582 4 $self->close_screen($game);
583  
584 4 return $game->result;
585 }
586  
587 4 ▶sub open_screen {
Subroutine open_screen: called CC=2 SCAR=9.2
Pod documented
588 4 my ($self, $game) = @_;
589  
590 4 ▶ if ($self->_paint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_paint) 0 4 4
591 0 my $handle = $self->_out;
592 0 print {$handle} "\e[2J\e[H";
593 0 $self->told(sprintf 'durak: the loser is the fool, and seat %d opens',
594 $game->turn);
595 0 return;
596 }
597  
598 4 $self->say('durak: the loser is the fool');
599 4 $self->say('trump is ' . $self->card_suit($game->trump)
600 . ', and seat ' . $game->turn . ' opens');
601 4 return;
602 }
603  
604 87 ▶sub position {
Subroutine position: called CC=4 SCAR=14.5
Pod documented
605 87 my ($self, $view, %o) = @_;
606  
607 87 ▶ my $footer = defined $o{footer} ? $o{footer} : $self->prompt_for($view);
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'footer'} ? : 8 79 87
608  
609 return $self->show($view, footer => $footer,
610 87 ▶ (defined $o{cursor} ? (cursor => $o{cursor}) : ()))
Branch: 2 branches
BranchTrueFalseTotal
if $self->_paint 0 87 87
defined $o{'cursor'} ? : 0 0 0
611 if $self->_paint;
612  
613 87 $self->say($self->table($view, %o));
614 87 $self->say(' ' . $footer);
615 87 return;
616 }
617  
618 4 ▶sub close_screen {
Subroutine close_screen: called CC=6 SCAR=33.6
Pod documented
619 4 my ($self, $game) = @_;
620 4 ▶ return unless $self->_paint;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_paint 4 0 4
621  
622 0 my $view = $game->view($self->_seat);
623 0 my $result = $game->result;
624 0 ▶ my $fool = $result ? $result->{fool} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$result ? : 0 0 0
625 0 ▶ my $over = !$result ? 'you left the table'
Branch: 3 branches
BranchTrueFalseTotal
!$result ? : 0 0 0
!defined($fool) ? : 0 0 0
$fool == $self->_seat ? : 0 0 0
626 : !defined $fool ? 'a draw, and no fool'
627 : $fool == $self->_seat ? 'you are the durak'
628 : 'they are the durak';
629  
630 0 $self->show($view, header => $over, footer => 'the deal is over');
631 0 my $handle = $self->_out;
632 0 print {$handle} "\e[0m\n";
633 0 return;
634 }
635  
636  
637 5 1;
638  
639 __END__
↑ Summary blib/lib/Game/Durak/Table.pm »