| 1 | package Game::Reversi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use Game::Reversi::Board; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use Game::Reversi::Move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use Game::Reversi::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 14 | ▶ | use Game::Reversi::Opening; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | use Game::Reversi::Rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 14 | ▶ | use Game::Reversi::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 14 | ▶ | use Game::Reversi::Scoring; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 14 | ▶ | use Game::Reversi::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 14 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | has variant => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | default => 'historic' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | has turn => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | has board => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | isa => ArrayRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | has status => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | default => 'active' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | has [qw/winner result/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | has log => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | default => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | has _held_seed => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | init_arg => 'seed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 511 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 511 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 511 | my $variant = $self->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 511 | ▶ | Carp::croak("Game::Reversi: there is no variant '$variant'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | unless Game::Reversi::Opening->describes($variant); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 510 | ▶ | my $given = defined $self->board ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 510 | ▶ | $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 | 510 | ▶ | unless @{ $self->board } == 64; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 510 | ▶ | my $first = defined $self->turn ? $self->turn : Game::Reversi::Opening->first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 510 | $self->turn(Game::Reversi::Rules->opening_turn($self->board, $first)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 510 | $self->log([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | $self->_emit('sys', 'start', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | variant => $variant, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | first => $first, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 510 | ▶ | ($given ? (board => join '', map { defined $_ ? $_ : '.' } @{ $self->board }) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 510 | ▶ | $self->_finish unless defined $self->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 510 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | ▶ | sub from_board { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_board: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | my ($class, $board, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | ▶ | 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 | 16 | return $class->new(%o, board => $board); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 415 | ▶ | sub seats { return ('b', 'w') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 397 | ▶ | 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 | 1495 | ▶ | sub phase { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
phase: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1495 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1495 | ▶ | return Game::Reversi::Rules->in_opening($self->board) ? 'opening' : 'play'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 22 | ▶ | sub seed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seed: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 22 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 22 | ▶ | return undef unless $self->status eq 'finished'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 8 | return $self->_held_seed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 702 | ▶ | 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 | 22336 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 22336 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 22336 | ▶ | return [] unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 22316 | ▶ | 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 | 22316 | ▶ | return [] unless $colour eq $self->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 22302 | return [ Game::Reversi::Rules->legal($self->board, $colour) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 229 | ▶ | sub waiting_on { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
waiting_on: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 229 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 229 | ▶ | return () unless $self->status eq 'active' && defined $self->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->status eq "active" and defined $self->turn
MC/DC50%1/2
$self->status eq "active" and defined $self->turn
$self->status eq "active"
defined $self->turn
Truth table66%2/3
A and B
A= $self->status eq "active"B= defined $self->turn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 217 | return ($self->turn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 22559 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=12 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 22559 | my ($self, $colour, $square) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 22559 | ▶ | return Game::Reversi::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 22553 | ▶ | 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 | 22550 | my $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 22550 | ▶ | if (Game::Reversi::Rules->in_opening($self->board)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 426 | my $error = Game::Reversi::Opening->check($self->board, $square); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 426 | ▶ | return $error if $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 422 | $move = Game::Reversi::Move->place($square, $colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 422 | $self->board(Game::Reversi::Opening->apply($self->board, $square, $colour)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 422 | $self->_emit($colour, 'place', { square => $square }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | return Game::Reversi::Error->throw('square_taken', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 22124 | ▶ | 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 | 22123 | my @flips = Game::Reversi::Board->flips_for($self->board, $square, $colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | return Game::Reversi::Error->throw('no_flip', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 22123 | ▶ | legal => [ map { $_->square } @{ $self->legal($colour) } ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | unless @flips; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 22121 | $move = Game::Reversi::Move->play($square, $colour, @flips); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 22121 | $self->board(Game::Reversi::Board->apply($self->board, $square, $colour)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 22121 | $self->_emit($colour, 'play', { square => $square, flips => [ @flips ] }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 22543 | $self->_advance($colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 22543 | 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 | 71 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 71 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 71 | my $copy = Object::Proto::clone($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 71 | $copy->board([ @{ $self->board } ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 71 | $copy->log([ map { { %$_, payload => { %{ $_->{payload} } } } } @{ $self->log } ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 71 | return $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 23715 | ▶ | sub _emit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 23715 | my ($self, $actor, $kind, $payload) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 23715 | ▶ | 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 | 23715 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 22543 | ▶ | sub _advance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_advance: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 22543 | my ($self, $just_moved) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 22543 | my ($turn, $forfeited) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | Game::Reversi::Rules->next_turn($self->board, $just_moved); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 22543 | ▶ | $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 | 22543 | $self->turn($turn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 22543 | ▶ | $self->_finish unless defined $turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 22543 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 393 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 393 | my ($self, $winner, $result) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 393 | my $count = $self->counts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 393 | ▶ | if (!defined $result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 363 | $winner = Game::Reversi::Scoring->winner($self->board); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 363 | ▶ | $result = defined $winner ? 'score' : 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 393 | ▶ | 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 | 393 | $self->winner($winner); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 393 | $self->status('finished'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 393 | $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 | 393 | ▶ | map { $_ => (!defined $winner ? 1 : $_ eq $winner ? 1 : 2) } $self->seats | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 393 | $self->_emit('sys', 'game_end', { winner => $winner, result => $result }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 393 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | ▶ | sub timeout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 7 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | ▶ | return Game::Reversi::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 6 | ▶ | Carp::croak('Game::Reversi: timeout wants the seat that ran out') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/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 table50%2/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 | 6 | $self->_emit('sys', 'timeout', { colour => $colour }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 6 | $self->_finish(Game::Reversi::Board->other($colour), 'timeout'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | return $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 7 | ▶ | sub abandon { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abandon: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | ▶ | return Game::Reversi::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | $self->_emit('sys', 'abandon', {}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | $self->_finish(undef, 'abandoned'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | return $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 20 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 20 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 20 | ▶ | return Game::Reversi::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 18 | ▶ | return Game::Reversi::Error->throw('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/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 table50%2/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 | 18 | $self->_emit($colour, 'resign', {}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 18 | $self->_finish(Game::Reversi::Board->other($colour), 'resign'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 18 | 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 | 260 | ▶ | sub to_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_text: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 260 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 260 | my $start = $self->log->[0]{payload}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 260 | my @line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 260 | ▶ | push @line, 'variant ' . $self->variant if $self->variant ne 'historic'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 260 | ▶ | push @line, 'first ' . $start->{first} if $start->{first} ne Game::Reversi::Opening->first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 260 | ▶ | push @line, 'board ' . $start->{board} if defined $start->{board}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 260 | ▶ | if (defined(my $seed = $self->_held_seed)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 253 | ▶ | utf8::encode($seed) if utf8::is_utf8($seed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 253 | push @line, 'seed ' . unpack 'H*', $seed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | my $transcript = Game::Reversi::Notation->render( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 6047 | [ map { $_->{payload}{square} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 260 | ▶ | 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'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 260 | ▶ | push @line, $transcript if length $transcript || @line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $transcript or @line
MC/DC0%0/2
length $transcript or @line
length $transcript
@line
Truth table66%2/3
A or B
A= length $transcriptB= @line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 260 | for my $event (@{ $self->log }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 6378 | ▶ | push @line, "resign $event->{actor}" if $event->{kind} eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 6378 | ▶ | push @line, "timeout $event->{payload}{colour}" if $event->{kind} eq 'timeout'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 6378 | ▶ | push @line, 'abandon' if $event->{kind} eq 'abandon'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 260 | return join "\n", @line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 36 | ▶ | sub from_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_text: called CC=31 SCAR=35.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 36 | my ($class, $text, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 36 | ▶ | Carp::croak('Game::Reversi: a transcript is a string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $text and not ref $text
MC/DC0%0/2
defined $text and not ref $text
defined $text
not ref $text
Truth table33%1/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | unless defined $text && !ref $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 36 | my (%setting, @ending, $squares); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 36 | for my $line (split /\n/, $text) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 84 | ▶ | next unless $line =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 84 | $line =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 84 | my ($word, $value) = $line =~ /^(variant|first|board|seed|resign|timeout|abandon)\b\s*(.*)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 84 | ▶ | if (!defined $word) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 30 | ▶ | Carp::croak('Game::Reversi: the transcript has moves after its ending') if @ending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 29 | ▶ | $squares = defined $squares ? "$squares $line" : $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 29 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 54 | ▶ | if ($word eq 'resign' || $word eq 'timeout' || $word eq 'abandon') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$word eq "resign" or $word eq "timeout" or $word eq "abandon"
$word eq "resign" or $word eq "timeout"
MC/DC100%3/3
$word eq "resign" or $word eq "timeout" or $word eq "abandon"
$word eq "resign"
$word eq "timeout"
$word eq "abandon"
Truth table100%4/4
A or B or C
A= $word eq "resign"B= $word eq "timeout"C= $word eq "abandon"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 10 | ▶ | Carp::croak("Game::Reversi: the transcript has a second ending, '$line'") if @ending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 10 | ▶ | Carp::croak("Game::Reversi: '$line' does not name a colour, b or w") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | unless $word eq 'abandon' ? $value eq '' : $value =~ /^[bw]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 9 | @ending = ($word, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 9 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | Carp::croak("Game::Reversi: the transcript says $word twice") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 44 | ▶ | if exists $setting{$word}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 44 | ▶ | Carp::croak("Game::Reversi: the transcript names its $word after its moves") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $squares or @ending
MC/DC0%0/2
defined $squares or @ending
defined $squares
@ending
Truth table33%1/3
A or B
A= defined $squaresB= @ending
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | if defined $squares || @ending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 44 | ▶ | if ($word eq 'first') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | ▶ | Carp::croak("Game::Reversi: the first colour is b or w, not '$value'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | unless $value =~ /^[bw]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | $setting{turn} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | elsif ($word eq 'board') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 3 | ▶ | Carp::croak("Game::Reversi: a board is 64 squares of b, w and ., not '$value'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | unless $value =~ /^[bw.]{64}$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 2 | ▶ | $setting{board} = [ map { $_ eq '.' ? undef : $_ } split //, $value ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | elsif ($word eq 'seed') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 29 | ▶ | Carp::croak("Game::Reversi: a seed is written in hexadecimal, not '$value'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | unless $value =~ /^(?:[0-9a-f]{2})*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 29 | $setting{seed} = pack 'H*', $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 10 | $setting{variant} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 33 | my $self = $class->new(%o, %setting); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 32 | for my $square (@{ Game::Reversi::Notation->parse($squares) }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 411 | my $result = $self->play($self->turn, $square); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 411 | ▶ | Carp::croak('Game::Reversi: the transcript does not fit this game: ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $result and $result->can("error")
MC/DC0%0/2
ref $result and $result->can("error")
ref $result
$result->can("error")
Truth table33%1/3
A and B
A= ref $resultB= $result->can("error")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | . $result->stringify) if ref $result && $result->can('error'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 31 | ▶ | if (@ending) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 8 | my ($word, $colour) = @ending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 8 | ▶ | my $result = $word eq 'abandon' ? $self->abandon : $self->$word($colour); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 8 | ▶ | Carp::croak("Game::Reversi: the transcript ends by $word, but the moves already end the game") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | if ref $result && $result->isa('Game::Reversi::Error'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 30 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||