| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | unless Game::Reversi::Opening->describes($variant); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 451 | ▶ | my $given = defined $self->board ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 451 | ▶ | $self->board($given ? [ @{ $self->board } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 451 | ▶ | my $first = defined $self->turn ? $self->turn : Game::Reversi::Opening->first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 451 | ▶ | $self->_finish unless defined $self->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $board eq "ARRAY" and @$board == 64
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->result and $self->result->natural
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 21987 | ▶ | return [] unless defined $colour && defined $self->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $colour and defined $self->turn
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 21987 | ▶ | return [] unless $colour eq $self->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$self->status eq "active" and defined $self->turn
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 21858 | ▶ | return Game::Reversi::Error->throw('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $colour and defined $self->turn and $colour eq $self->turn
defined $colour and defined $self->turn
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 315 | my $error = Game::Reversi::Opening->check($self->board, $square); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 315 | ▶ | return $error if $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition44%4/9
defined $square and $square >= 0 and $square < 64 and defined $self->board->[$square]
defined $square and $square >= 0 and $square < 64
defined $square and $square >= 0
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 68 | ▶ | return Game::Reversi::Error->throw('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $colour and defined $self->turn and $colour eq $self->turn
defined $colour and defined $self->turn
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || {}
MC/DC0%0/1
$payload || {}
$payload
Truth table50%1/2
A
A= $payload
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $forfeited and defined $turn
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | if defined $forfeited && defined $turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 21848 | $self->turn($turn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 21848 | ▶ | $self->_finish unless defined $turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 359 | $winner = Game::Reversi::Scoring->winner($self->board); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 359 | ▶ | $result = defined $winner ? 'score' : 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 373 | ▶ | my $natural = ($result eq 'score' || $result eq 'draw') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$result eq "score" or $result eq "draw"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | ▶ | Carp::croak('Game::Reversi: timeout wants the seat that ran out') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $colour and $colour eq "b" || $colour eq "w"
$colour eq "b" or $colour eq "w"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 8 | ▶ | return Game::Reversi::Error->throw('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $colour and $colour eq "b" || $colour eq "w"
$colour eq "b" or $colour eq "w"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition60%6/10
$start and ($start->{"actor"} // "") eq "sys" and ($start->{"kind"} // "") eq "start"
$start and ($start->{"actor"} // "") eq "sys"
$start->{"actor"} // ""
$start->{"kind"} // ""
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$start->{"payload"}{"variant"} // ""
MC/DC0%0/1
$start->{"payload"}{"variant"} // ""
$start->{"payload"}{"variant"}
Truth table50%1/2
A
A= $start->{"payload"}{"variant"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 11 | ▶ | my $began = join '', map { defined $_ ? $_ : '.' } @{ $self->board }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 11 | my $logged = $start->{payload}{board}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 11 | ▶ | Carp::croak('Game::Reversi: the log began from a different position') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $logged and $logged ne $began
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
MC/DC0%0/1
$event->{"kind"} // ""
$event->{"kind"}
Truth table50%1/2
A
A= $event->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 359 | ▶ | if (($event->{actor} // '') eq 'sys') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$event->{"actor"} // ""
MC/DC0%0/1
$event->{"actor"} // ""
$event->{"actor"}
Truth table50%1/2
A
A= $event->{"actor"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 16 | ▶ | $self->timeout($event->{payload}{colour}) if $kind eq 'timeout'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 16 | ▶ | $self->abandon if $kind eq 'abandon'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 343 | ▶ | Carp::croak('Game::Reversi: the log does not replay: ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $result and $result->isa("Game::Reversi::Error")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || {}
MC/DC0%0/1
$event->{'payload'} || {}
$event->{'payload'}
Truth table50%1/2
A
A= $event->{'payload'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | return join ':', $event->{actor} // '?', $event->{kind} // '?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | join ',', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 718 | ▶ | my $v = $payload->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$event->{"actor"} // "?"
$event->{"kind"} // "?"
MC/DC0%0/1
$event->{"actor"} // "?"
$event->{"actor"}
MC/DC0%0/1
$event->{"kind"} // "?"
$event->{"kind"}
Truth table50%1/2
A
A= $event->{"actor"}
Truth table50%1/2
A
A= $event->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1358 | ▶ | $_ . '=' . (ref $v eq 'ARRAY' ? join('.', @$v) : defined $v ? $v : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'
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'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $result and $result->can("error")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | . $result->stringify) if ref $result && $result->can('error'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||