| 1 | package Game::Fanorona; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 25 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 25 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 25 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 25 | ▶ | use Game::Fanorona::Engine qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | WHITE BLACK PAIKA APPROACH WITHDRAWAL | ||||||||||||||||||||||||||||||||||||||||||
| 12 | WHY_OFF_BOARD WHY_BAD_STEP WHY_NO_STONE WHY_NOT_YOURS WHY_NO_LINE WHY_OCCUPIED | ||||||||||||||||||||||||||||||||||||||||||
| 13 | WHY_TAKES_NOTHING WHY_NOT_A_PAIKA WHY_MUST_CAPTURE | ||||||||||||||||||||||||||||||||||||||||||
| 14 | WHY_NOT_THE_STONE WHY_SAME_DIRECTION WHY_REVISIT WHY_PAIKA_IN_CHAIN | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 25 | ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 25 | ▶ | use Game::Fanorona::Rules qw(PLAY_OVER); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 25 | ▶ | use Game::Fanorona::Move (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 25 | ▶ | use Game::Fanorona::Variant (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 25 | ▶ | use Game::Fanorona::Error (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 25 | ▶ | use Game::Fanorona::Result (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 25 | ▶ | use Game::Fanorona::Notation qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | parse_point parse_move format_move name_of square_of | ||||||||||||||||||||||||||||||||||||||||||
| 23 | format_position format_game parse_game | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 25 | ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 25 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 25 | my @WORD = (undef, 'white', 'black'); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 25 | my %SIDE = (white => WHITE, black => BLACK); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 25 | my %HOW = (PAIKA, 'paika', APPROACH, 'approach', WITHDRAWAL, 'withdrawal'); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 25 | my %LETTER = (PAIKA, '', APPROACH, 'A', WITHDRAWAL, 'W'); | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 25 | my %FROM_WHY = ( | |||||||||||||||||||||||||||||||||||||||||
| 34 | WHY_OFF_BOARD, 'off_board', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | WHY_BAD_STEP, 'bad_move', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | WHY_NO_STONE, 'no_stone', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | WHY_NOT_YOURS, 'not_your_stone', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | WHY_NO_LINE, 'no_line', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | WHY_OCCUPIED, 'point_taken', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | WHY_TAKES_NOTHING, 'takes_nothing', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | WHY_NOT_A_PAIKA, 'bad_move', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | WHY_MUST_CAPTURE, 'must_capture', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | WHY_NOT_THE_STONE, 'not_the_stone', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | WHY_SAME_DIRECTION, 'same_direction', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | WHY_REVISIT, 'point_revisited', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | WHY_PAIKA_IN_CHAIN, 'paika_in_chain', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 25 | my %FROM_NOTATION = map { $_ => $_ } qw(off_board not_adjacent no_line paika_in_chain); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 25 | has _variant_given => (is => 'ro', init_arg => 'variant', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | has _start_given => (is => 'ro', init_arg => 'position', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 25 | has _first_given => (is => 'ro', init_arg => 'first', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 25 | has _script_given => (is => 'ro', init_arg => 'script', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 25 | has _variant => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 25 | has _rules => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 966 | ▶ | has _log => (is => 'ro', default => sub { [] }, private => 1); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 25 | has _pending => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 25 | has _ended => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 25 | has _offer => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 25 | has _error => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 966 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 966 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 966 | my $first = $self->_first_given; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 966 | ▶ | Carp::croak("Game::Fanorona: White moves first; first => '$first' is not a game of fanorona") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $first and $first ne "white"
MC/DC100%2/2
defined $first and $first ne "white"
defined $first
$first ne "white"
Truth table100%3/3
A and B
A= defined $firstB= $first ne "white"
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | if defined $first && $first ne 'white'; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 965 | my $given = $self->_variant_given; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 965 | my $variant; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 965 | ▶ | if (!defined $given) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 392 | $variant = Game::Fanorona::Variant->named; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif (ref $given eq 'Game::Fanorona::Variant') { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 218 | $variant = $given; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif (ref $given eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 331 | $variant = Game::Fanorona::Variant->custom(%$given); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif (!ref $given) { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 23 | $variant = Game::Fanorona::Variant->from_string($given); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 23 | ▶ | Carp::croak("Game::Fanorona: '$given' is not a variant") unless $variant; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | Carp::croak('Game::Fanorona: a variant is a name, a hash of fields or a Game::Fanorona::Variant'); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 959 | my $start = $self->_start_given; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 959 | ▶ | if (defined $start) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | $variant = Game::Fanorona::Variant->custom( | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 520 | cols => $variant->cols, rows => $variant->rows, %{ $variant->limits }, start => $start, | |||||||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 957 | $self->_variant($variant); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 957 | $self->_rules(Game::Fanorona::Rules->new(position => $variant->start, variant => $variant->limits)); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 957 | $self->_pending([]); | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 957 | my $script = $self->_script_given; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 957 | ▶ | if (defined $script) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 15 | ▶ | Carp::croak('Game::Fanorona: a script is a list of moves') unless ref $script eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 14 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 14 | for my $move (@$script) { | |||||||||||||||||||||||||||||||||||||||||
| 114 | 32 | $n++; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 32 | ▶ | next if $self->play($move); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | Carp::croak("Game::Fanorona: move $n of the script, '" . ($move // 'undef') . "', was refused: " | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$move // "undef"
MC/DC0%0/1
$move // "undef"
$move
Truth table50%1/2
A
A= $move
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | . $self->error->message); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 955 | return; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 64 | ▶ | my $refuse = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 64 | my ($self, $code, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 64 | ▶ | $self->_error(Game::Fanorona::Error->of($code, (defined $move ? (move => $move) : ()))); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 64 | return; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 31390 | ▶ | my $describe = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 31390 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 31390 | my ($from, $to) = (name_of($s->{from}), name_of($s->{to})); | |||||||||||||||||||||||||||||||||||||||||
| 132 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | from => $from, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | to => $to, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | how => $HOW{ $s->{kind} }, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 31390 | takes => [ map { name_of($_) } @{ $s->{taken} } ], | |||||||||||||||||||||||||||||||||||||||||
| 137 | string => "$from-$to$LETTER{ $s->{kind} }", | ||||||||||||||||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 36426 | ▶ | my $read = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 36426 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 36426 | ▶ | my $text = ref $move ? format_move($move) : $move; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 36426 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 36426 | my ($parsed, $why) = parse_move($text, cols => $variant->cols, rows => $variant->rows); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 36426 | ▶ | return ($parsed, $text) if $parsed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 17 | ▶ | $refuse->($self, $FROM_NOTATION{ $why // '' } // 'bad_move', $text); | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$FROM_NOTATION{$why // ""} // "bad_move"
$why // ""
MC/DC100%1/1
$FROM_NOTATION{$why // ""} // "bad_move"
$FROM_NOTATION{$why // ""}
MC/DC0%0/1
$why // ""
$why
Truth table100%2/2
A
A= $FROM_NOTATION{$why // ""}
Truth table50%1/2
A
A= $why
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 17 | return; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 59560 | ▶ | my $take = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 59560 | my ($self, $rules, $wanted, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 59560 | my ($from, $dir, $kind) = @{$wanted}{qw(from dir kind)}; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 59560 | ▶ | my @there = grep { $_->{from} == $from && $_->{dir} == $dir } $rules->steps; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->{'from'} == $from && $_->{'dir'} == $dir
MC/DC100%2/2
$_->{'from'} == $from && $_->{'dir'} == $dir
$_->{'from'} == $from
$_->{'dir'} == $dir
Truth table100%3/3
A && B
A= $_->{'from'} == $fromB= $_->{'dir'} == $dir
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 59560 | ▶ | if ($kind == PAIKA) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 15448 | my @takes = grep { $_->{kind} != PAIKA } @there; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 15448 | ▶ | return $refuse->($self, 'choose_capture', $text) if @takes > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 15444 | ▶ | $kind = $takes[0]{kind} if @takes == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 59556 | my ($step) = grep { $_->{kind} == $kind } @there; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 59556 | ▶ | return $step if $step && $rules->step($from, $dir, $kind); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$step and $rules->step($from, $dir, $kind)
MC/DC50%1/2
$step and $rules->step($from, $dir, $kind)
$step
$rules->step($from, $dir, $kind)
Truth table66%2/3
A and B
A= $stepB= $rules->step($from, $dir, $kind)
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 23 | ▶ | $rules->step($from, $dir, $kind) unless $step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 23 | ▶ | my $code = $rules->refused == PLAY_OVER ? 'game_over' : ($FROM_WHY{ $rules->why } // 'bad_move'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$FROM_WHY{$rules->why} // "bad_move"
MC/DC0%0/1
$FROM_WHY{$rules->why} // "bad_move"
$FROM_WHY{$rules->why}
Truth table50%1/2
A
A= $FROM_WHY{$rules->why}
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 23 | return $refuse->($self, $code, $text); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 10674 | ▶ | my $run = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 10674 | my ($self, $rules, $parsed, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 10674 | my @made; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 10674 | for my $wanted (@{ $parsed->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||
| 171 | 13679 | my $step = $take->($self, $rules, $wanted, $text); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 13679 | ▶ | if (!$step) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 15 | $rules->undo for @made; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 13664 | push @made, $step; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 10659 | ▶ | $rules->stop if $rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 10659 | return @made; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 9491 | ▶ | my $finish = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 9491 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 9491 | my $steps = $self->_pending; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 9491 | ▶ | my $mover = $WORD[ $steps->[0] ? $self->_rules->at($steps->[-1]{to}) : 0 ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 9491 | push @{ $self->_log }, format_move({ from => $steps->[0]{from}, steps => $steps }); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 9491 | $self->_pending([]); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 9491 | my $offer = $self->_offer; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 9491 | ▶ | $self->_offer(undef) if defined $offer && defined $mover && $offer eq $mover; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $offer and defined $mover and $offer eq $mover
defined $offer and defined $mover
MC/DC66%2/3
defined $offer and defined $mover and $offer eq $mover
defined $offer
defined $mover
$offer eq $mover
Truth table75%3/4
A and B and C
A= defined $offerB= defined $moverC= $offer eq $mover
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 9491 | return; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 1514 | ▶ | sub variant { $_[0]->_variant } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
variant: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 48983 | ▶ | sub over { ($_[0]->_ended || $_[0]->_rules->over) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
over: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
$_[0]->_ended or $_[0]->_rules->over
MC/DC100%2/2
$_[0]->_ended or $_[0]->_rules->over
$_[0]->_ended
$_[0]->_rules->over
Truth table100%3/3
A or B
A= $_[0]->_endedB= $_[0]->_rules->over
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 1309 | ▶ | sub turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turn: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 1309 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 1309 | ▶ | return undef if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 1307 | return $WORD[ $self->_rules->side ]; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 647 | ▶ | sub result { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 647 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 647 | my $ended = $self->_ended; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 647 | ▶ | return $ended if $ended; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 630 | my $rules = $self->_rules; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 630 | ▶ | return undef unless $rules->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 339 | return Game::Fanorona::Result->new( | |||||||||||||||||||||||||||||||||||||||||
| 210 | how => $rules->how, | ||||||||||||||||||||||||||||||||||||||||||
| 211 | winner => $WORD[ $rules->winner ], | ||||||||||||||||||||||||||||||||||||||||||
| 212 | position => $rules->position, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | moves => $rules->ply, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 6 | ▶ | sub winner { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
winner: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | ▶ | my $result = $self->result or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | return $result->winner; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 69 | ▶ | sub error { $_[0]->_error } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 2738 | ▶ | sub position { $_[0]->_rules->position } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | sub position_counted { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position_counted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | my $rules = $self->_rules; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | return format_position($rules->position, $rules->quiet, $rules->ply + 1); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 345 | ▶ | sub signature { $_[0]->_rules->key_hex } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 4589 | ▶ | sub ply { $_[0]->_rules->ply } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 323 | ▶ | sub quiet { $_[0]->_rules->quiet } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quiet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 345 | ▶ | sub quiet_limit { $_[0]->_rules->quiet_limit } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quiet_limit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | sub repeats { $_[0]->_rules->repeats } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repeats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 813 | ▶ | sub in_chain { $_[0]->_rules->in_chain } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_chain: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | sub chain_at { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chain_at: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | my $at = $self->_rules->chain_at; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | return $at < 0 ? undef : name_of($at); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 99 | ▶ | sub at { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
at: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 99 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 99 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 99 | my @point = parse_point($name, cols => $variant->cols, rows => $variant->rows); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 99 | ▶ | return undef unless @point; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 91 | return $WORD[ $self->_rules->at(square_of($name)) ]; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 10 | ▶ | sub stones { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stones: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 10 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 10 | ▶ | return undef unless defined $side && $SIDE{$side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $side and $SIDE{$side}
MC/DC50%1/2
defined $side and $SIDE{$side}
defined $side
$SIDE{$side}
Truth table66%2/3
A and B
A= defined $sideB= $SIDE{$side}
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 9 | return $self->_rules->count($SIDE{$side}); | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 529 | ▶ | sub moves { @{ $_[0]->_log } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
moves: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 173 | ▶ | sub in_progress { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_progress: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 173 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 173 | my $steps = $self->_pending; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 173 | ▶ | return undef unless @$steps; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | return format_move({ from => $steps->[0]{from}, steps => $steps }); | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 659 | ▶ | sub steps { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
steps: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 659 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 659 | ▶ | return if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 655 | return map { $describe->($_) } $self->_rules->steps; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 6 | ▶ | sub can_stop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_stop: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 6 | ▶ | return 0 if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | ▶ | return $self->_rules->can_stop ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 472 | ▶ | sub starts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
starts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 472 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 472 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 472 | return grep { !$seen{$_}++ } map { $_->{from} } $self->steps; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 2758 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 2758 | my ($self, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 2758 | ▶ | return if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 2756 | return $self->_rules->moves($limit); | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 2737 | ▶ | sub legal_strings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal_strings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 2737 | my ($self, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 2737 | return sort map { format_move($_) } $self->legal($limit); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 519 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 519 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 519 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 301 | 519 | ▶ | return $refuse->($self, 'game_over', $string) if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 518 | ▶ | my ($parsed, $text) = $read->($self, $string) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 518 | ▶ | return $refuse->($self, 'bad_move', $text) unless @{ $parsed->{steps} } == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 517 | ▶ | my $step = $take->($self, $self->_rules, $parsed->{steps}[0], $text) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 513 | push @{ $self->_pending }, $step; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 513 | ▶ | $finish->($self) unless $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 513 | return $describe->($step); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 21 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 21 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 21 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 20 | ▶ | return $refuse->($self, 'nothing_to_stop') unless $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 19 | $self->_rules->stop; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 19 | $finish->($self); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 19 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 9152 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 9152 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 9152 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 9152 | ▶ | my $shown = ref $move ? format_move($move) : $move; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 9152 | ▶ | return $refuse->($self, 'game_over', $shown) if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 9150 | ▶ | return $refuse->($self, 'chain_open', $shown) if $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 9149 | ▶ | my ($parsed, $text) = $read->($self, $move) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 9137 | ▶ | my @made = $run->($self, $self->_rules, $parsed, $text) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 9123 | $self->_pending(\@made); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 9123 | $finish->($self); | |||||||||||||||||||||||||||||||||||||||||
| 330 | 9123 | return Game::Fanorona::Move->new(from => $made[0]{from}, steps => [ @made ]); | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 1539 | ▶ | sub preview { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preview: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 1539 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 1539 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 336 | 1539 | ▶ | my $shown = ref $move ? format_move($move) : $move; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 1539 | ▶ | return $refuse->($self, 'game_over', $shown) if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 1538 | ▶ | return $refuse->($self, 'chain_open', $shown) if $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 1537 | ▶ | my ($parsed, $text) = $read->($self, $move) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 1537 | my $rules = $self->_rules->clone; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 1537 | ▶ | $run->($self, $rules, $parsed, $text) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 1536 | return $rules->position; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 27113 | ▶ | sub continuations { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
continuations: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 27113 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 27113 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 27113 | ▶ | return $refuse->($self, 'game_over', $prefix) if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 27112 | my $rules = $self->_rules->clone; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 27112 | my $complete = 0; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 27112 | ▶ | if (defined $prefix && length $prefix) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $prefix and length $prefix
MC/DC100%2/2
defined $prefix and length $prefix
defined $prefix
length $prefix
Truth table100%3/3
A and B
A= defined $prefixB= length $prefix
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 25222 | ▶ | my ($parsed, $text) = $read->($self, $prefix) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 25217 | for my $wanted (@{ $parsed->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||
| 354 | 45365 | ▶ | return $refuse->($self, 'bad_move', $text) if $complete; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 45364 | ▶ | $take->($self, $rules, $wanted, $text) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 45356 | ▶ | $complete = 1 unless $rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | complete => $complete, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | stop => (!$complete && $rules->can_stop) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 27098 | ▶ | steps => [ $complete ? () : map { $describe->($_) } $rules->steps ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not $complete and $rules->can_stop
MC/DC100%2/2
not $complete and $rules->can_stop
not $complete
$rules->can_stop
Truth table100%3/3
not(A) and B
A= not $completeB= $rules->can_stop
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 21 | ▶ | my $end = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 21 | my ($self, $how, $winner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 21 | my $rules = $self->_rules; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 21 | ▶ | $self->_ended(Game::Fanorona::Result->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | how => $how, | ||||||||||||||||||||||||||||||||||||||||||
| 371 | (defined $winner ? (winner => $winner) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 372 | position => $rules->position, | ||||||||||||||||||||||||||||||||||||||||||
| 373 | moves => $rules->ply, | ||||||||||||||||||||||||||||||||||||||||||
| 374 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 21 | $self->_offer(undef); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 21 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 16 | ▶ | my $other = sub { $_[0] eq 'white' ? 'black' : 'white' }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 18 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 18 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 18 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 384 | 18 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 17 | ▶ | return $refuse->($self, 'not_a_side') unless defined $side && $SIDE{$side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $side and $SIDE{$side}
MC/DC50%1/2
defined $side and $SIDE{$side}
defined $side
$SIDE{$side}
Truth table66%2/3
A and B
A= defined $sideB= $SIDE{$side}
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 16 | return $end->($self, 'resign', $other->($side)); | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 20 | ▶ | sub offer_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offer_draw: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 20 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 20 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 392 | 20 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 19 | ▶ | return $refuse->($self, 'not_a_side') unless defined $side && $SIDE{$side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $side and $SIDE{$side}
MC/DC50%1/2
defined $side and $SIDE{$side}
defined $side
$SIDE{$side}
Truth table66%2/3
A and B
A= defined $sideB= $SIDE{$side}
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 18 | ▶ | return $refuse->($self, 'offer_standing') if defined $self->_offer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 17 | $self->_offer($side); | |||||||||||||||||||||||||||||||||||||||||
| 396 | 17 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 12 | ▶ | my $answer = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 12 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 12 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 12 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 11 | ▶ | return $refuse->($self, 'not_a_side') unless defined $side && $SIDE{$side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $side and $SIDE{$side}
MC/DC0%0/2
defined $side and $SIDE{$side}
defined $side
$SIDE{$side}
Truth table33%1/3
A and B
A= defined $sideB= $SIDE{$side}
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 11 | ▶ | return $refuse->($self, 'no_offer') unless defined $self->_offer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 9 | ▶ | return $refuse->($self, 'own_offer') if $self->_offer eq $side; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 8 | ▶ | sub accept_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_draw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 8 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 8 | ▶ | $answer->($self, $side) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 5 | return $end->($self, 'agreement'); | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 4 | ▶ | sub decline_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decline_draw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 4 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 4 | ▶ | $answer->($self, $side) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 3 | $self->_offer(undef); | |||||||||||||||||||||||||||||||||||||||||
| 419 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 305 | ▶ | sub draw_offered_by { $_[0]->_offer } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
draw_offered_by: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 253 | ▶ | sub search { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 253 | my ($self, %with) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 253 | ▶ | return undef if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 250 | ▶ | my $found = $self->_rules->search(%with) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 250 | my $steps = delete $found->{steps}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 250 | $found->{steps} = [ map { $describe->($_) } @$steps ]; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 250 | ▶ | $found->{move} = @$steps ? format_move({ from => $steps->[0]{from}, steps => $steps }) : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 250 | return $found; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 18 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 18 | my ($self, $weights) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 18 | return $self->_rules->evaluate($weights); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 136 | ▶ | sub replay { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 136 | my ($class, $moves, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 136 | ▶ | Carp::croak('Game::Fanorona: replay takes a list of moves') unless ref $moves eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 135 | my $game = $class->new(%arg); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 135 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 135 | for my $move (@$moves) { | |||||||||||||||||||||||||||||||||||||||||
| 445 | 5088 | $n++; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 5088 | ▶ | return ($game, $game->error, $n) unless $game->play($move); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 133 | return ($game, undef, undef); | |||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 63 | ▶ | sub as_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_text: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 63 | my ($self, %extra) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 63 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 63 | my $default = Game::Fanorona::Variant->named('telo')->limits; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 63 | my %game = (variant => $variant->name, moves => [ $self->moves ]); | |||||||||||||||||||||||||||||||||||||||||
| 456 | 63 | ▶ | $game{start} = $variant->start unless $variant->is_setup; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 63 | for my $limit (qw(quiet_limit repeat ply_cap)) { | |||||||||||||||||||||||||||||||||||||||||
| 458 | 189 | ▶ | $game{$limit} = $variant->$limit unless $variant->$limit == $default->{$limit}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 63 | for my $name (qw(white black)) { | |||||||||||||||||||||||||||||||||||||||||
| 461 | 126 | ▶ | $game{$name} = $extra{$name} if defined $extra{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 63 | my $result = $self->result; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 63 | ▶ | $game{result} = $result->how . (defined $result->winner ? ' ' . $result->winner : '') if $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 63 | return format_game(\%game); | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 68 | ▶ | sub from_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_text: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 68 | my ($class, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 68 | my ($parsed, $why, $line) = parse_game($text); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 68 | ▶ | return (undef, $why, $line) unless $parsed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 64 | my $variant = eval { | |||||||||||||||||||||||||||||||||||||||||
| 473 | Game::Fanorona::Variant->custom( | ||||||||||||||||||||||||||||||||||||||||||
| 474 | cols => $parsed->{cols}, rows => $parsed->{rows}, | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 64 | map { $_ => $parsed->{$_} } grep { defined $parsed->{$_} } qw(quiet_limit repeat ply_cap start), | |||||||||||||||||||||||||||||||||||||||||
| 476 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 477 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 64 | ▶ | return (undef, 'bad_variant', 2) unless $variant; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 64 | my ($game, $error, $n) = $class->replay($parsed->{moves}, variant => $variant); | |||||||||||||||||||||||||||||||||||||||||
| 480 | 64 | ▶ | return (undef, $error->code, $parsed->{moves_at} + $n - 1) if $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 63 | return ($game, undef, undef); | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 25 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | __END__ | ||||||||||||||||||||||||||||||||||||||||||