blib/lib/Game/Oware.pm

filter: Statementstmt 99.5% 221 / 222 Branchbran 82.5% 71 / 86 Conditioncond 53.2% 33 / 62 MC/DCmcdc 16.1% 5 / 31 Subroutinesub 100% 38 / 38 Podpod 94.7% 18 / 19 totaltotal 84.2% 386 / 458 CC 71 SCAR 21.5
CC
71
Cov
88%
replay
23.7
play
10.1
_signature
9.7
CRAP 8.6
« blib/lib/Game/Oware/Terminal.pm ↑ Summary blib/lib/Game/Oware/Bot.pm »
1 package Game::Oware;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 ▶use Game::Oware::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 17 ▶use Game::Oware::Move;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 17 ▶use Game::Oware::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 17 ▶use Game::Oware::Rules;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 17 ▶use Game::Oware::Scoring;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use Game::Oware::Notation;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use Game::Oware::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶use Game::Oware::Variant ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 17 our $VERSION = '0.03';
20  
21 has variant => (
22 is => 'ro',
23 isa => Str,
24 default => 'abapa'
25 17 );
26  
27 has board => (
28 is => 'rw',
29 isa => ArrayRef
30 17 );
31  
32 17 has turn => (is => 'rw');
33  
34 has status => (
35 is => 'rw',
36 isa => Str,
37 default => 'active'
38 17 );
39  
40 17 has [qw/ winner result /] => (is => 'rw');
41  
42 has log => (
43 is => 'rw',
44 isa => ArrayRef,
45 default => []
46 17 );
47  
48 has no_capture => (
49 is => 'rw',
50 isa => Int,
51 default => 0
52 17 );
53  
54 has seen => (
55 is => 'rw',
56 isa => HashRef,
57 default => {}
58 17 );
59  
60 has _held_seed => (
61 is => 'ro',
62 init_arg => 'seed',
63 private => 1
64 17 );
65  
66 123 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
67 123 my ($self) = @_;
68  
69 123 Game::Oware::Variant::check_variant($self->variant);
70  
71 123 ▶ $self->board(Game::Oware::Board->opening) unless $self->board;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->board 73 50 123
72 Carp::croak('Game::Oware: a board is fourteen cells')
73 123 ▶ unless @{ $self->board } == Game::Oware::Board->CELLS;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->board;} == "Game::Oware::Board"->CELLS 0 123 123
74  
75 123 ▶ $self->turn('p1') unless defined $self->turn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->turn 123 0 123
76  
77 $self->_emit('sys', 'start', {
78 variant => $self->variant,
79 first => $self->turn,
80 123 board => join(',', @{ $self->board }),
81 });
82  
83 123 $self->_remember;
84  
85 123 return $self;
86 }
87  
88 1 ▶sub seats { return qw/ p1 p2 / }
Subroutine seats: called CC=1 SCAR=0.0
Pod documented
89  
90 29 ▶sub events { return [ @{ $_[0]->log } ] }
Subroutine events: called CC=1 SCAR=0.0
Pod documented
91  
92 2855 ▶sub other { return Game::Oware::Board->other($_[1]) }
Subroutine other: called CC=1 SCAR=0.0
Pod documented
93  
94 75 ▶sub captured { return Game::Oware::Scoring->captured($_[0]->board) }
Subroutine captured: called CC=1 SCAR=0.0
Pod documented
95  
96 2 ▶sub score { return Game::Oware::Scoring->score($_[0]->board, $_[0]->status) }
Subroutine score: called CC=1 SCAR=0.0
Pod documented
97  
98 1 ▶sub scores {
Subroutine scores: called CC=1 SCAR=0.0
Pod documented
99 1 my ($self) = @_;
100 1 my $captured = $self->captured;
101 1 return { map { $_ => { current => $captured->{$_} } } $self->seats };
102 }
103  
104 1 ▶sub places {
Subroutine places: called CC=2 SCAR=8.1
Pod documented
105 1 my ($self) = @_;
106 1 ▶ return undef unless $self->status eq 'finished';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "finished" 1 0 1
107 0 return $self->result->places;
108 }
109  
110 3 ▶sub seed {
Subroutine seed: called CC=2 SCAR=6.9
Pod documented
111 3 my ($self) = @_;
112 3 ▶ return undef unless $self->status eq 'finished';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "finished" 1 2 3
113 2 return $self->_held_seed;
114 }
115  
116 9042 ▶sub legal {
Subroutine legal: called CC=4 SCAR=15.6
Pod documented
117 9042 my ($self, $seat) = @_;
118 9042 ▶ return [] unless $self->status eq 'active';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 0 9042 9042
119 9042 ▶ return [] unless defined $seat && $seat eq $self->turn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $seat eq $self->turn 0 9042 9042
Condition33%1/3
defined $seat and $seat eq $self->turn
!ll&&!rl&&r
009042
MC/DC0%0/2
defined $seat and $seat eq $self->turn
defined $seat $seat eq $self->turn
Truth table33%1/3
A and B
A= defined $seatB= $seat eq $self->turn
ABresult
0X0
100
111
120 9042 return [ Game::Oware::Rules->legal_moves($self->board, $seat, $self->variant) ];
121 }
122  
123 2645 ▶sub waiting_on {
Subroutine waiting_on: called CC=2 SCAR=7.1
Pod documented
124 2645 my ($self) = @_;
125 2645 ▶ return () unless $self->status eq 'active';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 0 2645 2645
126 2645 return ($self->turn);
127 }
128  
129 2836 ▶sub play {
Subroutine play: called CC=10 SCAR=23.1
Pod documented
130 2836 my ($self, $seat, $house) = @_;
131  
132 2836 ▶ return Game::Oware::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 2 2834 2836
133 unless $self->status eq 'active';
134  
135 2834 ▶ return Game::Oware::Error->throw('not_your_turn')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $seat eq "p1" || $seat eq "p2" and $seat eq $self->turn 2 2832 2834
Condition55%5/9
defined $seat and $seat eq "p1" || $seat eq "p2" and $seat eq $self->turn
!ll&&!rl&&r
022832
defined $seat and $seat eq "p1" || $seat eq "p2"
!ll&&!rl&&r
002834
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
142814060
MC/DC25%1/4
defined $seat and $seat eq "p1" || $seat eq "p2" and $seat eq $self->turn
defined $seat $seat eq "p1" $seat eq "p2" $seat eq $self->turn
Truth table50%3/6
A and B or C and D
A= defined $seatB= $seat eq "p1"C= $seat eq "p2"D= $seat eq $self->turn
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
136 unless defined $seat && ($seat eq 'p1' || $seat eq 'p2')
137 && $seat eq $self->turn;
138  
139 2832 Game::Oware::Board->assert_house($house);
140  
141 2831 ▶ return Game::Oware::Error->throw('not_your_house')
Branch: 1 branch
BranchTrueFalseTotal
unless "Game::Oware::Board"->owner_of($house) eq $seat 2 2829 2831
142 unless Game::Oware::Board->owner_of($house) eq $seat;
143  
144 2829 ▶ return Game::Oware::Error->throw('empty_house')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->board->[$house] 1 2828 2829
145 unless $self->board->[$house];
146  
147 2828 my $legal = $self->legal($seat);
148 return Game::Oware::Error->throw('must_feed', legal => [ @$legal ])
149 2828 ▶ unless grep { $_ == $house } @$legal;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ == $house;} @$legal 3 2825 2828
150  
151 2825 my ($next, $move) =
152 Game::Oware::Rules->resolve($self->board, $house, $seat, $self->variant);
153  
154 2825 $self->board($next);
155  
156 2825 ▶ if ($move->taken) {
Branch: 1 branch
BranchTrueFalseTotal
if ($move->taken) { } 297 2528 2825
157 297 $self->no_capture(0);
158 297 $self->seen({});
159 }
160 else {
161 2528 $self->no_capture($self->no_capture + 1);
162 }
163  
164 $self->_emit($seat, 'sow', {
165 house => $house,
166 2825 captured => [ @{ $move->captured } ],
167 taken => $move->taken,
168 slammed => $move->slammed,
169 2825 forfeited => [ @{ $move->forfeited } ],
170 });
171  
172 2825 $self->_after($move);
173  
174 2825 return $move;
175 }
176  
177 3 ▶sub timeout {
Subroutine timeout: called CC=5 SCAR=18.9
Pod documented
178 3 my ($self, $seat) = @_;
179 3 ▶ return Game::Oware::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 0 3 3
180 unless $self->status eq 'active';
181 3 ▶ Carp::croak('Game::Oware: a seat is p1 or p2')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $seat eq "p1" || $seat eq "p2" 0 3 3
Condition33%2/6
defined $seat and $seat eq "p1" || $seat eq "p2"
!ll&&!rl&&r
003
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
300
MC/DC0%0/3
defined $seat and $seat eq "p1" || $seat eq "p2"
defined $seat $seat eq "p1" $seat eq "p2"
Truth table25%1/4
A and B or C
A= defined $seatB= $seat eq "p1"C= $seat eq "p2"
ABCresult
0XX0
1000
11X1
1011
182 unless defined $seat && ($seat eq 'p1' || $seat eq 'p2');
183  
184 3 $self->_emit('sys', 'timeout', { p => $seat });
185 3 return $self->_finish($self->other($seat), 'timeout', 'timeout');
186 }
187  
188 1 ▶sub abandon {
Subroutine abandon: called CC=2 SCAR=7.0
Pod documented
189 1 my ($self) = @_;
190 1 ▶ return Game::Oware::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 0 1 1
191 unless $self->status eq 'active';
192  
193 1 $self->_emit('sys', 'abandon', {});
194 1 return $self->_finish(undef, 'abandoned', 'abandon');
195 }
196  
197 8 ▶sub resign {
Subroutine resign: called CC=5 SCAR=17.8
Pod documented
198 8 my ($self, $seat) = @_;
199 8 ▶ return Game::Oware::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 0 8 8
200 unless $self->status eq 'active';
201 8 ▶ Carp::croak('Game::Oware: a seat is p1 or p2')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $seat eq "p1" || $seat eq "p2" 0 8 8
Condition50%3/6
defined $seat and $seat eq "p1" || $seat eq "p2"
!ll&&!rl&&r
008
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
620
MC/DC0%0/3
defined $seat and $seat eq "p1" || $seat eq "p2"
defined $seat $seat eq "p1" $seat eq "p2"
Truth table50%2/4
A and B or C
A= defined $seatB= $seat eq "p1"C= $seat eq "p2"
ABCresult
0XX0
1000
11X1
1011
202 unless defined $seat && ($seat eq 'p1' || $seat eq 'p2');
203  
204 8 $self->_emit($seat, 'resign', {});
205 8 return $self->_finish($self->other($seat), 'resign', 'resign');
206 }
207  
208 1 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
209 1 my ($self) = @_;
210 1 my $copy = Object::Proto::clone($self);
211 1 $copy->board([ @{ $self->board } ]);
212 1 $copy->log([ map { { %$_, payload => { %{ $_->{payload} } } } } @{ $self->log } ]);
213 1 $copy->seen({ %{ $self->seen } });
214 1 return $copy;
215 }
216  
217 8 ▶sub to_text {
Subroutine to_text: called CC=1 SCAR=0.0
Pod documented
218 8 my ($self) = @_;
219 return Game::Oware::Notation->render(
220 8 [ map { $_->{payload}{house} } grep { $_->{kind} eq 'sow' } @{ $self->log } ]);
221 }
222  
223 1 ▶sub from_text {
Subroutine from_text: called CC=4 SCAR=14.5
Pod documented
224 1 my ($class, $text, %options) = @_;
225 1 my $game = $class->new(%options);
226 1 for my $house (@{ Game::Oware::Notation->parse($text) }) {
227 12 my $out = $game->play($game->turn, $house);
228 12 ▶ Carp::croak('Game::Oware: the transcript does not play: ' . $out->stringify)
Branch: 1 branch
BranchTrueFalseTotal
if ref $out and $out->isa("Game::Oware::Error") 0 12 12
Condition33%1/3
ref $out and $out->isa("Game::Oware::Error")
!ll&&!rl&&r
0120
MC/DC0%0/2
ref $out and $out->isa("Game::Oware::Error")
ref $out $out->isa("Game::Oware::Error")
Truth table33%1/3
A and B
A= ref $outB= $out->isa("Game::Oware::Error")
ABresult
0X0
100
111
229 if ref $out && $out->isa('Game::Oware::Error');
230 }
231 1 return $game;
232 }
233  
234 11 ▶sub replay {
Subroutine replay: called CC=22 SCAR=31.7
Pod documented
235 11 my ($self, $log) = @_;
236  
237 11 ▶ Carp::croak('Game::Oware: a log is an arrayref of events')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $log eq "ARRAY" 0 11 11
238 unless ref $log eq 'ARRAY';
239 Carp::croak('Game::Oware: replay wants a game that has not been played')
240 11 ▶ unless @{ $self->log } == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->log;} == 1 1 10 11
241  
242 10 my @events = @$log;
243 10 my $start = shift @events;
244 Carp::croak('Game::Oware: the log does not open with a start')
245 unless $start && ($start->{actor} // '') eq 'sys'
246 10 ▶ && ($start->{kind} // '') eq 'start';
Branch: 1 branch
BranchTrueFalseTotal
unless $start and ($start->{"actor"} // "") eq "sys" and ($start->{"kind"} // "") eq "start" 1 9 10
Condition60%6/10
$start and ($start->{"actor"} // "") eq "sys" and ($start->{"kind"} // "") eq "start"
!ll&&!rl&&r
109
$start and ($start->{"actor"} // "") eq "sys"
!ll&&!rl&&r
019
$start->{"actor"} // ""
l!l
100
$start->{"kind"} // ""
l!l
90
MC/DC0%0/3
$start and ($start->{"actor"} // "") eq "sys" and ($start->{"kind"} // "") eq "start"
$start $start->{"actor"} $start->{"kind"}
Truth table25%1/4
A and B and C
A= $startB= $start->{"actor"}C= $start->{"kind"}
ABCresult
0XX0
10X0
1100
1111
247 Carp::croak('Game::Oware: the log was made under a different variant')
248 9 ▶ unless ($start->{payload}{variant} // '') eq $self->variant;
Branch: 1 branch
BranchTrueFalseTotal
unless ($start->{"payload"}{"variant"} // "") eq $self->variant 1 8 9
Condition50%1/2
$start->{"payload"}{"variant"} // ""
l!l
90
MC/DC0%0/1
$start->{"payload"}{"variant"} // ""
$start->{"payload"}{"variant"}
Truth table50%1/2
A
A= $start->{"payload"}{"variant"}
Aresult
11
00
249  
250 8 my $began = join ',', @{ $self->board };
251 8 my $logged = $start->{payload}{board};
252 8 ▶ Carp::croak('Game::Oware: the log began from a different position')
Branch: 1 branch
BranchTrueFalseTotal
if defined $logged and $logged ne $began 1 7 8
Condition66%2/3
defined $logged and $logged ne $began
!ll&&!rl&&r
071
MC/DC50%1/2
defined $logged and $logged ne $began
defined $logged $logged ne $began
Truth table66%2/3
A and B
A= defined $loggedB= $logged ne $began
ABresult
0X0
100
111
253 if defined($logged) && $logged ne $began;
254  
255 7 for my $event (@events) {
256 153 ▶ my $actor = $event->{actor} // '';
Condition50%1/2
$event->{"actor"} // ""
l!l
1530
MC/DC0%0/1
$event->{"actor"} // ""
$event->{"actor"}
Truth table50%1/2
A
A= $event->{"actor"}
Aresult
11
00
257 153 ▶ my $kind = $event->{kind} // '';
Condition50%1/2
$event->{"kind"} // ""
l!l
1530
MC/DC0%0/1
$event->{"kind"} // ""
$event->{"kind"}
Truth table50%1/2
A
A= $event->{"kind"}
Aresult
11
00
258  
259 153 ▶ if ($actor eq 'sys') {
Branch: 1 branch
BranchTrueFalseTotal
if ($actor eq "sys") 6 147 153
260 6 ▶ $self->timeout($event->{payload}{p}) if $kind eq 'timeout';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "timeout" 1 5 6
261 6 ▶ $self->abandon if $kind eq 'abandon';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "abandon" 0 6 6
262 6 next;
263 }
264  
265 my $out = $kind eq 'resign'
266 ? $self->resign($actor)
267 147 ▶ : $self->play($actor, $event->{payload}{house});
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'resign' ? : 1 146 147
268 147 ▶ Carp::croak('Game::Oware: the log does not replay: ' . $out->stringify)
Branch: 1 branch
BranchTrueFalseTotal
if ref $out and $out->isa("Game::Oware::Error") 1 146 147
Condition66%2/3
ref $out and $out->isa("Game::Oware::Error")
!ll&&!rl&&r
01461
MC/DC50%1/2
ref $out and $out->isa("Game::Oware::Error")
ref $out $out->isa("Game::Oware::Error")
Truth table66%2/3
A and B
A= ref $outB= $out->isa("Game::Oware::Error")
ABresult
0X0
100
111
269 if ref $out && $out->isa('Game::Oware::Error');
270 }
271  
272 6 my $ours = join '|', map { _signature($_) } @{ $self->log };
273 6 my $theirs = join '|', map { _signature($_) } @$log;
274 6 ▶ Carp::croak('Game::Oware: the log does not replay to itself, so it records '
Branch: 1 branch
BranchTrueFalseTotal
unless $ours eq $theirs 3 3 6
275 . 'something this game would not have produced')
276 unless $ours eq $theirs;
277  
278 3 return $self;
279 }
280  
281 3025 ▶sub _emit {
Subroutine _emit: called CC=2 SCAR=7.0
282 3025 my ($self, $actor, $kind, $payload) = @_;
283 3025 ▶ push @{ $self->log },
Condition50%1/2
$payload || {}
l!l
30250
MC/DC0%0/1
$payload || {}
$payload
Truth table50%1/2
A
A= $payload
Aresult
11
00
284 { actor => $actor, kind => $kind, payload => $payload || {} };
285 3025 return;
286 }
287  
288 2929 ▶sub _key {
Subroutine _key: called CC=1 SCAR=0.0
289 2929 my ($self) = @_;
290 2929 return join(',', @{ $self->board }) . ':' . $self->turn;
291 }
292  
293 2929 ▶sub _remember {
Subroutine _remember: called CC=1 SCAR=0.0
294 2929 my ($self) = @_;
295 2929 my $seen = $self->seen;
296 2929 return ++$seen->{ $self->_key };
297 }
298  
299 2825 ▶sub _after {
Subroutine _after: called CC=6 SCAR=17.9
300 2825 my ($self, $move) = @_;
301  
302 2825 my $target = Game::Oware::Scoring->target_reached($self->board);
303 2825 ▶ return $self->_finish($target, 'score', 'target') if $target;
Branch: 1 branch
BranchTrueFalseTotal
if $target 18 2807 2825
304  
305 2807 ▶ return $self->_finish(undef, 'draw', 'even')
Branch: 1 branch
BranchTrueFalseTotal
if "Game::Oware::Scoring"->is_draw($self->board) 1 2806 2807
306 if Game::Oware::Scoring->is_draw($self->board);
307  
308 2806 my $limit = Game::Oware::Variant::plies_without_capture($self->variant);
309 2806 ▶ if ($self->no_capture >= $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->no_capture >= $limit) 1 2805 2806
310 1 $self->board(Game::Oware::Scoring->sweep_split($self->board));
311 1 $self->_emit('sys', 'cycle', { why => 'plies', plies => $self->no_capture });
312 1 return $self->_settle('cycle');
313 }
314  
315 2805 $self->turn($self->other($move->seat));
316  
317 2805 my $repeats = $self->_remember;
318 2805 ▶ if ($repeats >= Game::Oware::Variant::repetition_limit($self->variant)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeats >= Game::Oware::Variant::repetition_limit($self->variant)) 7 2798 2805
319 7 $self->board(Game::Oware::Scoring->sweep_split($self->board));
320 7 $self->_emit('sys', 'cycle', { why => 'repetition', times => $repeats });
321 7 return $self->_settle('cycle');
322 }
323  
324 2798 ▶ unless (@{ $self->legal($self->turn) }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->legal($self->turn);}) 9 2789 2798
325 9 my $swept = $self->turn;
326 9 $self->board(Game::Oware::Scoring->sweep_to($self->board, $swept));
327 9 $self->_emit('sys', 'sweep', { p => $swept, why => 'no_feed' });
328 9 return $self->_settle('no_feed');
329 }
330  
331 2789 return;
332 }
333  
334 17 ▶sub _settle {
Subroutine _settle: called CC=3 SCAR=11.0
335 17 my ($self, $reason) = @_;
336  
337 17 my $captured = $self->captured;
338 return $self->_finish(undef, 'draw', $reason)
339 17 ▶ if $captured->{p1} == $captured->{p2};
Branch: 1 branch
BranchTrueFalseTotal
if $captured->{"p1"} == $captured->{"p2"} 7 10 17
340  
341 10 ▶ my $winner = $captured->{p1} > $captured->{p2} ? 'p1' : 'p2';
Branch: 1 branch
BranchTrueFalseTotal
$captured->{'p1'} > $captured->{'p2'} ? : 4 6 10
342 10 return $self->_finish($winner, 'score', $reason);
343 }
344  
345 48 ▶sub _finish {
Subroutine _finish: called CC=4 SCAR=13.9
346 48 my ($self, $winner, $result, $reason) = @_;
347  
348 48 $self->status('finished');
349 48 $self->winner($winner);
350  
351 48 my $captured = $self->captured;
352 48 ▶ my $natural = $result eq 'score' || $result eq 'draw';
Condition100%3/3
$result eq 'score' || $result eq 'draw'
l!l&&r!l&&!r
28812
MC/DC100%2/2
$result eq 'score' || $result eq 'draw'
$result eq 'score' $result eq 'draw'
Truth table100%3/3
A || B
A= $result eq 'score'B= $result eq 'draw'
ABresult
1X1
011
000
353  
354 48 ▶ my %places = defined $winner
Branch: 1 branch
BranchTrueFalseTotal
defined $winner ? : 39 9 48
355 ? ($winner => 1, $self->other($winner) => 2)
356 : (p1 => 1, p2 => 1);
357  
358 48 ▶ my $done = Game::Oware::Result->new(
Branch: 1 branch
BranchTrueFalseTotal
$natural ? : 36 12 48
359 winner => $winner,
360 result => $result,
361 reason => $reason,
362 captured => $captured,
363 ($natural ? (score => $captured) : ()),
364 places => \%places,
365 );
366  
367 48 $self->result($done);
368 48 $self->_emit('sys', 'game_end', {
369 winner => $winner,
370 result => $result,
371 reason => $reason,
372 captured => $captured,
373 });
374  
375 48 return $done;
376 }
377  
378 292 ▶sub _signature {
Subroutine _signature: called CC=9 SCAR=22.8
379 292 my ($event) = @_;
380 292 ▶ my $payload = $event->{payload} || {};
Condition50%1/2
$event->{'payload'} || {}
l!l
2920
MC/DC0%0/1
$event->{'payload'} || {}
$event->{'payload'}
Truth table50%1/2
A
A= $event->{'payload'}
Aresult
11
00
381 292 my @pairs;
382 292 for my $key (sort keys %$payload) {
383 1406 my $value = $payload->{$key};
384 1406 ▶ $value = join '.', @$value if ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 536 870 1406
385 1406 ▶ $value = join ';', map { "$_=" . ($value->{$_} // '') } sort keys %$value
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 6 1400 1406
Condition50%1/2
$value->{$_} // ""
l!l
120
MC/DC0%0/1
$value->{$_} // ""
$value->{$_}
Truth table50%1/2
A
A= $value->{$_}
Aresult
11
00
386 if ref $value eq 'HASH';
387 1406 ▶ push @pairs, $key . '=' . (defined $value ? $value : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 1406 0 1406
388 }
389 292 ▶ return ($event->{actor} // '') . ':' . ($event->{kind} // '')
Condition50%2/4
$event->{"actor"} // ""
l!l
2920
$event->{"kind"} // ""
l!l
2920
MC/DC0%0/1
$event->{"actor"} // ""
$event->{"actor"}
MC/DC0%0/1
$event->{"kind"} // ""
$event->{"kind"}
Truth table50%1/2
A
A= $event->{"actor"}
Aresult
11
00
Truth table50%1/2
A
A= $event->{"kind"}
Aresult
11
00
390 . ':' . join(',', @pairs);
391 }
392  
393 17 1;
394  
395 __END__
« blib/lib/Game/Oware/Terminal.pm ↑ Summary blib/lib/Game/Oware/Bot.pm »