| 1 | package Game::Fanorona; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 28 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 28 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 28 | ▶ | 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 | 28 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 28 | ▶ | use Game::Fanorona::Rules qw(PLAY_OVER); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 28 | ▶ | use Game::Fanorona::Move (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 28 | ▶ | use Game::Fanorona::Variant (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 28 | ▶ | use Game::Fanorona::Error (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 28 | ▶ | use Game::Fanorona::Result (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 28 | ▶ | 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 | 28 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 28 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 28 | my @WORD = (undef, 'white', 'black'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 28 | my %SIDE = (white => WHITE, black => BLACK); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 28 | my %HOW = (PAIKA, 'paika', APPROACH, 'approach', WITHDRAWAL, 'withdrawal'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 28 | my %LETTER = (PAIKA, '', APPROACH, 'A', WITHDRAWAL, 'W'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 28 | 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 | 28 | my %FROM_NOTATION = map { $_ => $_ } qw(off_board not_adjacent no_line paika_in_chain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 28 | has _variant_given => (is => 'ro', init_arg => 'variant', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 28 | has _start_given => (is => 'ro', init_arg => 'position', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 28 | has _first_given => (is => 'ro', init_arg => 'first', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 28 | has _script_given => (is => 'ro', init_arg => 'script', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 28 | has _variant => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 28 | has _rules => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1052 | ▶ | has _log => (is => 'ro', default => sub { [] }, private => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 28 | has _pending => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 28 | has _ended => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 28 | has _offer => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 28 | has _error => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1052 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1052 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1052 | my $first = $self->_first_given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1052 | ▶ | 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 | 1051 | my $given = $self->_variant_given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1051 | my $variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1051 | ▶ | if (!defined $given) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 415 | $variant = Game::Fanorona::Variant->named; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif (ref $given eq 'Game::Fanorona::Variant') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 279 | $variant = $given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif (ref $given eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 332 | $variant = Game::Fanorona::Variant->custom(%$given); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif (!ref $given) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 24 | $variant = Game::Fanorona::Variant->from_string($given); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 24 | ▶ | 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 | 1045 | my $start = $self->_start_given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1045 | ▶ | if (defined $start) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | $variant = Game::Fanorona::Variant->custom( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 534 | cols => $variant->cols, rows => $variant->rows, %{ $variant->limits }, start => $start, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1043 | $self->_variant($variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1043 | $self->_rules(Game::Fanorona::Rules->new(position => $variant->start, variant => $variant->limits)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1043 | $self->_pending([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1043 | my $script = $self->_script_given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1043 | ▶ | 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 | 1041 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 65 | ▶ | my $refuse = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 65 | my ($self, $code, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 65 | ▶ | $self->_error(Game::Fanorona::Error->of($code, (defined $move ? (move => $move) : ()))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 65 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 32346 | ▶ | my $describe = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 32346 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 32346 | 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 | 32346 | takes => [ map { name_of($_) } @{ $s->{taken} } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | string => "$from-$to$LETTER{ $s->{kind} }", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 36806 | ▶ | my $read = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 36806 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 36806 | ▶ | my $text = ref $move ? format_move($move) : $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 36806 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 36806 | my ($parsed, $why) = parse_move($text, cols => $variant->cols, rows => $variant->rows); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 36806 | ▶ | 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 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 59994 | ▶ | my $take = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 59994 | my ($self, $rules, $wanted, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 59994 | my ($from, $dir, $kind) = @{$wanted}{qw(from dir kind)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 59994 | ▶ | 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 | 59994 | ▶ | if ($kind == PAIKA) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 15503 | my @takes = grep { $_->{kind} != PAIKA } @there; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 15503 | ▶ | return $refuse->($self, 'choose_capture', $text) if @takes > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 15499 | ▶ | $kind = $takes[0]{kind} if @takes == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 59990 | my ($step) = grep { $_->{kind} == $kind } @there; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 59990 | ▶ | 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 | 24 | ▶ | $rules->step($from, $dir, $kind) unless $step; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 24 | ▶ | 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 | 24 | return $refuse->($self, $code, $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 10808 | ▶ | my $run = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 10808 | my ($self, $rules, $parsed, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 10808 | my @made; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 10808 | for my $wanted (@{ $parsed->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 13858 | my $step = $take->($self, $rules, $wanted, $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 13858 | ▶ | if (!$step) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 15 | $rules->undo for @made; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 13843 | push @made, $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 10793 | ▶ | $rules->stop if $rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 10793 | return @made; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 9733 | ▶ | my $finish = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9733 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9733 | my $steps = $self->_pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 9733 | ▶ | my $mover = $WORD[ $steps->[0] ? $self->_rules->at($steps->[-1]{to}) : 0 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 9733 | push @{ $self->_log }, format_move({ from => $steps->[0]{from}, steps => $steps }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 9733 | $self->_pending([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 9733 | my $offer = $self->_offer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 9733 | ▶ | $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 | 9733 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1914 | ▶ | sub variant { $_[0]->_variant } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
variant: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 50452 | ▶ | 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 | 1682 | ▶ | sub turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turn: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1682 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1682 | ▶ | return undef if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1672 | return $WORD[ $self->_rules->side ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1268 | ▶ | sub result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1268 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1268 | my $ended = $self->_ended; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1268 | ▶ | return $ended if $ended; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1229 | my $rules = $self->_rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1229 | ▶ | return undef unless $rules->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 420 | 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 | 8 | ▶ | sub winner { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
winner: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | ▶ | my $result = $self->result or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 7 | return $result->winner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 70 | ▶ | sub error { $_[0]->_error } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2916 | ▶ | sub position { $_[0]->_rules->position } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 20 | ▶ | sub position_counted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position_counted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 20 | my $rules = $self->_rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 20 | return format_position($rules->position, $rules->quiet, $rules->ply + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 475 | ▶ | sub signature { $_[0]->_rules->key_hex } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 4820 | ▶ | sub ply { $_[0]->_rules->ply } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 407 | ▶ | sub quiet { $_[0]->_rules->quiet } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quiet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 432 | ▶ | sub quiet_limit { $_[0]->_rules->quiet_limit } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quiet_limit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 19 | ▶ | sub repeats { $_[0]->_rules->repeats } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repeats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 956 | ▶ | 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 | 11 | ▶ | sub stones { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stones: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 11 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 11 | ▶ | 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 | 10 | return $self->_rules->count($SIDE{$side}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1064 | ▶ | sub moves { @{ $_[0]->_log } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
moves: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 836 | ▶ | sub in_progress { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_progress: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 836 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 836 | my $steps = $self->_pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 836 | ▶ | return undef unless @$steps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 24 | return format_move({ from => $steps->[0]{from}, steps => $steps }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 763 | ▶ | sub steps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
steps: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 763 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 763 | ▶ | return if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 751 | 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 | 537 | ▶ | sub starts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
starts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 537 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 537 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 537 | return grep { !$seen{$_}++ } map { $_->{from} } $self->steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2771 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2771 | my ($self, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 2771 | ▶ | return if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 2769 | return $self->_rules->moves($limit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 2750 | ▶ | sub legal_strings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal_strings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 2750 | my ($self, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 2750 | return sort map { format_move($_) } $self->legal($limit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 719 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 719 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 719 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 719 | ▶ | return $refuse->($self, 'game_over', $string) if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 718 | ▶ | my ($parsed, $text) = $read->($self, $string) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 718 | ▶ | return $refuse->($self, 'bad_move', $text) unless @{ $parsed->{steps} } == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 717 | ▶ | my $step = $take->($self, $self->_rules, $parsed->{steps}[0], $text) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 713 | push @{ $self->_pending }, $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 713 | ▶ | $finish->($self) unless $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 713 | return $describe->($step); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 34 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 34 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 34 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 34 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 33 | ▶ | return $refuse->($self, 'nothing_to_stop') unless $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 32 | $self->_rules->stop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 32 | $finish->($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 32 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 9271 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 9271 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 9271 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 9271 | ▶ | my $shown = ref $move ? format_move($move) : $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 9271 | ▶ | return $refuse->($self, 'game_over', $shown) if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 9269 | ▶ | return $refuse->($self, 'chain_open', $shown) if $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 9268 | ▶ | my ($parsed, $text) = $read->($self, $move) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 9256 | ▶ | my @made = $run->($self, $self->_rules, $parsed, $text) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 9242 | $self->_pending(\@made); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 9242 | $finish->($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 9242 | return Game::Fanorona::Move->new(from => $made[0]{from}, steps => [ @made ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1554 | ▶ | sub preview { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preview: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1554 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1554 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1554 | ▶ | my $shown = ref $move ? format_move($move) : $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1554 | ▶ | return $refuse->($self, 'game_over', $shown) if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1553 | ▶ | return $refuse->($self, 'chain_open', $shown) if $self->_rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1552 | ▶ | my ($parsed, $text) = $read->($self, $move) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1552 | my $rules = $self->_rules->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1552 | ▶ | $run->($self, $rules, $parsed, $text) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1551 | return $rules->position; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 27211 | ▶ | sub continuations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
continuations: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 27211 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 27211 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 27211 | ▶ | return $refuse->($self, 'game_over', $prefix) if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 27210 | my $rules = $self->_rules->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 27210 | my $complete = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 27210 | ▶ | 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 | 25268 | ▶ | my ($parsed, $text) = $read->($self, $prefix) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 25263 | for my $wanted (@{ $parsed->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 45417 | ▶ | return $refuse->($self, 'bad_move', $text) if $complete; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 45416 | ▶ | $take->($self, $rules, $wanted, $text) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 45407 | ▶ | $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 | 27195 | ▶ | 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 | 31 | ▶ | my $end = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 31 | my ($self, $how, $winner) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 31 | my $rules = $self->_rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 31 | ▶ | $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 | 31 | $self->_offer(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 31 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 18 | ▶ | my $other = sub { $_[0] eq 'white' ? 'black' : 'white' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 20 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 20 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 20 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 20 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 18 | return $end->($self, 'resign', $other->($side)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 27 | ▶ | sub offer_draw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offer_draw: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 27 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 27 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 27 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 26 | ▶ | 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 | 25 | ▶ | return $refuse->($self, 'offer_standing') if defined $self->_offer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 24 | $self->_offer($side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 14 | ▶ | my $answer = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 14 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 14 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 14 | ▶ | return $refuse->($self, 'game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 13 | ▶ | 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 | 13 | ▶ | return $refuse->($self, 'no_offer') unless defined $self->_offer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 11 | ▶ | return $refuse->($self, 'own_offer') if $self->_offer eq $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 10 | ▶ | sub accept_draw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_draw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 10 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 10 | ▶ | $answer->($self, $side) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 7 | 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 | 404 | ▶ | sub draw_offered_by { $_[0]->_offer } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
draw_offered_by: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 362 | ▶ | sub search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 362 | my ($self, %with) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 362 | ▶ | return undef if $self->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 359 | ▶ | my $found = $self->_rules->search(%with) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 359 | my $steps = delete $found->{steps}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 359 | $found->{steps} = [ map { $describe->($_) } @$steps ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 359 | ▶ | $found->{move} = @$steps ? format_move({ from => $steps->[0]{from}, steps => $steps }) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 359 | 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 | 183 | ▶ | sub replay { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 183 | my ($class, $moves, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 183 | ▶ | Carp::croak('Game::Fanorona: replay takes a list of moves') unless ref $moves eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 182 | my $game = $class->new(%arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 182 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 182 | for my $move (@$moves) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 5191 | $n++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 5191 | ▶ | return ($game, $game->error, $n) unless $game->play($move); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 180 | return ($game, undef, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 529 | ▶ | sub as_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_text: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 529 | my ($self, %extra) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 529 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 529 | my $default = Game::Fanorona::Variant->named('telo')->limits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 529 | my %game = (variant => $variant->name, moves => [ $self->moves ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 529 | ▶ | $game{start} = $variant->start unless $variant->is_setup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 529 | for my $limit (qw(quiet_limit repeat ply_cap)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1587 | ▶ | $game{$limit} = $variant->$limit unless $variant->$limit == $default->{$limit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 529 | for my $name (qw(white black)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1058 | ▶ | $game{$name} = $extra{$name} if defined $extra{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 529 | my $result = $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 529 | ▶ | $game{result} = $result->how . (defined $result->winner ? ' ' . $result->winner : '') if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 529 | ▶ | $game{offer} = $self->_offer if defined $self->_offer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 529 | ▶ | $game{chain} = $self->in_progress if defined $self->in_progress; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 529 | return format_game(\%game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 108 | ▶ | sub from_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_text: called CC=22 SCAR=31.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 108 | my ($class, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 108 | my ($parsed, $why, $line) = parse_game($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 108 | ▶ | return (undef, $why, $line) unless $parsed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 101 | my $variant = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | Game::Fanorona::Variant->custom( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | cols => $parsed->{cols}, rows => $parsed->{rows}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 101 | map { $_ => $parsed->{$_} } grep { defined $parsed->{$_} } qw(quiet_limit repeat ply_cap start), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 101 | ▶ | return (undef, 'bad_variant', 2) unless $variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 101 | my ($game, $error, $n) = $class->replay($parsed->{moves}, variant => $variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 101 | ▶ | return (undef, $error->code, $parsed->{moves_at} + $n - 1) if $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 100 | my $at = $parsed->{at}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 100 | ▶ | if (defined $parsed->{chain}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 3 | my ($chain) = parse_move($parsed->{chain}, cols => $variant->cols, rows => $variant->rows); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 3 | my $rules = $game->_rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 3 | for my $wanted (@{ $chain->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | my $step = $take->($game, $rules, $wanted, $parsed->{chain}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 3 | ▶ | or return (undef, $game->error->code, $at->{chain}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 3 | push @{ $game->_pending }, $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 3 | ▶ | return (undef, 'bad_chain', $at->{chain}) unless $rules->in_chain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 99 | ▶ | if (defined $parsed->{offer}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 3 | ▶ | $game->offer_draw($parsed->{offer}) or return (undef, $game->error->code, $at->{offer}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 99 | ▶ | if (defined $parsed->{result}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 70 | my ($how, $winner) = split / /, $parsed->{result}, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 70 | ▶ | if ($how eq 'resign' || $how eq 'agreement') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$how eq "resign" or $how eq "agreement"
MC/DC100%2/2
$how eq "resign" or $how eq "agreement"
$how eq "resign"
$how eq "agreement"
Truth table100%3/3
A or B
A= $how eq "resign"B= $how eq "agreement"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | return (undef, 'bad_result', $at->{result}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | if $game->over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 7 | ▶ | || ($how eq 'resign' ? !(defined $winner && $SIDE{$winner}) : defined $winner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$game->over or $how eq "resign" ? !(defined $winner && $SIDE{$winner}) : defined $winner
defined $winner && $SIDE{$winner}
MC/DC50%1/2
$game->over or $how eq "resign" ? !(defined $winner && $SIDE{$winner}) : defined $winner
$game->over
$how eq "resign" ? !(defined $winner && $SIDE{$winner}) : defined $winner
MC/DC50%1/2
defined $winner && $SIDE{$winner}
defined $winner
$SIDE{$winner}
Truth table66%2/3
A or B
A= $game->overB= $how eq "resign" ? !(defined $winner && $SIDE{$winner}) : defined $winner
Truth table66%2/3
A && B
A= defined $winnerB= $SIDE{$winner}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 6 | $end->($game, $how, $winner); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 63 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | return (undef, 'bad_result', $at->{result}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 63 | ▶ | unless $result && $result->how eq $how && ($result->winner // '') eq ($winner // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%8/10
$result and $result->how eq $how and ($result->winner // "") eq ($winner // "")
$result and $result->how eq $how
$result->winner // ""
$winner // ""
MC/DC66%2/3
$result and $result->how eq $how and ($result->winner // "") eq ($winner // "")
$result
$result->how eq $how
$result->winner
MC/DC100%1/1
$winner // ""
$winner
Truth table75%3/4
A and B and C
A= $resultB= $result->how eq $howC= $result->winner
Truth table100%2/2
A
A= $winner
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 97 | return ($game, undef, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 28 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||