| 1 | package Game::Go; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 25 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 25 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 25 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 25 | ▶ | use Game::Go::Rules; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 25 | ▶ | use Game::Go::Engine; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 25 | ▶ | use Game::Go::Board; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 25 | ▶ | use Game::Go::Move; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 25 | ▶ | use Game::Go::Error; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 25 | ▶ | use Game::Go::Marking; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 25 | ▶ | use Game::Go::Scoring; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 25 | ▶ | use Game::Go::Result; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | 25 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 25 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 25 | EMPTY => Game::Go::Rules::EMPTY, | |||||||||||||||||||||||||||||||||||||
| 24 | BLACK => Game::Go::Rules::BLACK, | ||||||||||||||||||||||||||||||||||||||
| 25 | WHITE => Game::Go::Rules::WHITE, | ||||||||||||||||||||||||||||||||||||||
| 26 | BORDER => Game::Go::Rules::BORDER, | ||||||||||||||||||||||||||||||||||||||
| 27 | 25 | }; | |||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | 25 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 30 | 25 | OK => Game::Go::Rules::OK, | |||||||||||||||||||||||||||||||||||||
| 31 | ILL_OFF => Game::Go::Rules::ILL_OFF, | ||||||||||||||||||||||||||||||||||||||
| 32 | ILL_TAKEN => Game::Go::Rules::ILL_TAKEN, | ||||||||||||||||||||||||||||||||||||||
| 33 | ILL_KO => Game::Go::Rules::ILL_KO, | ||||||||||||||||||||||||||||||||||||||
| 34 | ILL_SUICIDE => Game::Go::Rules::ILL_SUICIDE, | ||||||||||||||||||||||||||||||||||||||
| 35 | ILL_REPEAT => Game::Go::Rules::ILL_REPEAT, | ||||||||||||||||||||||||||||||||||||||
| 36 | ILL_COLOUR => Game::Go::Rules::ILL_COLOUR, | ||||||||||||||||||||||||||||||||||||||
| 37 | 25 | }; | |||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | 25 | ▶ | use constant MAX_DISPUTES => 3; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 25 | has size => (is => 'ro', isa => Int, default => 19); | |||||||||||||||||||||||||||||||||||||
| 42 | 25 | has komi => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||
| 43 | 25 | has handicap => (is => 'ro', isa => Int, default => 0); | |||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 25 | has ko => (is => 'ro', isa => Str, default => 'positional'); | |||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | 25 | has setup => (is => 'ro', private => 1); | |||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 25 | has first => (is => 'ro', private => 1); | |||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | 25 | has status => (is => 'rw', isa => Str, default => 'active'); | |||||||||||||||||||||||||||||||||||||
| 52 | 25 | has phase => (is => 'rw', isa => Str, default => 'play'); | |||||||||||||||||||||||||||||||||||||
| 53 | 25 | has turn => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | 25 | has [qw/winner result/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | 25 | has scored_by => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | 25 | has outcome => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||
| 61 | 25 | has marking => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 25 | has disputes => (is => 'rw', default => 0); | |||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 25 | has log => (is => 'rw', isa => ArrayRef, default => []); | |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 25 | has _engine => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||
| 68 | 25 | has _passes => (is => 'rw', private => 1, default => 0); | |||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | 25 | has _held_seed => (is => 'ro', init_arg => 'seed', private => 1); | |||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | 457 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=14 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 73 | 457 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | 457 | my $size = $self->size; | |||||||||||||||||||||||||||||||||||||
| 76 | Carp::croak("Game::Go: size must be 9, 13 or 19, not '$size'") | ||||||||||||||||||||||||||||||||||||||
| 77 | 457 | ▶ | unless grep { $_ == $size } Game::Go::Rules::sizes(); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 448 | ▶ | $self->komi( | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 80 | $self->handicap | ||||||||||||||||||||||||||||||||||||||
| 81 | ? Game::Go::Rules::HANDICAP_KOMI | ||||||||||||||||||||||||||||||||||||||
| 82 | : Game::Go::Rules::DEFAULT_KOMI | ||||||||||||||||||||||||||||||||||||||
| 83 | ) unless defined $self->komi; | ||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | 448 | my $komi = $self->komi; | |||||||||||||||||||||||||||||||||||||
| 86 | 448 | ▶ | Carp::croak("Game::Go: komi must be a multiple of 0.5, not '$komi'") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | unless $komi =~ /\A-?[0-9]+(?:\.[05])?\z/; | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | 447 | my $handicap = $self->handicap; | |||||||||||||||||||||||||||||||||||||
| 90 | 447 | my $most = Game::Go::Rules::max_handicap($size); | |||||||||||||||||||||||||||||||||||||
| 91 | 447 | ▶ | Carp::croak("Game::Go: handicap must be 0 to $most on a ${size}x$size board, not '$handicap'") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$handicap < 0 or $handicap > $most
MC/DC100%2/2
$handicap < 0 or $handicap > $most
$handicap < 0
$handicap > $most
Truth table100%3/3
A or B
A= $handicap < 0B= $handicap > $most
| |||||||||||||||||||||||||||||||||||||||
| 92 | if $handicap < 0 || $handicap > $most; | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 437 | my $ko = $self->ko; | |||||||||||||||||||||||||||||||||||||
| 95 | 437 | ▶ | Carp::croak("Game::Go: ko must be 'positional' or 'simple', not '$ko'") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ko eq "positional" or $ko eq "simple"
MC/DC0%0/2
$ko eq "positional" or $ko eq "simple"
$ko eq "positional"
$ko eq "simple"
Truth table66%2/3
A or B
A= $ko eq "positional"B= $ko eq "simple"
| |||||||||||||||||||||||||||||||||||||||
| 96 | unless $ko eq 'positional' || $ko eq 'simple'; | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 437 | $self->_engine(Game::Go::Engine->new(size => $size)); | |||||||||||||||||||||||||||||||||||||
| 99 | 437 | ▶ | $self->_engine->superko(0) if $ko eq 'simple'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | 437 | $self->turn(BLACK); | |||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | 437 | $self->_log('sys', 'start', { | |||||||||||||||||||||||||||||||||||||
| 104 | size => $size, | ||||||||||||||||||||||||||||||||||||||
| 105 | komi => $komi + 0, | ||||||||||||||||||||||||||||||||||||||
| 106 | handicap => $handicap, | ||||||||||||||||||||||||||||||||||||||
| 107 | ko => $ko, | ||||||||||||||||||||||||||||||||||||||
| 108 | first => Game::Go::Rules::letter($self->turn), | ||||||||||||||||||||||||||||||||||||||
| 109 | }); | ||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||
| 111 | 437 | ▶ | $self->_place_setup($self->setup) if $self->setup; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 112 | 437 | ▶ | $self->_place_handicap($handicap) if $handicap > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | 437 | ▶ | if (my $first = $self->first) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $who = Game::Go::Rules::from_letter($first); | |||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | Carp::croak("Game::Go: first must be 'b' or 'w', not '$first'") unless $who; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $self->turn($who); | |||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | 437 | return; | |||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub _place_setup { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_place_setup: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my ($self, $setup) = @_; | |||||||||||||||||||||||||||||||||||||
| 125 | 0 | my %placed; | |||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||
| 127 | 0 | for my $letter (sort keys %$setup) { | |||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $colour = Game::Go::Rules::from_letter($letter); | |||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | Carp::croak("Game::Go: setup names '$letter', which is not a colour") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 130 | unless $colour; | ||||||||||||||||||||||||||||||||||||||
| 131 | 0 | for my $cr (@{ $setup->{$letter} }) { | |||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $pt = $self->point(@$cr); | |||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | Carp::croak('Game::Go: a setup stone is off the board') if $pt < 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $self->_engine->put($pt, $colour); | |||||||||||||||||||||||||||||||||||||
| 135 | 0 | push @{ $placed{$letter} }, $pt; | |||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $self->_log('sys', 'setup', \%placed); | |||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->_engine->push_position; | |||||||||||||||||||||||||||||||||||||
| 141 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | 32 | ▶ | sub _place_handicap { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_place_handicap: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 145 | 32 | my ($self, $n) = @_; | |||||||||||||||||||||||||||||||||||||
| 146 | 32 | my $points = Game::Go::Rules::handicap_points($self->size, $n); | |||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | 32 | for my $cr (@$points) { | |||||||||||||||||||||||||||||||||||||
| 149 | 170 | my $pt = $self->point(@$cr); | |||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 170 | $self->_engine->put($pt, BLACK); | |||||||||||||||||||||||||||||||||||||
| 152 | 170 | $self->_log(Game::Go::Rules::letter(BLACK), 'handicap', { pt => $pt }); | |||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | 32 | $self->_engine->push_position; | |||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||
| 157 | 32 | $self->turn(WHITE); | |||||||||||||||||||||||||||||||||||||
| 158 | 32 | return; | |||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||
| 161 | 16 | ▶ | sub seats { (BLACK, WHITE) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
seats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 533 | ▶ | sub board { Game::Go::Board->new($_[0]->_engine) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
board: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | 16244 | ▶ | sub point { $_[0]->_engine->point_of($_[1], $_[2]) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||
| 167 | 357 | ▶ | sub col_row { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
col_row: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 168 | 357 | my ($self, $pt) = @_; | |||||||||||||||||||||||||||||||||||||
| 169 | 357 | my $engine = $self->_engine; | |||||||||||||||||||||||||||||||||||||
| 170 | 357 | return ($engine->col_of($pt), $engine->row_of($pt)); | |||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||
| 173 | 236 | ▶ | sub events { [ map { { %$_ } } @{ $_[0]->log } ] } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
events: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||
| 175 | 64 | ▶ | sub raw_score { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_score: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 176 | 64 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 177 | 64 | my $m = $self->marking; | |||||||||||||||||||||||||||||||||||||
| 178 | 64 | my $p = $self->prisoners; | |||||||||||||||||||||||||||||||||||||
| 179 | return $self->_engine->score( | ||||||||||||||||||||||||||||||||||||||
| 180 | dead => ($m ? $m->dead_points : []), | ||||||||||||||||||||||||||||||||||||||
| 181 | seki => ($m ? $m->seki_points : []), | ||||||||||||||||||||||||||||||||||||||
| 182 | prisoners_b => $p->{ +BLACK }, | ||||||||||||||||||||||||||||||||||||||
| 183 | 64 | ▶ | prisoners_w => $p->{ +WHITE }, | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 184 | komi_tenths => int($self->komi * 10 + ($self->komi < 0 ? -0.5 : 0.5)), | ||||||||||||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||
| 188 | 2 | ▶ | sub raw_area { $_[0]->_engine->area_score } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_area: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | sub territory_map { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
territory_map: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 191 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 192 | 1 | my $m = $self->marking; | |||||||||||||||||||||||||||||||||||||
| 193 | 1 | ▶ | return $self->_engine->territory_map( | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 194 | dead => ($m ? $m->dead_points : []), | ||||||||||||||||||||||||||||||||||||||
| 195 | seki => ($m ? $m->seki_points : []), | ||||||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | 7 | ▶ | sub _handicap_points { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_handicap_points: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 200 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 201 | 35 | return [ map { $self->point(@$_) } | |||||||||||||||||||||||||||||||||||||
| 202 | 7 | @{ Game::Go::Rules::handicap_points($self->size, $self->handicap) } ]; | |||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||
| 205 | 175 | ▶ | sub star_points { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
star_points: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 206 | 175 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 207 | 175 | return [ map { $self->point(@$_) } @{ Game::Go::Rules::star_points($self->size) } ]; | |||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | sub ko_point { $_[0]->_engine->ko_point } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
ko_point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub ko_colour { $_[0]->_engine->ko_colour } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
ko_colour: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | 799 | ▶ | sub search_from { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
search_from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 214 | 799 | my ($self, %o) = @_; | |||||||||||||||||||||||||||||||||||||
| 215 | 799 | return $self->_engine->search(%o); | |||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||
| 218 | 22 | ▶ | sub dead_guess_from { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
dead_guess_from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 219 | 22 | my ($self, %o) = @_; | |||||||||||||||||||||||||||||||||||||
| 220 | 22 | return $self->_engine->dead_guess(%o); | |||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||
| 223 | 27 | ▶ | sub is_alive { $_[0]->_engine->is_alive($_[1]) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_alive: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||
| 225 | 25 | ▶ | sub chain_id { $_[0]->_chain_id($_[1]) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
chain_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||
| 227 | 31 | ▶ | sub marked_seki { $_[0]->marking ? $_[0]->marking->seki_points : [] } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
marked_seki: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub marked_dead { $_[0]->marking ? $_[0]->marking->dead_points : [] } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
marked_dead: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | 248 | ▶ | sub prisoners { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
prisoners: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 231 | 248 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 232 | 248 | my %taken = (BLACK, 0, WHITE, 0); | |||||||||||||||||||||||||||||||||||||
| 233 | 248 | for my $e (@{ $self->log }) { | |||||||||||||||||||||||||||||||||||||
| 234 | 9274 | ▶ | next unless $e->{kind} eq 'play'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 235 | 5183 | ▶ | my $by = Game::Go::Rules::from_letter($e->{actor}) or next; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 236 | 5183 | ▶ | $taken{$by} += scalar @{ $e->{payload}{caps} || [] }; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$e->{'payload'}{'caps'} || []
MC/DC0%0/1
$e->{'payload'}{'caps'} || []
$e->{'payload'}{'caps'}
Truth table50%1/2
A
A= $e->{'payload'}{'caps'}
| |||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||
| 238 | 248 | return \%taken; | |||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||
| 241 | 932 | ▶ | sub waiting_on { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
waiting_on: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 242 | 932 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 243 | 932 | ▶ | return () unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 244 | 929 | ▶ | return ($self->marking->turn) if $self->phase eq 'marking'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 245 | 906 | return ($self->turn); | |||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||
| 248 | 2 | ▶ | sub seed { $_[0]->status eq 'finished' ? $_[0]->_held_seed : undef } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
seed: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||
| 251 | 4537 | ▶ | sub _log { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 252 | 4537 | my ($self, $actor, $kind, $payload) = @_; | |||||||||||||||||||||||||||||||||||||
| 253 | 4537 | ▶ | push @{ $self->log }, { | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$payload || {}
MC/DC100%1/1
$payload || {}
$payload
Truth table100%2/2
A
A= $payload
| |||||||||||||||||||||||||||||||||||||||
| 254 | actor => $actor, | ||||||||||||||||||||||||||||||||||||||
| 255 | kind => $kind, | ||||||||||||||||||||||||||||||||||||||
| 256 | payload => $payload || {}, | ||||||||||||||||||||||||||||||||||||||
| 257 | }; | ||||||||||||||||||||||||||||||||||||||
| 258 | 4537 | return; | |||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | 3709 | ▶ | sub _guard { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_guard: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||
| 262 | 3709 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 263 | 3709 | ▶ | return Game::Go::Error->throw('bad_colour') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 264 | unless Game::Go::Rules::is_colour($colour); | ||||||||||||||||||||||||||||||||||||||
| 265 | 3709 | ▶ | return Game::Go::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 266 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||
| 267 | 3708 | ▶ | return Game::Go::Error->throw('still_marking') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 268 | unless $self->phase eq 'play'; | ||||||||||||||||||||||||||||||||||||||
| 269 | 3702 | ▶ | return Game::Go::Error->throw('not_your_turn') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 270 | unless $colour == $self->turn; | ||||||||||||||||||||||||||||||||||||||
| 271 | 3700 | return undef; | |||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | 898 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 275 | 898 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 276 | 898 | ▶ | return [] unless Game::Go::Rules::is_colour($colour); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 277 | 897 | ▶ | return [] unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||
| 279 | 895 | ▶ | return $self->_legal_marking($colour) if $self->phase eq 'marking'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | 886 | ▶ | return [] unless $colour == $self->turn; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||
| 283 | 885 | my $engine = $self->_engine; | |||||||||||||||||||||||||||||||||||||
| 284 | my @moves = map { | ||||||||||||||||||||||||||||||||||||||
| 285 | 31640 | Game::Go::Move->new(kind => 'play', colour => $colour, point => $_) | |||||||||||||||||||||||||||||||||||||
| 286 | 885 | } @{ $engine->legal_moves($colour) }; | |||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||
| 288 | 885 | push @moves, Game::Go::Move->new(kind => 'pass', colour => $colour); | |||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||
| 290 | 885 | return \@moves; | |||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | 3400 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 294 | 3400 | my ($self, $colour, $pt) = @_; | |||||||||||||||||||||||||||||||||||||
| 295 | 3400 | my $stop = $self->_guard($colour); | |||||||||||||||||||||||||||||||||||||
| 296 | 3400 | ▶ | return $stop if $stop; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||
| 298 | 3394 | my $r = $self->_engine->play($pt, $colour); | |||||||||||||||||||||||||||||||||||||
| 299 | 3394 | ▶ | return Game::Go::Error->from_code($r->{code}) unless $r->{ok}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||
| 301 | 3375 | $self->_passes(0); | |||||||||||||||||||||||||||||||||||||
| 302 | $self->_log(Game::Go::Rules::letter($colour), 'play', { | ||||||||||||||||||||||||||||||||||||||
| 303 | pt => $pt, | ||||||||||||||||||||||||||||||||||||||
| 304 | caps => $r->{caps}, | ||||||||||||||||||||||||||||||||||||||
| 305 | 3375 | }); | |||||||||||||||||||||||||||||||||||||
| 306 | 3375 | $self->turn(Game::Go::Rules::other($colour)); | |||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||
| 308 | return Game::Go::Move->new( | ||||||||||||||||||||||||||||||||||||||
| 309 | kind => 'play', | ||||||||||||||||||||||||||||||||||||||
| 310 | colour => $colour, | ||||||||||||||||||||||||||||||||||||||
| 311 | point => $pt, | ||||||||||||||||||||||||||||||||||||||
| 312 | caps => $r->{caps}, | ||||||||||||||||||||||||||||||||||||||
| 313 | 3375 | ); | |||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||
| 316 | 309 | ▶ | sub pass { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
pass: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 317 | 309 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 318 | 309 | my $stop = $self->_guard($colour); | |||||||||||||||||||||||||||||||||||||
| 319 | 309 | ▶ | return $stop if $stop; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||
| 321 | 306 | $self->_engine->pass($colour); | |||||||||||||||||||||||||||||||||||||
| 322 | 306 | $self->_log(Game::Go::Rules::letter($colour), 'pass'); | |||||||||||||||||||||||||||||||||||||
| 323 | 306 | $self->_passes($self->_passes + 1); | |||||||||||||||||||||||||||||||||||||
| 324 | 306 | $self->turn(Game::Go::Rules::other($colour)); | |||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||
| 326 | 306 | ▶ | $self->_stop if $self->_passes >= 2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | 306 | return Game::Go::Move->new(kind => 'pass', colour => $colour); | |||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||
| 331 | 56 | ▶ | sub _stop { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_stop: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 332 | 56 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 333 | 56 | $self->_log('sys', 'stop'); | |||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | 56 | ▶ | if ($self->disputes >= MAX_DISPUTES) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 336 | 2 | $self->_log('sys', 'area'); | |||||||||||||||||||||||||||||||||||||
| 337 | 2 | return $self->_score('area'); | |||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | 54 | $self->phase('marking'); | |||||||||||||||||||||||||||||||||||||
| 341 | 54 | $self->marking(Game::Go::Marking->new( | |||||||||||||||||||||||||||||||||||||
| 342 | proposer => $self->turn, | ||||||||||||||||||||||||||||||||||||||
| 343 | answerer => Game::Go::Rules::other($self->turn), | ||||||||||||||||||||||||||||||||||||||
| 344 | )); | ||||||||||||||||||||||||||||||||||||||
| 345 | 54 | return; | |||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | 9 | ▶ | sub _legal_marking { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_legal_marking: called CC=13 SCAR=26.1
| |||||||||||||||||||||||||||||||||||||||
| 350 | 9 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 351 | 9 | my $m = $self->marking; | |||||||||||||||||||||||||||||||||||||
| 352 | 9 | ▶ | return [] unless $m && $colour == $m->turn; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$m and $colour == $m->turn
MC/DC50%1/2
$m and $colour == $m->turn
$m
$colour == $m->turn
Truth table66%2/3
A and B
A= $mB= $colour == $m->turn
| |||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||
| 354 | 7 | my @moves; | |||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||
| 356 | 7 | ▶ | if (!$m->proposed) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 357 | 2 | my $engine = $self->_engine; | |||||||||||||||||||||||||||||||||||||
| 358 | 2 | my $alive = $self->_alive_set; | |||||||||||||||||||||||||||||||||||||
| 359 | 2 | my %chain; | |||||||||||||||||||||||||||||||||||||
| 360 | 2 | for my $row (0 .. $self->size - 1) { | |||||||||||||||||||||||||||||||||||||
| 361 | 18 | for my $col (0 .. $self->size - 1) { | |||||||||||||||||||||||||||||||||||||
| 362 | 162 | my $pt = $engine->point_of($col, $row); | |||||||||||||||||||||||||||||||||||||
| 363 | 162 | my $at = $engine->at($pt); | |||||||||||||||||||||||||||||||||||||
| 364 | 162 | ▶ | if ($at == EMPTY) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 365 | 147 | ▶ | push @moves, Game::Go::Move->new( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 366 | kind => ($m->is_seki($pt) ? 'unseki' : 'seki'), | ||||||||||||||||||||||||||||||||||||||
| 367 | colour => $colour, | ||||||||||||||||||||||||||||||||||||||
| 368 | point => $pt, | ||||||||||||||||||||||||||||||||||||||
| 369 | ); | ||||||||||||||||||||||||||||||||||||||
| 370 | 147 | next; | |||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||
| 372 | 15 | ▶ | next if $alive->{$pt}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 373 | 2 | my $id = $self->_chain_id($pt); | |||||||||||||||||||||||||||||||||||||
| 374 | 2 | ▶ | next if !defined $id || $chain{$id}++; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $id or $chain{$id}++
MC/DC0%0/2
not defined $id or $chain{$id}++
not defined $id
$chain{$id}++
Truth table33%1/3
not(A) or B
A= not defined $idB= $chain{$id}++
| |||||||||||||||||||||||||||||||||||||||
| 375 | 2 | ▶ | push @moves, Game::Go::Move->new( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 376 | kind => ($m->is_dead($id) ? 'unmark' : 'mark'), | ||||||||||||||||||||||||||||||||||||||
| 377 | colour => $colour, | ||||||||||||||||||||||||||||||||||||||
| 378 | point => $id, | ||||||||||||||||||||||||||||||||||||||
| 379 | ); | ||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||
| 382 | 2 | push @moves, Game::Go::Move->new(kind => 'done', colour => $colour); | |||||||||||||||||||||||||||||||||||||
| 383 | 2 | return \@moves; | |||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||
| 386 | 5 | push @moves, Game::Go::Move->new(kind => 'accept', colour => $colour); | |||||||||||||||||||||||||||||||||||||
| 387 | 5 | ▶ | push @moves, Game::Go::Move->new(kind => 'dispute', colour => $colour) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 388 | if $self->disputes < MAX_DISPUTES; | ||||||||||||||||||||||||||||||||||||||
| 389 | 5 | return \@moves; | |||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||
| 392 | 41 | ▶ | sub _chain_id { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_chain_id: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 393 | 41 | my ($self, $pt) = @_; | |||||||||||||||||||||||||||||||||||||
| 394 | 41 | my $stones = $self->_engine->chain_at($pt); | |||||||||||||||||||||||||||||||||||||
| 395 | 41 | ▶ | return undef unless @$stones; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 396 | 40 | my ($low) = sort { $a <=> $b } @$stones; | |||||||||||||||||||||||||||||||||||||
| 397 | 40 | return $low; | |||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||
| 400 | 110 | ▶ | sub _marking_guard { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_marking_guard: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||
| 401 | 110 | my ($self, $colour, $role) = @_; | |||||||||||||||||||||||||||||||||||||
| 402 | 110 | ▶ | return Game::Go::Error->throw('bad_colour') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 403 | unless Game::Go::Rules::is_colour($colour); | ||||||||||||||||||||||||||||||||||||||
| 404 | 110 | ▶ | return Game::Go::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 405 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||
| 406 | 110 | ▶ | return Game::Go::Error->throw('not_marking') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 407 | unless $self->phase eq 'marking'; | ||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||
| 409 | 110 | my $m = $self->marking; | |||||||||||||||||||||||||||||||||||||
| 410 | 110 | ▶ | my $whose = $role eq 'proposer' ? $m->proposer : $m->answerer; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 411 | 110 | ▶ | return Game::Go::Error->throw('not_your_turn') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$colour == $whose and $colour == $m->turn
MC/DC100%2/2
$colour == $whose and $colour == $m->turn
$colour == $whose
$colour == $m->turn
Truth table100%3/3
A and B
A= $colour == $whoseB= $colour == $m->turn
| |||||||||||||||||||||||||||||||||||||||
| 412 | unless $colour == $whose && $colour == $m->turn; | ||||||||||||||||||||||||||||||||||||||
| 413 | 104 | return undef; | |||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||
| 416 | 15 | ▶ | sub _alive_set { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_alive_set: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||
| 417 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 418 | 15 | my $engine = $self->_engine; | |||||||||||||||||||||||||||||||||||||
| 419 | 15 | my %alive; | |||||||||||||||||||||||||||||||||||||
| 420 | 15 | for my $colour ($self->seats) { | |||||||||||||||||||||||||||||||||||||
| 421 | 30 | $alive{$_} = 1 for @{ $engine->alive($colour) }; | |||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||
| 423 | 15 | return \%alive; | |||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||
| 426 | 16 | ▶ | sub mark { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
mark: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 427 | 16 | my ($self, $colour, $pt) = @_; | |||||||||||||||||||||||||||||||||||||
| 428 | 16 | my $stop = $self->_marking_guard($colour, 'proposer'); | |||||||||||||||||||||||||||||||||||||
| 429 | 16 | ▶ | return $stop if $stop; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||
| 431 | 14 | my $id = $self->_chain_id($pt); | |||||||||||||||||||||||||||||||||||||
| 432 | 14 | ▶ | return Game::Go::Error->throw('not_a_chain') unless defined $id; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||
| 434 | return Game::Go::Error->throw('alive_chain') | ||||||||||||||||||||||||||||||||||||||
| 435 | 13 | ▶ | if $self->_alive_set->{$pt}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||
| 437 | 12 | my $on = $self->marking->toggle_dead($id); | |||||||||||||||||||||||||||||||||||||
| 438 | 12 | ▶ | $self->_log(Game::Go::Rules::letter($colour), ($on ? 'mark' : 'unmark'), { chain => $id }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 439 | 12 | ▶ | return Game::Go::Move->new( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 440 | kind => ($on ? 'mark' : 'unmark'), | ||||||||||||||||||||||||||||||||||||||
| 441 | colour => $colour, | ||||||||||||||||||||||||||||||||||||||
| 442 | point => $id, | ||||||||||||||||||||||||||||||||||||||
| 443 | ); | ||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||
| 446 | 13 | ▶ | sub mark_seki { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
mark_seki: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 447 | 13 | my ($self, $colour, $pt) = @_; | |||||||||||||||||||||||||||||||||||||
| 448 | 13 | my $stop = $self->_marking_guard($colour, 'proposer'); | |||||||||||||||||||||||||||||||||||||
| 449 | 13 | ▶ | return $stop if $stop; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||
| 451 | 13 | ▶ | return Game::Go::Error->throw('off_board') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 452 | unless $self->_engine->at($pt) == EMPTY; | ||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||
| 454 | 12 | my $on = $self->marking->toggle_seki($pt); | |||||||||||||||||||||||||||||||||||||
| 455 | 12 | ▶ | $self->_log(Game::Go::Rules::letter($colour), ($on ? 'seki' : 'unseki'), { region => $pt }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 456 | 12 | ▶ | return Game::Go::Move->new( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 457 | kind => ($on ? 'seki' : 'unseki'), | ||||||||||||||||||||||||||||||||||||||
| 458 | colour => $colour, | ||||||||||||||||||||||||||||||||||||||
| 459 | point => $pt, | ||||||||||||||||||||||||||||||||||||||
| 460 | ); | ||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||
| 463 | 40 | ▶ | sub done { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
done: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 464 | 40 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 465 | 40 | my $stop = $self->_marking_guard($colour, 'proposer'); | |||||||||||||||||||||||||||||||||||||
| 466 | 40 | ▶ | return $stop if $stop; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||
| 468 | 39 | $self->marking->proposed(1); | |||||||||||||||||||||||||||||||||||||
| 469 | 39 | $self->_log(Game::Go::Rules::letter($colour), 'done'); | |||||||||||||||||||||||||||||||||||||
| 470 | 39 | return Game::Go::Move->new(kind => 'done', colour => $colour); | |||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||
| 473 | 28 | ▶ | sub accept { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
accept: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 474 | 28 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 475 | 28 | my $stop = $self->_marking_guard($colour, 'answerer'); | |||||||||||||||||||||||||||||||||||||
| 476 | 28 | ▶ | return $stop if $stop; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||
| 478 | 26 | $self->_log(Game::Go::Rules::letter($colour), 'accept'); | |||||||||||||||||||||||||||||||||||||
| 479 | 26 | return $self->_score('territory'); | |||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||
| 482 | 13 | ▶ | sub dispute { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
dispute: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 483 | 13 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 484 | 13 | my $stop = $self->_marking_guard($colour, 'answerer'); | |||||||||||||||||||||||||||||||||||||
| 485 | 13 | ▶ | return $stop if $stop; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||
| 487 | 12 | my $proposer = $self->marking->proposer; | |||||||||||||||||||||||||||||||||||||
| 488 | 12 | $self->disputes($self->disputes + 1); | |||||||||||||||||||||||||||||||||||||
| 489 | 12 | $self->_log(Game::Go::Rules::letter($colour), 'dispute'); | |||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||
| 491 | 12 | $self->phase('play'); | |||||||||||||||||||||||||||||||||||||
| 492 | 12 | $self->marking(undef); | |||||||||||||||||||||||||||||||||||||
| 493 | 12 | $self->_passes(0); | |||||||||||||||||||||||||||||||||||||
| 494 | 12 | $self->turn($proposer); | |||||||||||||||||||||||||||||||||||||
| 495 | 12 | $self->_log('sys', 'resumed', { first => Game::Go::Rules::letter($proposer) }); | |||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||
| 497 | 12 | return Game::Go::Move->new(kind => 'dispute', colour => $colour); | |||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||
| 500 | 28 | ▶ | sub _score { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_score: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 501 | 28 | my ($self, $how) = @_; | |||||||||||||||||||||||||||||||||||||
| 502 | 28 | $self->scored_by($how); | |||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||
| 504 | 28 | ▶ | my $scored = $how eq 'area' | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 505 | ? Game::Go::Scoring::score_by_area($self) | ||||||||||||||||||||||||||||||||||||||
| 506 | : Game::Go::Scoring::score($self, scored_by => 'territory'); | ||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||
| 508 | 28 | $self->phase('play'); | |||||||||||||||||||||||||||||||||||||
| 509 | 28 | $self->marking(undef); | |||||||||||||||||||||||||||||||||||||
| 510 | 28 | $self->outcome($scored); | |||||||||||||||||||||||||||||||||||||
| 511 | 28 | return $self->_finish($scored->winner, 'score'); | |||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||
| 515 | 17 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 516 | 17 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 517 | 17 | ▶ | return Game::Go::Error->throw('bad_colour') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 518 | unless Game::Go::Rules::is_colour($colour); | ||||||||||||||||||||||||||||||||||||||
| 519 | 17 | ▶ | return Game::Go::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 520 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||
| 522 | 16 | $self->_log(Game::Go::Rules::letter($colour), 'resign'); | |||||||||||||||||||||||||||||||||||||
| 523 | 16 | return $self->_finish(Game::Go::Rules::other($colour), 'resign'); | |||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||
| 526 | 5 | ▶ | sub timeout { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 527 | 5 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||
| 528 | 5 | ▶ | return Game::Go::Error->throw('bad_colour') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 529 | unless Game::Go::Rules::is_colour($colour); | ||||||||||||||||||||||||||||||||||||||
| 530 | 5 | ▶ | return Game::Go::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 531 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||
| 533 | 5 | $self->_log('sys', 'timeout', { p => Game::Go::Rules::letter($colour) }); | |||||||||||||||||||||||||||||||||||||
| 534 | 5 | return $self->_finish(Game::Go::Rules::other($colour), 'timeout'); | |||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||
| 537 | 4 | ▶ | sub abandon { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
abandon: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 538 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 539 | 4 | ▶ | return Game::Go::Error->throw('game_over') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 540 | unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||
| 542 | 4 | $self->_log('sys', 'abandon'); | |||||||||||||||||||||||||||||||||||||
| 543 | 4 | return $self->_finish(undef, 'abandoned'); | |||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||
| 546 | 53 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 547 | 53 | my ($self, $winner, $result) = @_; | |||||||||||||||||||||||||||||||||||||
| 548 | 53 | $self->status('finished'); | |||||||||||||||||||||||||||||||||||||
| 549 | 53 | $self->winner($winner); | |||||||||||||||||||||||||||||||||||||
| 550 | 53 | $self->result($result); | |||||||||||||||||||||||||||||||||||||
| 551 | 53 | $self->turn(undef); | |||||||||||||||||||||||||||||||||||||
| 552 | 53 | ▶ | $self->_log('sys', 'game_end', { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 553 | winner => (defined $winner ? Game::Go::Rules::letter($winner) : undef), | ||||||||||||||||||||||||||||||||||||||
| 554 | result => $result, | ||||||||||||||||||||||||||||||||||||||
| 555 | scored_by => $self->scored_by, | ||||||||||||||||||||||||||||||||||||||
| 556 | }); | ||||||||||||||||||||||||||||||||||||||
| 557 | 53 | return $result; | |||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||
| 561 | 25 | our %SITE_OWNED; | |||||||||||||||||||||||||||||||||||||
| 562 | 25 | ▶ | BEGIN { %SITE_OWNED = map { $_ => 1 } qw(timeout abandon) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||
| 564 | 199 | ▶ | sub replay { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
replay: called CC=30 SCAR=34.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 565 | 199 | my ($self, $events) = @_; | |||||||||||||||||||||||||||||||||||||
| 566 | 199 | ▶ | Carp::croak('Game::Go: replay wants an arrayref of events') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 567 | unless ref $events eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||
| 569 | 198 | my $seen = 0; | |||||||||||||||||||||||||||||||||||||
| 570 | 198 | my $seen_handicap = 0; | |||||||||||||||||||||||||||||||||||||
| 571 | 198 | for my $e (@$events) { | |||||||||||||||||||||||||||||||||||||
| 572 | 1541 | my $actor = $e->{actor}; | |||||||||||||||||||||||||||||||||||||
| 573 | 1541 | my $kind = $e->{kind}; | |||||||||||||||||||||||||||||||||||||
| 574 | 1541 | ▶ | my $load = $e->{payload} || {}; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$e->{'payload'} || {}
MC/DC0%0/1
$e->{'payload'} || {}
$e->{'payload'}
Truth table50%1/2
A
A= $e->{'payload'}
| |||||||||||||||||||||||||||||||||||||||
| 575 | 1541 | $seen++; | |||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||
| 577 | 1541 | ▶ | if ($actor eq 'sys') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 578 | 209 | ▶ | if ($kind eq 'timeout') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 579 | 1 | ▶ | my $who = Game::Go::Rules::from_letter($load->{p} || ''); | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$load->{'p'} || ''
MC/DC0%0/1
$load->{'p'} || ''
$load->{'p'}
Truth table50%1/2
A
A= $load->{'p'}
| |||||||||||||||||||||||||||||||||||||||
| 580 | 1 | ▶ | Carp::croak("Game::Go: replay: timeout names no colour") unless $who; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 581 | 1 | $self->timeout($who); | |||||||||||||||||||||||||||||||||||||
| 582 | 1 | next; | |||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||
| 584 | 208 | ▶ | if ($kind eq 'abandon') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 585 | 1 | $self->abandon; | |||||||||||||||||||||||||||||||||||||
| 586 | 1 | next; | |||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||
| 589 | 207 | my $mine = $self->_last_sys($kind); | |||||||||||||||||||||||||||||||||||||
| 590 | 207 | ▶ | Carp::croak("Game::Go: replay: the log claims a 'sys $kind' the engine did not produce") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 591 | unless $mine; | ||||||||||||||||||||||||||||||||||||||
| 592 | 206 | $self->_agree($kind, $load, $mine->{payload}); | |||||||||||||||||||||||||||||||||||||
| 593 | 203 | next; | |||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||
| 596 | 1332 | my $colour = Game::Go::Rules::from_letter($actor); | |||||||||||||||||||||||||||||||||||||
| 597 | 1332 | ▶ | Carp::croak("Game::Go: replay: '$actor' is not a player") unless $colour; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||
| 599 | 1331 | ▶ | if ($kind eq 'handicap') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 600 | 7 | my $mine = $self->_handicap_points; | |||||||||||||||||||||||||||||||||||||
| 601 | 7 | my $want = $mine->[ $seen_handicap++ ]; | |||||||||||||||||||||||||||||||||||||
| 602 | 7 | ▶ | Carp::croak('Game::Go: replay: the log has more handicap stones than this board places') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 603 | unless defined $want; | ||||||||||||||||||||||||||||||||||||||
| 604 | Carp::croak("Game::Go: replay: handicap stone $seen_handicap is on the wrong point") | ||||||||||||||||||||||||||||||||||||||
| 605 | 7 | ▶ | unless defined $load->{pt} && $load->{pt} == $want; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $load->{"pt"} and $load->{"pt"} == $want
MC/DC50%1/2
defined $load->{"pt"} and $load->{"pt"} == $want
defined $load->{"pt"}
$load->{"pt"} == $want
Truth table66%2/3
A and B
A= defined $load->{"pt"}B= $load->{"pt"} == $want
| |||||||||||||||||||||||||||||||||||||||
| 606 | 5 | next; | |||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||
| 609 | 1324 | my $out; | |||||||||||||||||||||||||||||||||||||
| 610 | 1324 | ▶ | if ($kind eq 'play') { $out = $self->play($colour, $load->{pt}) } | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 611 | 19 | elsif ($kind eq 'pass') { $out = $self->pass($colour) } | |||||||||||||||||||||||||||||||||||||
| 612 | 1 | elsif ($kind eq 'resign') { $out = $self->resign($colour); next } | |||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||
| 614 | ▶ | elsif ($kind eq 'mark' || $kind eq 'unmark') { | |||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$kind eq "mark" or $kind eq "unmark"
MC/DC50%1/2
$kind eq "mark" or $kind eq "unmark"
$kind eq "mark"
$kind eq "unmark"
Truth table66%2/3
A or B
A= $kind eq "mark"B= $kind eq "unmark"
| |||||||||||||||||||||||||||||||||||||||
| 615 | 2 | $out = $self->mark($colour, $load->{chain}); | |||||||||||||||||||||||||||||||||||||
| 616 | 2 | ▶ | Carp::croak("Game::Go: replay: the log's '$kind' came out as a '" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $out eq "Game::Go::Move" and $out->kind ne $kind
MC/DC0%0/2
ref $out eq "Game::Go::Move" and $out->kind ne $kind
ref $out eq "Game::Go::Move"
$out->kind ne $kind
Truth table33%1/3
A and B
A= ref $out eq "Game::Go::Move"B= $out->kind ne $kind
| |||||||||||||||||||||||||||||||||||||||
| 617 | . $out->kind . "'") | ||||||||||||||||||||||||||||||||||||||
| 618 | if ref $out eq 'Game::Go::Move' && $out->kind ne $kind; | ||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||
| 620 | ▶ | elsif ($kind eq 'seki' || $kind eq 'unseki') { | |||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$kind eq "seki" or $kind eq "unseki"
MC/DC50%1/2
$kind eq "seki" or $kind eq "unseki"
$kind eq "seki"
$kind eq "unseki"
Truth table66%2/3
A or B
A= $kind eq "seki"B= $kind eq "unseki"
| |||||||||||||||||||||||||||||||||||||||
| 621 | 1 | $out = $self->mark_seki($colour, $load->{region}); | |||||||||||||||||||||||||||||||||||||
| 622 | 1 | ▶ | Carp::croak("Game::Go: replay: the log's '$kind' came out as a '" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $out eq "Game::Go::Move" and $out->kind ne $kind
MC/DC0%0/2
ref $out eq "Game::Go::Move" and $out->kind ne $kind
ref $out eq "Game::Go::Move"
$out->kind ne $kind
Truth table33%1/3
A and B
A= ref $out eq "Game::Go::Move"B= $out->kind ne $kind
| |||||||||||||||||||||||||||||||||||||||
| 623 | . $out->kind . "'") | ||||||||||||||||||||||||||||||||||||||
| 624 | if ref $out eq 'Game::Go::Move' && $out->kind ne $kind; | ||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||
| 626 | 3 | elsif ($kind eq 'done') { $out = $self->done($colour) } | |||||||||||||||||||||||||||||||||||||
| 627 | 2 | elsif ($kind eq 'accept') { $out = $self->accept($colour); next } | |||||||||||||||||||||||||||||||||||||
| 628 | 1 | elsif ($kind eq 'dispute') { $out = $self->dispute($colour) } | |||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||
| 630 | 1 | else { Carp::croak("Game::Go: replay: no such player event '$kind'") } | |||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||
| 632 | 1320 | ▶ | Carp::croak("Game::Go: replay: the log's '$kind' was refused: " . $out->message) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 633 | if ref $out eq 'Game::Go::Error'; | ||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||
| 636 | 189 | return $seen; | |||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||
| 639 | 207 | ▶ | sub _last_sys { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_last_sys: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||
| 640 | 207 | my ($self, $kind) = @_; | |||||||||||||||||||||||||||||||||||||
| 641 | 207 | for my $e (reverse @{ $self->log }) { | |||||||||||||||||||||||||||||||||||||
| 642 | 224 | ▶ | return $e if $e->{actor} eq 'sys' && $e->{kind} eq $kind; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$e->{"actor"} eq "sys" and $e->{"kind"} eq $kind
MC/DC100%2/2
$e->{"actor"} eq "sys" and $e->{"kind"} eq $kind
$e->{"actor"} eq "sys"
$e->{"kind"} eq $kind
Truth table100%3/3
A and B
A= $e->{"actor"} eq "sys"B= $e->{"kind"} eq $kind
| |||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||
| 644 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||
| 647 | 206 | ▶ | sub _agree { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_agree: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||
| 648 | 206 | my ($self, $kind, $theirs, $mine) = @_; | |||||||||||||||||||||||||||||||||||||
| 649 | 206 | for my $key (sort keys %$mine) { | |||||||||||||||||||||||||||||||||||||
| 650 | Carp::croak("Game::Go: replay: 'sys $kind' disagrees about $key") | ||||||||||||||||||||||||||||||||||||||
| 651 | 995 | ▶ | unless _same($mine->{$key}, $theirs->{$key}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||
| 653 | 203 | return; | |||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||
| 656 | 995 | ▶ | sub _same { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_same: called CC=13 SCAR=38.0
| |||||||||||||||||||||||||||||||||||||||
| 657 | 995 | my ($a, $b) = @_; | |||||||||||||||||||||||||||||||||||||
| 658 | 995 | ▶ | return 1 if !defined $a && !defined $b; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $a or defined $b
MC/DC50%1/2
defined $a or defined $b
defined $a
defined $b
Truth table66%2/3
A or B
A= defined $aB= defined $b
| |||||||||||||||||||||||||||||||||||||||
| 659 | 991 | ▶ | return 0 if !defined $a || !defined $b; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $a and defined $b
MC/DC0%0/2
defined $a and defined $b
defined $a
defined $b
Truth table33%1/3
A and B
A= defined $aB= defined $b
| |||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||
| 661 | 991 | ▶ | if (ref $a eq 'ARRAY' || ref $b eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $a eq "ARRAY" or ref $b eq "ARRAY"
MC/DC0%0/2
ref $a eq "ARRAY" or ref $b eq "ARRAY"
ref $a eq "ARRAY"
ref $b eq "ARRAY"
Truth table33%1/3
A or B
A= ref $a eq "ARRAY"B= ref $b eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 662 | 0 | ▶ | return 0 unless ref $a eq 'ARRAY' && ref $b eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $a eq "ARRAY" and ref $b eq "ARRAY"
MC/DC0%0/2
ref $a eq "ARRAY" and ref $b eq "ARRAY"
ref $a eq "ARRAY"
ref $b eq "ARRAY"
Truth table0%0/3
A and B
A= ref $a eq "ARRAY"B= ref $b eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 663 | 0 | ▶ | return 0 unless @$a == @$b; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ▶ | _same($a->[$_], $b->[$_]) or return 0 for 0 .. $#$a; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 665 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||
| 668 | 991 | ▶ | return $a eq $b ? 1 : 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||
| 671 | 179 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 672 | 179 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 673 | 179 | my $new = ref($self)->new( | |||||||||||||||||||||||||||||||||||||
| 674 | size => $self->size, | ||||||||||||||||||||||||||||||||||||||
| 675 | komi => $self->komi, | ||||||||||||||||||||||||||||||||||||||
| 676 | handicap => $self->handicap, | ||||||||||||||||||||||||||||||||||||||
| 677 | seed => $self->_held_seed, | ||||||||||||||||||||||||||||||||||||||
| 678 | ); | ||||||||||||||||||||||||||||||||||||||
| 679 | 179 | $new->replay($self->events); | |||||||||||||||||||||||||||||||||||||
| 680 | 179 | return $new; | |||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||
| 683 | 64 | ▶ | sub sizes { Game::Go::Rules::sizes() } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
sizes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | sub other { Game::Go::Rules::other($_[-1]) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
other: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | sub refusal { Game::Go::Rules::refusal($_[-1]) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
refusal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | sub refusals { Game::Go::Rules::refusals() } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
refusals: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 687 | 3 | ▶ | sub abi_version { Game::Go::Engine::_abi_version() } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
abi_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||
| 689 | 25 | 1; | |||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||
| 691 | __END__ | ||||||||||||||||||||||||||||||||||||||