Reversi.pm

filter: Statementstmt 92.0% 196 / 213 Branchbran 86.7% 92 / 106 Conditioncond 50.5% 44 / 87 MC/DCmcdc 26.0% 12 / 46 Subroutinesub 89.1% 33 / 37 Podpod 95.2% 20 / 21 totaltotal 77.8% 397 / 510 CC 88 SCAR 22.8
CC
88
Cov
82%
replay
24.7
from_text
20.0
play
12.6
CRAP 9.8
« Reversi/Board.pm ↑ Summary Reversi/Result.pm »
1 package Game::Reversi;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 ▶use Game::Reversi::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Game::Reversi::Move;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Game::Reversi::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Game::Reversi::Opening;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Game::Reversi::Rules;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use Game::Reversi::Notation;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Game::Reversi::Scoring;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Game::Reversi::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 10 our $VERSION = '0.03';
20  
21 has variant => (
22 is => 'ro',
23 isa => Str,
24 default => 'historic'
25 10 );
26  
27 has turn => (
28 is => 'rw'
29 10 );
30  
31 has board => (
32 is => 'rw',
33 isa => ArrayRef
34 10 );
35  
36 has status => (
37 is => 'rw',
38 isa => Str,
39 default => 'active'
40 10 );
41  
42 has [qw/winner result/] => (
43 is => 'rw'
44 10 );
45  
46 has log => (
47 is => 'rw',
48 isa => ArrayRef,
49 default => []
50 10 );
51  
52 has _held_seed => (
53 is => 'ro',
54 init_arg => 'seed',
55 private => 1
56 10 );
57  
58 451 ▶sub BUILD {
Subroutine BUILD: called CC=9 SCAR=22.0
Pod undocumented
59 451 my ($self) = @_;
60 451 my $variant = $self->variant;
61 451 ▶ Carp::croak("Game::Reversi: there is no variant '$variant'")
Branch: 1 branch
BranchTrueFalseTotal
unless "Game::Reversi::Opening"->describes($variant) 0 451 451
62 unless Game::Reversi::Opening->describes($variant);
63  
64 451 ▶ my $given = defined $self->board ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->board ? : 15 436 451
65 451 ▶ $self->board($given ? [ @{ $self->board } ]
Branch: 1 branch
BranchTrueFalseTotal
$given ? : 15 436 451
66 : Game::Reversi::Opening->board_for($variant));
67 Carp::croak('Game::Reversi: a board is an arrayref of 64 cells')
68 451 ▶ unless @{ $self->board } == 64;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->board;} == 64 0 451 451
69  
70 451 ▶ my $first = defined $self->turn ? $self->turn : Game::Reversi::Opening->first;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->turn ? : 15 436 451
71 451 $self->turn(Game::Reversi::Rules->opening_turn($self->board, $first));
72 451 $self->log([]);
73  
74 $self->_emit('sys', 'start', {
75 variant => $variant,
76 first => $first,
77 451 ▶ ($given ? (board => join '', map { defined $_ ? $_ : '.' } @{ $self->board }) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$given ? : 15 436 451
defined $_ ? : 118 842 960
78 });
79  
80 451 ▶ $self->_finish unless defined $self->turn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->turn 1 450 451
81 451 return $self;
82 }
83  
84 15 ▶sub from_board {
Subroutine from_board: called CC=3 SCAR=12.5
Pod documented
85 15 my ($class, $board, %o) = @_;
86 15 ▶ Carp::croak('Game::Reversi: a board is an arrayref of 64 cells')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $board eq "ARRAY" and @$board == 64 0 15 15
Condition33%1/3
ref $board eq "ARRAY" and @$board == 64
!ll&&!rl&&r
0015
MC/DC0%0/2
ref $board eq "ARRAY" and @$board == 64
ref $board eq "ARRAY" @$board == 64
Truth table33%1/3
A and B
A= ref $board eq "ARRAY"B= @$board == 64
ABresult
0X0
100
111
87 unless ref $board eq 'ARRAY' && @$board == 64;
88 15 return $class->new(%o, board => $board);
89 }
90  
91 373 ▶sub seats { return ('b', 'w') }
Subroutine seats: called CC=1 SCAR=0.0
Pod documented
92 353 ▶sub events { return [ @{ $_[0]->log } ] }
Subroutine events: called CC=1 SCAR=0.0
Pod documented
93  
94 2 ▶sub places {
Subroutine places: called CC=2 SCAR=6.9
Pod documented
95 2 my ($self) = @_;
96 2 ▶ return undef unless $self->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result 1 1 2
97 1 return $self->result->places;
98 }
99  
100 1283 ▶sub phase {
Subroutine phase: called CC=2 SCAR=6.9
Pod documented
101 1283 my ($self) = @_;
102 1283 ▶ return Game::Reversi::Rules->in_opening($self->board) ? 'opening' : 'play';
Branch: 1 branch
BranchTrueFalseTotal
'Game::Reversi::Rules'->in_opening($self->board) ? : 144 1139 1283
103 }
104  
105 0 ▶sub seed {
Subroutine seed: not called CC=2 SCAR=17.9
Pod documented
106 0 my ($self) = @_;
107 0 ▶ return undef unless $self->status eq 'finished';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "finished" 0 0 0
108 0 return $self->_held_seed;
109 }
110  
111 571 ▶sub counts { return Game::Reversi::Scoring->count($_[0]->board) }
Subroutine counts: called CC=1 SCAR=0.0
Pod documented
112  
113 9 ▶sub score {
Subroutine score: called CC=3 SCAR=11.0
Pod documented
114 9 my ($self) = @_;
115 9 ▶ return undef unless $self->result && $self->result->natural;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result and $self->result->natural 2 7 9
Condition100%3/3
$self->result and $self->result->natural
!ll&&!rl&&r
117
MC/DC100%2/2
$self->result and $self->result->natural
$self->result $self->result->natural
Truth table100%3/3
A and B
A= $self->resultB= $self->result->natural
ABresult
0X0
100
111
116 7 return $self->result->score;
117 }
118  
119 0 ▶sub scores {
Subroutine scores: not called CC=1 SCAR=6.9
Pod documented
120 0 my ($self) = @_;
121 0 my $count = $self->counts;
122 0 return { map { $_ => { current => $count->{$_} } } $self->seats };
123 }
124  
125 21991 ▶sub legal {
Subroutine legal: called CC=5 SCAR=17.2
Pod documented
126 21991 my ($self, $colour) = @_;
127 21991 ▶ return [] unless $self->status eq 'active';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 4 21987 21991
128 21987 ▶ return [] unless defined $colour && defined $self->turn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $colour and defined $self->turn 0 21987 21987
Condition33%1/3
defined $colour and defined $self->turn
!ll&&!rl&&r
0021987
MC/DC0%0/2
defined $colour and defined $self->turn
defined $colour defined $self->turn
Truth table33%1/3
A and B
A= defined $colourB= defined $self->turn
ABresult
0X0
100
111
129 21987 ▶ return [] unless $colour eq $self->turn;
Branch: 1 branch
BranchTrueFalseTotal
unless $colour eq $self->turn 0 21987 21987
130 21987 return [ Game::Reversi::Rules->legal($self->board, $colour) ];
131 }
132  
133 0 ▶sub waiting_on {
Subroutine waiting_on: not called CC=3 SCAR=24.8
Pod documented
134 0 my ($self) = @_;
135 0 ▶ return () unless $self->status eq 'active' && defined $self->turn;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" and defined $self->turn 0 0 0
Condition0%0/3
$self->status eq "active" and defined $self->turn
!ll&&!rl&&r
000
MC/DC0%0/2
$self->status eq "active" and defined $self->turn
$self->status eq "active" defined $self->turn
Truth table0%0/3
A and B
A= $self->status eq "active"B= defined $self->turn
ABresult
0X0
100
111
136 0 return ($self->turn);
137 }
138  
139 21864 ▶sub play {
Subroutine play: called CC=12 SCAR=25.4
Pod documented
140 21864 my ($self, $colour, $square) = @_;
141  
142 21864 ▶ return Game::Reversi::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 6 21858 21864
143 unless $self->status eq 'active';
144 21858 ▶ return Game::Reversi::Error->throw('not_your_turn')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $colour and defined $self->turn and $colour eq $self->turn 3 21855 21858
Condition50%3/6
defined $colour and defined $self->turn and $colour eq $self->turn
!ll&&!rl&&r
0321855
defined $colour and defined $self->turn
!ll&&!rl&&r
0021858
MC/DC33%1/3
defined $colour and defined $self->turn and $colour eq $self->turn
defined $colour defined $self->turn $colour eq $self->turn
Truth table50%2/4
A and B and C
A= defined $colourB= defined $self->turnC= $colour eq $self->turn
ABCresult
0XX0
10X0
1100
1111
145 unless defined $colour && defined $self->turn && $colour eq $self->turn;
146  
147 21855 my $move;
148 21855 ▶ if (Game::Reversi::Rules->in_opening($self->board)) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Game::Reversi::Rules'->in_opening($self->board)) { } 315 21540 21855
149 315 my $error = Game::Reversi::Opening->check($self->board, $square);
150 315 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 4 311 315
151 311 $move = Game::Reversi::Move->place($square, $colour);
152 311 $self->board(Game::Reversi::Opening->apply($self->board, $square, $colour));
153 311 $self->_emit($colour, 'place', { square => $square });
154 }
155 else {
156 return Game::Reversi::Error->throw('square_taken',
157 21540 ▶ legal => [ map { $_->square } @{ $self->legal($colour) } ])
Branch: 1 branch
BranchTrueFalseTotal
if defined $square and $square >= 0 and $square < 64 and defined $self->board->[$square] 1 21539 21540
Condition44%4/9
defined $square and $square >= 0 and $square < 64 and defined $self->board->[$square]
!ll&&!rl&&r
0215391
defined $square and $square >= 0 and $square < 64
!ll&&!rl&&r
0021540
defined $square and $square >= 0
!ll&&!rl&&r
0021540
MC/DC25%1/4
defined $square and $square >= 0 and $square < 64 and defined $self->board->[$square]
defined $square $square >= 0 $square < 64 defined $self->board->[$square]
Truth table40%2/5
A and B and C and D
A= defined $squareB= $square >= 0C= $square < 64D= defined $self->board->[$square]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
158 if defined $square && $square >= 0 && $square < 64
159 && defined $self->board->[$square];
160  
161 21539 my @flips = Game::Reversi::Board->flips_for($self->board, $square, $colour);
162 return Game::Reversi::Error->throw('no_flip',
163 21539 ▶ legal => [ map { $_->square } @{ $self->legal($colour) } ])
Branch: 1 branch
BranchTrueFalseTotal
unless @flips 2 21537 21539
164 unless @flips;
165  
166 21537 $move = Game::Reversi::Move->play($square, $colour, @flips);
167 21537 $self->board(Game::Reversi::Board->apply($self->board, $square, $colour));
168 21537 $self->_emit($colour, 'play', { square => $square, flips => [ @flips ] });
169 }
170  
171 21848 $self->_advance($colour);
172 21848 return $move;
173 }
174  
175 71 ▶sub pass {
Subroutine pass: called CC=5 SCAR=16.4
Pod documented
176 71 my ($self, $colour) = @_;
177 71 ▶ return Game::Reversi::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 3 68 71
178 unless $self->status eq 'active';
179 68 ▶ return Game::Reversi::Error->throw('not_your_turn')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $colour and defined $self->turn and $colour eq $self->turn 2 66 68
Condition50%3/6
defined $colour and defined $self->turn and $colour eq $self->turn
!ll&&!rl&&r
0266
defined $colour and defined $self->turn
!ll&&!rl&&r
0068
MC/DC33%1/3
defined $colour and defined $self->turn and $colour eq $self->turn
defined $colour defined $self->turn $colour eq $self->turn
Truth table50%2/4
A and B and C
A= defined $colourB= defined $self->turnC= $colour eq $self->turn
ABCresult
0XX0
10X0
1100
1111
180 unless defined $colour && defined $self->turn && $colour eq $self->turn;
181 return Game::Reversi::Error->throw('has_move',
182 66 legal => [ map { $_->square } @{ $self->legal($colour) } ]);
183 }
184  
185 8 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
186 8 my ($self) = @_;
187 8 my $copy = Object::Proto::clone($self);
188 8 $copy->board([ @{ $self->board } ]);
189 8 $copy->log([ map { { %$_, payload => { %{ $_->{payload} } } } } @{ $self->log } ]);
190 8 return $copy;
191 }
192  
193 22905 ▶sub _emit {
Subroutine _emit: called CC=2 SCAR=7.0
194 22905 my ($self, $actor, $kind, $payload) = @_;
195 22905 ▶ push @{ $self->log }, { actor => $actor, kind => $kind, payload => $payload || {} };
Condition50%1/2
$payload || {}
l!l
229050
MC/DC0%0/1
$payload || {}
$payload
Truth table50%1/2
A
A= $payload
Aresult
11
00
196 22905 return;
197 }
198  
199 21848 ▶sub _advance {
Subroutine _advance: called CC=4 SCAR=13.9
200 21848 my ($self, $just_moved) = @_;
201 21848 my ($turn, $forfeited) =
202 Game::Reversi::Rules->next_turn($self->board, $just_moved);
203  
204 21848 ▶ $self->_emit('sys', 'pass', { colour => $forfeited })
Branch: 1 branch
BranchTrueFalseTotal
if defined $forfeited and defined $turn 219 21629 21848
Condition100%3/3
defined $forfeited and defined $turn
!ll&&!rl&&r
21271358219
MC/DC100%2/2
defined $forfeited and defined $turn
defined $forfeited defined $turn
Truth table100%3/3
A and B
A= defined $forfeitedB= defined $turn
ABresult
0X0
100
111
205 if defined $forfeited && defined $turn;
206  
207 21848 $self->turn($turn);
208 21848 ▶ $self->_finish unless defined $turn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $turn 358 21490 21848
209 21848 return;
210 }
211  
212 373 ▶sub _finish {
Subroutine _finish: called CC=8 SCAR=20.8
213 373 my ($self, $winner, $result) = @_;
214 373 my $count = $self->counts;
215  
216 373 ▶ if (!defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 359 14 373
217 359 $winner = Game::Reversi::Scoring->winner($self->board);
218 359 ▶ $result = defined $winner ? 'score' : 'draw';
Branch: 1 branch
BranchTrueFalseTotal
defined $winner ? : 344 15 359
219 }
220  
221 373 ▶ my $natural = ($result eq 'score' || $result eq 'draw') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$result eq 'score' || $result eq 'draw' ? : 359 14 373
Condition100%3/3
$result eq "score" or $result eq "draw"
l!l&&r!l&&!r
3441514
MC/DC100%2/2
$result eq "score" or $result eq "draw"
$result eq "score" $result eq "draw"
Truth table100%3/3
A or B
A= $result eq "score"B= $result eq "draw"
ABresult
1X1
011
000
222 373 $self->winner($winner);
223 373 $self->status('finished');
224 373 $self->turn(undef);
225 $self->result(Game::Reversi::Result->new(
226 winner => $winner,
227 result => $result,
228 counts => $count,
229 score => $natural ? Game::Reversi::Scoring->score($self->board) : undef,
230 places => {
231 373 ▶ map { $_ => (!defined $winner ? 1 : $_ eq $winner ? 1 : 2) } $self->seats
Branch: 3 branches
BranchTrueFalseTotal
$natural ? : 359 14 373
!defined($winner) ? : 36 710 746
$_ eq $winner ? : 355 355 710
232 },
233 ));
234  
235 373 $self->_emit('sys', 'game_end', { winner => $winner, result => $result });
236 373 return;
237 }
238  
239 4 ▶sub timeout {
Subroutine timeout: called CC=5 SCAR=17.5
Pod documented
240 4 my ($self, $colour) = @_;
241 4 ▶ return Game::Reversi::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 1 3 4
242 unless $self->status eq 'active';
243 3 ▶ Carp::croak('Game::Reversi: timeout wants the seat that ran out')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $colour and $colour eq "b" || $colour eq "w" 0 3 3
Condition33%2/6
defined $colour and $colour eq "b" || $colour eq "w"
!ll&&!rl&&r
003
$colour eq "b" or $colour eq "w"
l!l&&r!l&&!r
300
MC/DC0%0/3
defined $colour and $colour eq "b" || $colour eq "w"
defined $colour $colour eq "b" $colour eq "w"
Truth table25%1/4
A and B or C
A= defined $colourB= $colour eq "b"C= $colour eq "w"
ABCresult
0XX0
1000
11X1
1011
244 unless defined $colour && ($colour eq 'b' || $colour eq 'w');
245  
246 3 $self->_emit('sys', 'timeout', { colour => $colour });
247 3 $self->_finish(Game::Reversi::Board->other($colour), 'timeout');
248 3 return $self->result;
249 }
250  
251 4 ▶sub abandon {
Subroutine abandon: called CC=2 SCAR=6.9
Pod documented
252 4 my ($self) = @_;
253 4 ▶ return Game::Reversi::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 1 3 4
254 unless $self->status eq 'active';
255 3 $self->_emit('sys', 'abandon', {});
256 3 $self->_finish(undef, 'abandoned');
257 3 return $self->result;
258 }
259  
260 9 ▶sub resign {
Subroutine resign: called CC=5 SCAR=17.5
Pod documented
261 9 my ($self, $colour) = @_;
262 9 ▶ return Game::Reversi::Error->throw('game_over')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status eq "active" 1 8 9
263 unless $self->status eq 'active';
264 8 ▶ return Game::Reversi::Error->throw('not_your_turn')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $colour and $colour eq "b" || $colour eq "w" 0 8 8
Condition33%2/6
defined $colour and $colour eq "b" || $colour eq "w"
!ll&&!rl&&r
008
$colour eq "b" or $colour eq "w"
l!l&&r!l&&!r
800
MC/DC0%0/3
defined $colour and $colour eq "b" || $colour eq "w"
defined $colour $colour eq "b" $colour eq "w"
Truth table25%1/4
A and B or C
A= defined $colourB= $colour eq "b"C= $colour eq "w"
ABCresult
0XX0
1000
11X1
1011
265 unless defined $colour && ($colour eq 'b' || $colour eq 'w');
266  
267 8 $self->_emit($colour, 'resign', {});
268 8 $self->_finish(Game::Reversi::Board->other($colour), 'resign');
269 8 return $self->result;
270 }
271  
272 15 ▶sub replay {
Subroutine replay: called CC=23 SCAR=32.1
Pod documented
273 15 my ($self, $log) = @_;
274 15 ▶ Carp::croak('Game::Reversi: a log is an arrayref of events')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $log eq "ARRAY" 1 14 15
275 unless ref $log eq 'ARRAY';
276 Carp::croak('Game::Reversi: replay wants a game that has not been played')
277 14 ▶ unless @{ $self->log } == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->log;} == 1 1 13 14
278  
279 13 my @events = @$log;
280 13 my $start = shift @events;
281 Carp::croak('Game::Reversi: the log does not open with a start')
282 unless $start && ($start->{actor} // '') eq 'sys'
283 13 ▶ && ($start->{kind} // '') eq 'start';
Branch: 1 branch
BranchTrueFalseTotal
unless $start and ($start->{"actor"} // "") eq "sys" and ($start->{"kind"} // "") eq "start" 1 12 13
Condition60%6/10
$start and ($start->{"actor"} // "") eq "sys" and ($start->{"kind"} // "") eq "start"
!ll&&!rl&&r
1012
$start and ($start->{"actor"} // "") eq "sys"
!ll&&!rl&&r
0112
$start->{"actor"} // ""
l!l
130
$start->{"kind"} // ""
l!l
120
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
284 Carp::croak('Game::Reversi: the log was made under a different variant')
285 12 ▶ unless ($start->{payload}{variant} // '') eq $self->variant;
Branch: 1 branch
BranchTrueFalseTotal
unless ($start->{"payload"}{"variant"} // "") eq $self->variant 1 11 12
Condition50%1/2
$start->{"payload"}{"variant"} // ""
l!l
120
MC/DC0%0/1
$start->{"payload"}{"variant"} // ""
$start->{"payload"}{"variant"}
Truth table50%1/2
A
A= $start->{"payload"}{"variant"}
Aresult
11
00
286  
287 11 ▶ my $began = join '', map { defined $_ ? $_ : '.' } @{ $self->board };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 4 700 704
288 11 my $logged = $start->{payload}{board};
289 11 ▶ Carp::croak('Game::Reversi: the log began from a different position')
Branch: 1 branch
BranchTrueFalseTotal
if defined $logged and $logged ne $began 0 11 11
Condition33%1/3
defined $logged and $logged ne $began
!ll&&!rl&&r
1100
MC/DC0%0/2
defined $logged and $logged ne $began
defined $logged $logged ne $began
Truth table33%1/3
A and B
A= defined $loggedB= $logged ne $began
ABresult
0X0
100
111
290 if defined($logged) && $logged ne $began;
291  
292 11 for my $event (@events) {
293 359 ▶ my $kind = $event->{kind} // '';
Condition50%1/2
$event->{"kind"} // ""
l!l
3590
MC/DC0%0/1
$event->{"kind"} // ""
$event->{"kind"}
Truth table50%1/2
A
A= $event->{"kind"}
Aresult
11
00
294  
295 359 ▶ if (($event->{actor} // '') eq 'sys') {
Branch: 1 branch
BranchTrueFalseTotal
if (($event->{"actor"} // "") eq "sys") 16 343 359
Condition50%1/2
$event->{"actor"} // ""
l!l
3590
MC/DC0%0/1
$event->{"actor"} // ""
$event->{"actor"}
Truth table50%1/2
A
A= $event->{"actor"}
Aresult
11
00
296 16 ▶ $self->timeout($event->{payload}{colour}) if $kind eq 'timeout';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "timeout" 1 15 16
297 16 ▶ $self->abandon if $kind eq 'abandon';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "abandon" 1 15 16
298 16 next;
299 }
300  
301 my $result = $kind eq 'resign'
302 ? $self->resign($event->{actor})
303 343 ▶ : $self->play($event->{actor}, $event->{payload}{square});
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'resign' ? : 1 342 343
304 343 ▶ Carp::croak('Game::Reversi: the log does not replay: '
Branch: 1 branch
BranchTrueFalseTotal
if ref $result and $result->isa("Game::Reversi::Error") 3 340 343
Condition66%2/3
ref $result and $result->isa("Game::Reversi::Error")
!ll&&!rl&&r
03403
MC/DC50%1/2
ref $result and $result->isa("Game::Reversi::Error")
ref $result $result->isa("Game::Reversi::Error")
Truth table66%2/3
A and B
A= ref $resultB= $result->isa("Game::Reversi::Error")
ABresult
0X0
100
111
305 . $result->stringify)
306 if ref $result && $result->isa('Game::Reversi::Error');
307 }
308  
309 8 my $ours = join '|', map { _signature($_) } @{ $self->log };
310 8 my $theirs = join '|', map { _signature($_) } @$log;
311 8 ▶ Carp::croak('Game::Reversi: the log does not replay to itself, so it '
Branch: 1 branch
BranchTrueFalseTotal
unless $ours eq $theirs 2 6 8
312 . 'records something this game would not have produced')
313 unless $ours eq $theirs;
314  
315 6 return $self;
316 }
317  
318 718 ▶sub _signature {
Subroutine _signature: called CC=6 SCAR=18.4
319 718 my ($event) = @_;
320 718 ▶ my $payload = $event->{payload} || {};
Condition50%1/2
$event->{'payload'} || {}
l!l
7180
MC/DC0%0/1
$event->{'payload'} || {}
$event->{'payload'}
Truth table50%1/2
A
A= $event->{'payload'}
Aresult
11
00
321 return join ':', $event->{actor} // '?', $event->{kind} // '?',
322 join ',', map {
323 718 ▶ my $v = $payload->{$_};
Condition50%2/4
$event->{"actor"} // "?"
l!l
7180
$event->{"kind"} // "?"
l!l
7180
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
324 1358 ▶ $_ . '=' . (ref $v eq 'ARRAY' ? join('.', @$v) : defined $v ? $v : '')
Branch: 2 branches
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 612 746 1358
defined $v ? : 744 2 746
325 } sort keys %$payload;
326 }
327  
328 7 ▶sub to_text {
Subroutine to_text: called CC=2 SCAR=6.9
Pod documented
329 7 my ($self) = @_;
330 return Game::Reversi::Notation->render(
331 448 [ map { $_->{payload}{square} }
332 7 ▶ grep { $_->{kind} eq 'place' || $_->{kind} eq 'play' } @{ $self->log } ]);
Condition100%3/3
$_->{'kind'} eq 'place' || $_->{'kind'} eq 'play'
l!l&&r!l&&!r
2842018
MC/DC100%2/2
$_->{'kind'} eq 'place' || $_->{'kind'} eq 'play'
$_->{'kind'} eq 'place' $_->{'kind'} eq 'play'
Truth table100%3/3
A || B
A= $_->{'kind'} eq 'place'B= $_->{'kind'} eq 'play'
ABresult
1X1
011
000
333 }
334  
335 0 ▶sub from_text {
Subroutine from_text: not called CC=4 SCAR=30.0
Pod documented
336 0 my ($class, $text, %o) = @_;
337 0 my $self = $class->new(%o);
338 0 for my $square (@{ Game::Reversi::Notation->parse($text) }) {
339 0 my $result = $self->play($self->turn, $square);
340 0 ▶ Carp::croak('Game::Reversi: the transcript does not fit this game: '
Branch: 1 branch
BranchTrueFalseTotal
if ref $result and $result->can("error") 0 0 0
Condition0%0/3
ref $result and $result->can("error")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $result and $result->can("error")
ref $result $result->can("error")
Truth table0%0/3
A and B
A= ref $resultB= $result->can("error")
ABresult
0X0
100
111
341 . $result->stringify) if ref $result && $result->can('error');
342 }
343 0 return $self;
344 }
345  
346 10 1;
347  
348 __END__
« Reversi/Board.pm ↑ Summary Reversi/Result.pm »