blib/lib/Game/Fanorona/Rules.pm

filter: Statementstmt 100% 205 / 205 Branchbran 90.9% 80 / 88 Conditioncond 66.6% 34 / 51 MC/DCmcdc 50.0% 15 / 30 Subroutinesub 100% 52 / 52 Podpod 97.3% 37 / 38 totaltotal 91.1% 423 / 464 CC 67 SCAR 22.1
CC
67
Cov
93%
search
26.6
BUILD
15.0
play_move
8.0
CRAP 9.2
« blib/lib/Game/Fanorona/Terminal.pm ↑ Summary blib/lib/Game/Fanorona/Variant.pm »
1 package Game::Fanorona::Rules;
2  
3 33 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 33 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 33 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 33 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 33 ▶use Game::Fanorona::Engine ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 33 ▶use Game::Fanorona::Move ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 33 our $VERSION = '0.02';
15  
16 33 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 33 ONGOING => 0,
18 BY_STONES => 1,
19 BY_NO_MOVES => 2,
20 DRAW_REPETITION => 3,
21 DRAW_QUIET => 4,
22 DRAW_PLY_CAP => 5,
23 33 };
24  
25 33 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 33 PLAY_OK => 0,
27 PLAY_OVER => 1,
28 PLAY_ILLEGAL => 2,
29 33 };
30  
31 33 our @EXPORT_OK = qw(
32 ONGOING BY_STONES BY_NO_MOVES DRAW_REPETITION DRAW_QUIET DRAW_PLY_CAP
33 PLAY_OK PLAY_OVER PLAY_ILLEGAL
34 );
35 33 our %EXPORT_TAGS = (all => \@EXPORT_OK);
36  
37 33 my @HOW = (undef, 'stones', 'no_moves', 'repetition', 'quiet', 'ply_cap');
38  
39 33 my %LIMIT = map { $_ => 1 } qw(quiet_limit repeat ply_cap);
40  
41 33 has _ptr => (is => 'rw', private => 1);
42  
43 33 has _hold => (is => 'rw', private => 1);
44  
45 33 has _want_position => (is => 'ro', init_arg => 'position', private => 1);
46  
47 33 has _want_board => (is => 'ro', init_arg => 'board', private => 1);
48  
49 33 has _want_variant => (is => 'ro', init_arg => 'variant', private => 1);
50  
51 33 has _refused => (is => 'rw', private => 1, default => 0);
52  
53 33 has _reason => (is => 'rw', private => 1, default => 0);
54  
55 33 my %ADOPTING;
56  
57 495904 ▶sub BUILD {
Subroutine BUILD: called CC=15 SCAR=27.1
Pod undocumented
58 495904 my ($self) = @_;
59 495904 my $given = $self->_ptr;
60 495904 ▶ if ($given) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given) 31111 464793 495904
61 31111 ▶ if (delete $ADOPTING{$given}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $ADOPTING{$given}) 31110 1 31111
62 31110 $self->_hold(_hold_game($given));
63 31110 return;
64 }
65 1 $self->_ptr(0);
66 1 Carp::croak("Game::Fanorona::Rules: a game is made by new or clone");
67 }
68  
69 464793 my $position = $self->_want_position;
70 464793 my $name = $self->_want_board;
71 464793 ▶ Carp::croak("Game::Fanorona::Rules: give a position or a board, not both")
Branch: 1 branch
BranchTrueFalseTotal
if defined $position and defined $name 1 464792 464793
Condition100%3/3
defined $position and defined $name
!ll&&!rl&&r
1744646181
MC/DC100%2/2
defined $position and defined $name
defined $position defined $name
Truth table100%3/3
A and B
A= defined $positionB= defined $name
ABresult
0X0
100
111
72 if defined $position && defined $name;
73 464792 ▶ if (!defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $position) 174 464618 464792
74 174 ▶ $name = 'sivy' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 154 20 174
75 174 my ($cols, $rows) = Game::Fanorona::Engine->size_of($name);
76 174 ▶ Carp::croak("Game::Fanorona::Rules: no board is called '$name'") unless $cols;
Branch: 1 branch
BranchTrueFalseTotal
unless $cols 1 173 174
77 173 $position = Game::Fanorona::Engine->new(cols => $cols, rows => $rows)->to_string;
78 }
79  
80 464791 my $variant = $self->_want_variant;
81 464791 my %limit = (quiet_limit => -1, repeat => -1, ply_cap => -1);
82 464791 ▶ if (defined $variant) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $variant) 464606 185 464791
83 464606 ▶ Carp::croak("Game::Fanorona::Rules: a variant is a hash reference")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $variant eq "HASH" 1 464605 464606
84 unless ref $variant eq 'HASH';
85 464605 for my $key (sort keys %$variant) {
86 930334 ▶ Carp::croak("Game::Fanorona::Rules: no limit is called '$key'") unless $LIMIT{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $LIMIT{$key} 1 930333 930334
87 930333 my $value = $variant->{$key};
88 930333 ▶ Carp::croak("Game::Fanorona::Rules: $key is a whole number, 0 or more")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /\A[0-9]+\z/u 2 930331 930333
Condition66%2/3
defined $value and $value =~ /\A[0-9]+\z/u
!ll&&!rl&&r
02930331
MC/DC50%1/2
defined $value and $value =~ /\A[0-9]+\z/u
defined $value $value =~ /\A[0-9]+\z/u
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /\A[0-9]+\z/u
ABresult
0X0
100
111
89 unless defined $value && $value =~ /\A[0-9]+\z/;
90 930331 $limit{$key} = $value;
91 }
92 }
93  
94 464787 my $ptr = _new_game($position, @limit{qw(quiet_limit repeat ply_cap)});
95 464787 ▶ Carp::croak("Game::Fanorona::Rules: the position was refused") unless $ptr;
Branch: 1 branch
BranchTrueFalseTotal
unless $ptr 1 464786 464787
96 464786 $self->_ptr($ptr);
97 464786 $self->_hold(_hold_game($ptr));
98 464786 return;
99 }
100  
101 31110 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
102 31110 my ($self) = @_;
103 31110 my $ptr = _copy_game($self->_ptr);
104 31110 $ADOPTING{$ptr} = 1;
105 31110 return ref($self)->new(_ptr => $ptr);
106 }
107  
108 415898 ▶my $step = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
109 415898 my ($raw) = @_;
110 415898 my ($from, $to, $dir, $kind, @taken) = @$raw;
111 415898 return { from => $from, to => $to, dir => $dir, kind => $kind, taken => \@taken };
112 33 };
113  
114 2315304 ▶my $triple = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
115 2315304 ▶ return @{ $_[0] }{qw(from dir kind)} if ref $_[0] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 2255736 59568 2315304
116 59568 return @_[0 .. 2];
117 33 };
118  
119 7717539 ▶my $board = sub { _game_board($_[0]->_ptr) };
Subroutine __ANON__: called CC=1 SCAR=0.0
120  
121 2699990 ▶sub position { Game::Fanorona::Engine::_to_string($board->($_[0])) }
Subroutine position: called CC=1 SCAR=0.0
Pod documented
122 7457 ▶sub side { Game::Fanorona::Engine::_side($board->($_[0])) }
Subroutine side: called CC=1 SCAR=0.0
Pod documented
123 9582 ▶sub at { Game::Fanorona::Engine::_at($board->($_[0]), $_[1]) }
Subroutine at: called CC=1 SCAR=0.0
Pod documented
124 10 ▶sub count { Game::Fanorona::Engine::_count($board->($_[0]), $_[1]) }
Subroutine count: called CC=1 SCAR=0.0
Pod documented
125 347 ▶sub key_hex { Game::Fanorona::Engine::_key_hex($board->($_[0])) }
Subroutine key_hex: called CC=1 SCAR=0.0
Pod documented
126 5000151 ▶sub in_chain { Game::Fanorona::Engine::_chain_at($board->($_[0])) >= 0 ? 1 : 0 }
Subroutine in_chain: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
Game::Fanorona::Engine::_chain_at(&$board($_[0])) >= 0 ? : 43650 4956501 5000151
127 2 ▶sub chain_at { Game::Fanorona::Engine::_chain_at($board->($_[0])) }
Subroutine chain_at: called CC=1 SCAR=0.0
Pod documented
128  
129 19239 ▶sub ply { _game_ply($_[0]->_ptr) }
Subroutine ply: called CC=1 SCAR=0.0
Pod documented
130 9785 ▶sub quiet { _game_quiet($_[0]->_ptr) }
Subroutine quiet: called CC=1 SCAR=0.0
Pod documented
131 6 ▶sub depth { _game_depth($_[0]->_ptr) }
Subroutine depth: called CC=1 SCAR=0.0
Pod documented
132 7 ▶sub repeats { _game_repeats($_[0]->_ptr) }
Subroutine repeats: called CC=1 SCAR=0.0
Pod documented
133  
134 368 ▶sub quiet_limit { (_game_variant($_[0]->_ptr))[0] }
Subroutine quiet_limit: called CC=1 SCAR=0.0
Pod documented
135 24 ▶sub repeat { (_game_variant($_[0]->_ptr))[1] }
Subroutine repeat: called CC=1 SCAR=0.0
Pod documented
136 25 ▶sub ply_cap { (_game_variant($_[0]->_ptr))[2] }
Subroutine ply_cap: called CC=1 SCAR=0.0
Pod documented
137  
138 2 ▶sub key_at {
Subroutine key_at: called CC=4 SCAR=14.6
Pod documented
139 2 my ($self, $ply) = @_;
140 2 ▶ return undef if !defined $ply || $ply !~ /\A[0-9]+\z/ || $ply > _game_ply($self->_ptr);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ply && $ply =~ /\A[0-9]+\z/u or $ply > _game_ply($self->_ptr) 1 1 2
Condition50%3/6
not defined $ply && $ply =~ /\A[0-9]+\z/u or $ply > _game_ply($self->_ptr)
l!l&&r!l&&!r
011
defined $ply && $ply =~ /\A[0-9]+\z/u
!ll&&!rl&&r
002
MC/DC33%1/3
not defined $ply && $ply =~ /\A[0-9]+\z/u or $ply > _game_ply($self->_ptr)
defined $ply $ply =~ /\A[0-9]+\z/u $ply > _game_ply($self->_ptr)
Truth table50%2/4
not(A && B) or C
A= defined $plyB= $ply =~ /\A[0-9]+\z/uC= $ply > _game_ply($self->_ptr)
ABCresult
0XX1
10X1
1111
1100
141 1 return _game_key_hex($self->_ptr, $ply);
142 }
143  
144 4 ▶sub history {
Subroutine history: called CC=1 SCAR=0.0
Pod documented
145 4 my ($self) = @_;
146 4 my $ptr = $self->_ptr;
147 4 return map { _game_key_hex($ptr, $_) } 0 .. _game_ply($ptr);
148 }
149  
150 8 ▶sub outcome { _game_outcome($_[0]->_ptr) }
Subroutine outcome: called CC=1 SCAR=0.0
Pod documented
151 3210197 ▶sub over { _game_outcome($_[0]->_ptr) != ONGOING ? 1 : 0 }
Subroutine over: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
_game_outcome($_[0]->_ptr) != 0 ? : 6951 3203246 3210197
152 524 ▶sub how { $HOW[ _game_outcome($_[0]->_ptr) ] }
Subroutine how: called CC=1 SCAR=0.0
Pod documented
153 6748 ▶sub winner { _game_winner($_[0]->_ptr) }
Subroutine winner: called CC=1 SCAR=0.0
Pod documented
154  
155 5 ▶sub is_draw {
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
156 5 my $outcome = _game_outcome($_[0]->_ptr);
157 5 ▶ return $outcome >= DRAW_REPETITION ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$outcome >= 3 ? : 3 2 5
158 }
159  
160 74566 ▶sub steps {
Subroutine steps: called CC=2 SCAR=6.9
Pod documented
161 74566 my ($self) = @_;
162 74566 my @raw = _game_steps($self->_ptr);
163 74566 ▶ return wantarray ? map { $step->($_) } @raw : scalar @raw;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 74562 4 74566
164 }
165  
166 11722 ▶sub can_stop { _game_can_stop($_[0]->_ptr) }
Subroutine can_stop: called CC=1 SCAR=0.0
Pod documented
167  
168 2315304 ▶sub step {
Subroutine step: called CC=2 SCAR=6.9
Pod documented
169 2315304 my $self = shift;
170 2315304 my ($answer, $why) = _game_step($self->_ptr, $triple->(@_));
171 2315304 $self->_refused($answer);
172 2315304 $self->_reason($why);
173 2315304 ▶ return $answer == PLAY_OK ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$answer == 0 ? : 2315273 31 2315304
174 }
175  
176 13449 ▶sub stop {
Subroutine stop: called CC=2 SCAR=6.9
Pod documented
177 13449 my ($self) = @_;
178 13449 my $answer = _game_stop($self->_ptr);
179 13449 $self->_refused($answer);
180 13449 $self->_reason(0);
181 13449 ▶ return $answer == PLAY_OK ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$answer == 0 ? : 13447 2 13449
182 }
183  
184 29 ▶sub refused { $_[0]->_refused }
Subroutine refused: called CC=1 SCAR=0.0
Pod documented
185 31 ▶sub why { $_[0]->_reason }
Subroutine why: called CC=1 SCAR=0.0
Pod documented
186  
187 2776 ▶sub undo { _game_undo($_[0]->_ptr) }
Subroutine undo: called CC=1 SCAR=0.0
Pod documented
188  
189 2225707 ▶sub undo_move {
Subroutine undo_move: called CC=6 SCAR=18.0
Pod documented
190 2225707 my ($self) = @_;
191 2225707 my $ptr = $self->_ptr;
192 2225707 ▶ return 0 unless _game_depth($ptr);
Branch: 1 branch
BranchTrueFalseTotal
unless _game_depth($ptr) 1 2225706 2225707
193 2225706 my $ply = _game_ply($ptr);
194 2225706 my $open = Game::Fanorona::Engine::_chain_at(_game_board($ptr)) >= 0;
195 2225706 ▶ my $target = $open ? $ply : $ply - 1;
Branch: 1 branch
BranchTrueFalseTotal
$open ? : 1 2225705 2225706
196 2225706 ▶ while (_game_depth($ptr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_game_depth($ptr)) 2245299 0 2245299
197 2245299 _game_undo($ptr);
198 2245299 ▶ last if _game_ply($ptr) == $target
Branch: 1 branch
BranchTrueFalseTotal
if _game_ply($ptr) == $target and Game::Fanorona::Engine::_chain_at(_game_board($ptr)) < 0 2225706 19593 2245299
Condition66%2/3
_game_ply($ptr) == $target and Game::Fanorona::Engine::_chain_at(_game_board($ptr)) < 0
!ll&&!rl&&r
0195932225706
MC/DC50%1/2
_game_ply($ptr) == $target and Game::Fanorona::Engine::_chain_at(_game_board($ptr)) < 0
_game_ply($ptr) == $target Game::Fanorona::Engine::_chain_at(_game_board($ptr)) < 0
Truth table66%2/3
A and B
A= _game_ply($ptr) == $targetB= Game::Fanorona::Engine::_chain_at(_game_board($ptr)) < 0
ABresult
0X0
100
111
199 && Game::Fanorona::Engine::_chain_at(_game_board($ptr)) < 0;
200 }
201 2225706 return 1;
202 }
203  
204 461072 ▶sub moves {
Subroutine moves: called CC=3 SCAR=11.0
Pod documented
205 461072 my ($self, $limit) = @_;
206 461072 ▶ return if $self->over || $self->in_chain;
Branch: 1 branch
BranchTrueFalseTotal
if $self->over or $self->in_chain 4 461068 461072
Condition100%3/3
$self->over or $self->in_chain
l!l&&r!l&&!r
22461068
MC/DC100%2/2
$self->over or $self->in_chain
$self->over $self->in_chain
Truth table100%3/3
A or B
A= $self->overB= $self->in_chain
ABresult
1X1
011
000
207 461068 my ($engine) = Game::Fanorona::Engine->of_string($self->position);
208 461068 return $engine->moves($limit);
209 }
210  
211 2232486 ▶sub play_move {
Subroutine play_move: called CC=8 SCAR=20.8
Pod documented
212 2232486 my ($self, $move) = @_;
213 2232486 ▶ return 0 if $self->over || $self->in_chain;
Branch: 1 branch
BranchTrueFalseTotal
if $self->over or $self->in_chain 2 2232484 2232486
Condition100%3/3
$self->over or $self->in_chain
l!l&&r!l&&!r
112232484
MC/DC100%2/2
$self->over or $self->in_chain
$self->over $self->in_chain
Truth table100%3/3
A or B
A= $self->overB= $self->in_chain
ABresult
1X1
011
000
214 2232484 my $made = 0;
215 2232484 for my $s (@{ $move->steps }) {
216 2244234 ▶ if (!$self->step($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->step($s)) 1 2244233 2244234
217 1 my ($refused, $why) = ($self->_refused, $self->_reason);
218 1 $self->undo for 1 .. $made;
219 1 $self->_refused($refused);
220 1 $self->_reason($why);
221 1 return 0;
222 }
223 2244233 $made++;
224 }
225 2232483 ▶ return 0 unless $made;
Branch: 1 branch
BranchTrueFalseTotal
unless $made 0 2232483 2232483
226 2232483 ▶ $self->stop if $self->in_chain;
Branch: 1 branch
BranchTrueFalseTotal
if $self->in_chain 10415 2222068 2232483
227 2232483 return 1;
228 }
229  
230 9 ▶sub live { _games_live() }
Subroutine live: called CC=1 SCAR=0.0
Pod documented
231  
232 33 my @WEIGHT = qw(stone strong centre room);
233  
234 2481 ▶sub weights {
Subroutine weights: called CC=1 SCAR=0.0
Pod documented
235 2481 my %weight;
236 2481 @weight{@WEIGHT} = _weights_default();
237 2481 return \%weight;
238 }
239  
240 2480 ▶my $weights = sub {
Subroutine __ANON__: called CC=7 SCAR=19.9
241 2480 my ($given) = @_;
242 2480 my $all = weights();
243 2480 ▶ return @{$all}{@WEIGHT} unless defined $given;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $given 2472 8 2480
244 8 ▶ Carp::croak('Game::Fanorona::Rules: weights are a hash reference') unless ref $given eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $given eq "HASH" 0 8 8
245 8 for my $key (sort keys %$given) {
246 22 ▶ Carp::croak("Game::Fanorona::Rules: no weight is called '$key'") unless exists $all->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $all->{$key} 1 21 22
247 Carp::croak("Game::Fanorona::Rules: the weight $key is a whole number")
248 21 ▶ unless defined $given->{$key} && $given->{$key} =~ /\A-?[0-9]{1,6}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $given->{$key} and $given->{$key} =~ /\A-?[0-9]{1,6}\z/u 0 21 21
Condition33%1/3
defined $given->{$key} and $given->{$key} =~ /\A-?[0-9]{1,6}\z/u
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $given->{$key} and $given->{$key} =~ /\A-?[0-9]{1,6}\z/u
defined $given->{$key} $given->{$key} =~ /\A-?[0-9]{1,6}\z/u
Truth table33%1/3
A and B
A= defined $given->{$key}B= $given->{$key} =~ /\A-?[0-9]{1,6}\z/u
ABresult
0X0
100
111
249 21 $all->{$key} = $given->{$key};
250 }
251 7 return @{$all}{@WEIGHT};
252 33 };
253  
254 28 ▶sub evaluate {
Subroutine evaluate: called CC=1 SCAR=0.0
Pod documented
255 28 my ($self, $given) = @_;
256 28 return _game_evaluate($self->_ptr, $weights->($given));
257 }
258  
259 2455 ▶sub search {
Subroutine search: called CC=23 SCAR=32.8
Pod documented
260 2455 my ($self, %with) = @_;
261 2455 my %known = map { $_ => 1 } qw(budget seed depth weights);
262 2455 for my $key (sort keys %with) {
263 Carp::croak("Game::Fanorona::Rules: search takes budget, seed, depth and weights, not '$key'")
264 2656 ▶ unless $known{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$key} 1 2655 2656
265 }
266 2454 ▶ my $budget = defined $with{budget} ? $with{budget} : 10_000;
Branch: 1 branch
BranchTrueFalseTotal
defined $with{'budget'} ? : 2454 0 2454
267 2454 ▶ my $seed = defined $with{seed} ? $with{seed} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $with{'seed'} ? : 183 2271 2454
268 2454 ▶ my $depth = defined $with{depth} ? $with{depth} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $with{'depth'} ? : 18 2436 2454
269 2454 ▶ Carp::croak('Game::Fanorona::Rules: a budget is a whole number of positions, from 1 up')
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $budget and $budget =~ /\A[0-9]{1,9}\z/u and $budget >= 1 1 2453 2454
Condition50%3/6
not ref $budget and $budget =~ /\A[0-9]{1,9}\z/u and $budget >= 1
!ll&&!rl&&r
012453
not ref $budget and $budget =~ /\A[0-9]{1,9}\z/u
!ll&&!rl&&r
002454
MC/DC33%1/3
not ref $budget and $budget =~ /\A[0-9]{1,9}\z/u and $budget >= 1
not ref $budget $budget =~ /\A[0-9]{1,9}\z/u $budget >= 1
Truth table50%2/4
not(A) and B and C
A= not ref $budgetB= $budget =~ /\A[0-9]{1,9}\z/uC= $budget >= 1
ABCresult
0XX0
10X0
1100
1111
270 unless !ref $budget && $budget =~ /\A[0-9]{1,9}\z/ && $budget >= 1;
271 2453 ▶ Carp::croak('Game::Fanorona::Rules: a seed is a whole number below 4,294,967,296')
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $seed and $seed =~ /\A[0-9]{1,10}\z/u and $seed <= 4294967295 1 2452 2453
Condition66%4/6
not ref $seed and $seed =~ /\A[0-9]{1,10}\z/u and $seed <= 4294967295
!ll&&!rl&&r
102452
not ref $seed and $seed =~ /\A[0-9]{1,10}\z/u
!ll&&!rl&&r
012452
MC/DC33%1/3
not ref $seed and $seed =~ /\A[0-9]{1,10}\z/u and $seed <= 4294967295
not ref $seed $seed =~ /\A[0-9]{1,10}\z/u $seed <= 4294967295
Truth table50%2/4
not(A) and B and C
A= not ref $seedB= $seed =~ /\A[0-9]{1,10}\z/uC= $seed <= 4294967295
ABCresult
0XX0
10X0
1100
1111
272 unless !ref $seed && $seed =~ /\A[0-9]{1,10}\z/ && $seed <= 4_294_967_295;
273 2452 ▶ Carp::croak('Game::Fanorona::Rules: a depth is a whole number of moves, 0 for no limit')
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $depth and $depth =~ /\A[0-9]{1,3}\z/u 0 2452 2452
Condition33%1/3
not ref $depth and $depth =~ /\A[0-9]{1,3}\z/u
!ll&&!rl&&r
002452
MC/DC0%0/2
not ref $depth and $depth =~ /\A[0-9]{1,3}\z/u
not ref $depth $depth =~ /\A[0-9]{1,3}\z/u
Truth table33%1/3
not(A) and B
A= not ref $depthB= $depth =~ /\A[0-9]{1,3}\z/u
ABresult
0X0
100
111
274 unless !ref $depth && $depth =~ /\A[0-9]{1,3}\z/;
275  
276 my ($found, $nodes, $done, $score, $stopped, $from, @pairs)
277 2452 = _game_search($self->_ptr, $budget, $seed, $depth, $weights->($with{weights}));
278 2452 ▶ return undef unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 2452 2452
279  
280 2452 my $copy = $self->clone;
281 2452 my @steps;
282 2452 ▶ while (@pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs) 2632 2452 5084
283 2632 my ($dir, $kind) = splice @pairs, 0, 2;
284 2632 ▶ my ($s) = grep { $_->{from} == $from && $_->{dir} == $dir && $_->{kind} == $kind } $copy->steps;
Condition100%6/6
$_->{'from'} == $from && $_->{'dir'} == $dir && $_->{'kind'} == $kind
!ll&&!rl&&r
10307272632
$_->{"from"} == $from and $_->{"dir"} == $dir
!ll&&!rl&&r
486754402659
MC/DC100%3/3
$_->{'from'} == $from && $_->{'dir'} == $dir && $_->{'kind'} == $kind
$_->{"from"} == $from $_->{"dir"} == $dir $_->{'kind'} == $kind
Truth table100%4/4
A and B && C
A= $_->{"from"} == $fromB= $_->{"dir"} == $dirC= $_->{'kind'} == $kind
ABCresult
0XX0
10X0
1100
1111
285 2632 ▶ Carp::croak('Game::Fanorona::Rules: the search chose a step that is not one') unless $s && $copy->step($s);
Branch: 1 branch
BranchTrueFalseTotal
unless $s and $copy->step($s) 0 2632 2632
Condition33%1/3
$s and $copy->step($s)
!ll&&!rl&&r
002632
MC/DC0%0/2
$s and $copy->step($s)
$s $copy->step($s)
Truth table33%1/3
A and B
A= $sB= $copy->step($s)
ABresult
0X0
100
111
286 2632 push @steps, $s;
287 2632 $from = $s->{to};
288 }
289 return {
290 2452 ▶ steps => \@steps,
Branch: 2 branches
BranchTrueFalseTotal
$copy->in_chain || !@steps ? : 23 2429 2452
$stopped ? : 1465 987 2452
Condition66%2/3
$copy->in_chain or not @steps
l!l&&r!l&&!r
2302429
MC/DC50%1/2
$copy->in_chain or not @steps
$copy->in_chain not @steps
Truth table66%2/3
A or not(B)
A= $copy->in_chainB= not @steps
ABresult
1X1
011
000
291 stop => ($copy->in_chain || !@steps) ? 1 : 0,
292 nodes => $nodes,
293 depth => $done,
294 score => $score,
295 stopped => $stopped ? 1 : 0,
296 };
297 }
298  
299 2 ▶sub win_score { _win_score() }
Subroutine win_score: called CC=1 SCAR=0.0
Pod documented
300  
301 33 1;
302  
303 __END__
« blib/lib/Game/Fanorona/Terminal.pm ↑ Summary blib/lib/Game/Fanorona/Variant.pm »