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 36 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 36 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 36 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 36 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 36 ▶use Game::Fanorona::Engine ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 36 ▶use Game::Fanorona::Move ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 36 our $VERSION = '0.03';
15  
16 36 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 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 36 };
24  
25 36 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 PLAY_OK => 0,
27 PLAY_OVER => 1,
28 PLAY_ILLEGAL => 2,
29 36 };
30  
31 36 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 36 our %EXPORT_TAGS = (all => \@EXPORT_OK);
36  
37 36 my @HOW = (undef, 'stones', 'no_moves', 'repetition', 'quiet', 'ply_cap');
38  
39 36 my %LIMIT = map { $_ => 1 } qw(quiet_limit repeat ply_cap);
40  
41 36 has _ptr => (is => 'rw', private => 1);
42  
43 36 has _hold => (is => 'rw', private => 1);
44  
45 36 has _want_position => (is => 'ro', init_arg => 'position', private => 1);
46  
47 36 has _want_board => (is => 'ro', init_arg => 'board', private => 1);
48  
49 36 has _want_variant => (is => 'ro', init_arg => 'variant', private => 1);
50  
51 36 has _refused => (is => 'rw', private => 1, default => 0);
52  
53 36 has _reason => (is => 'rw', private => 1, default => 0);
54  
55 36 my %ADOPTING;
56  
57 496214 ▶sub BUILD {
Subroutine BUILD: called CC=15 SCAR=27.1
Pod undocumented
58 496214 my ($self) = @_;
59 496214 my $given = $self->_ptr;
60 496214 ▶ if ($given) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given) 31333 464881 496214
61 31333 ▶ if (delete $ADOPTING{$given}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $ADOPTING{$given}) 31332 1 31333
62 31332 $self->_hold(_hold_game($given));
63 31332 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 464881 my $position = $self->_want_position;
70 464881 my $name = $self->_want_board;
71 464881 ▶ Carp::croak("Game::Fanorona::Rules: give a position or a board, not both")
Branch: 1 branch
BranchTrueFalseTotal
if defined $position and defined $name 1 464880 464881
Condition100%3/3
defined $position and defined $name
!ll&&!rl&&r
1764647041
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 464880 ▶ if (!defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $position) 176 464704 464880
74 176 ▶ $name = 'sivy' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 154 22 176
75 176 my ($cols, $rows) = Game::Fanorona::Engine->size_of($name);
76 176 ▶ Carp::croak("Game::Fanorona::Rules: no board is called '$name'") unless $cols;
Branch: 1 branch
BranchTrueFalseTotal
unless $cols 1 175 176
77 175 $position = Game::Fanorona::Engine->new(cols => $cols, rows => $rows)->to_string;
78 }
79  
80 464879 my $variant = $self->_want_variant;
81 464879 my %limit = (quiet_limit => -1, repeat => -1, ply_cap => -1);
82 464879 ▶ if (defined $variant) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $variant) 464692 187 464879
83 464692 ▶ Carp::croak("Game::Fanorona::Rules: a variant is a hash reference")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $variant eq "HASH" 1 464691 464692
84 unless ref $variant eq 'HASH';
85 464691 for my $key (sort keys %$variant) {
86 930592 ▶ Carp::croak("Game::Fanorona::Rules: no limit is called '$key'") unless $LIMIT{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $LIMIT{$key} 1 930591 930592
87 930591 my $value = $variant->{$key};
88 930591 ▶ 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 930589 930591
Condition66%2/3
defined $value and $value =~ /\A[0-9]+\z/u
!ll&&!rl&&r
02930589
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 930589 $limit{$key} = $value;
91 }
92 }
93  
94 464875 my $ptr = _new_game($position, @limit{qw(quiet_limit repeat ply_cap)});
95 464875 ▶ Carp::croak("Game::Fanorona::Rules: the position was refused") unless $ptr;
Branch: 1 branch
BranchTrueFalseTotal
unless $ptr 1 464874 464875
96 464874 $self->_ptr($ptr);
97 464874 $self->_hold(_hold_game($ptr));
98 464874 return;
99 }
100  
101 31332 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
102 31332 my ($self) = @_;
103 31332 my $ptr = _copy_game($self->_ptr);
104 31332 $ADOPTING{$ptr} = 1;
105 31332 return ref($self)->new(_ptr => $ptr);
106 }
107  
108 419327 ▶my $step = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
109 419327 my ($raw) = @_;
110 419327 my ($from, $to, $dir, $kind, @taken) = @$raw;
111 419327 return { from => $from, to => $to, dir => $dir, kind => $kind, taken => \@taken };
112 36 };
113  
114 2315910 ▶my $triple = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
115 2315910 ▶ return @{ $_[0] }{qw(from dir kind)} if ref $_[0] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 2255908 60002 2315910
116 60002 return @_[0 .. 2];
117 36 };
118  
119 7719390 ▶my $board = sub { _game_board($_[0]->_ptr) };
Subroutine __ANON__: called CC=1 SCAR=0.0
120  
121 2700303 ▶sub position { Game::Fanorona::Engine::_to_string($board->($_[0])) }
Subroutine position: called CC=1 SCAR=0.0
Pod documented
122 7822 ▶sub side { Game::Fanorona::Engine::_side($board->($_[0])) }
Subroutine side: called CC=1 SCAR=0.0
Pod documented
123 9824 ▶sub at { Game::Fanorona::Engine::_at($board->($_[0]), $_[1]) }
Subroutine at: called CC=1 SCAR=0.0
Pod documented
124 11 ▶sub count { Game::Fanorona::Engine::_count($board->($_[0]), $_[1]) }
Subroutine count: called CC=1 SCAR=0.0
Pod documented
125 477 ▶sub key_hex { Game::Fanorona::Engine::_key_hex($board->($_[0])) }
Subroutine key_hex: called CC=1 SCAR=0.0
Pod documented
126 5000951 ▶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 ? : 43823 4957128 5000951
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 19579 ▶sub ply { _game_ply($_[0]->_ptr) }
Subroutine ply: called CC=1 SCAR=0.0
Pod documented
130 9887 ▶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 25 ▶sub repeats { _game_repeats($_[0]->_ptr) }
Subroutine repeats: called CC=1 SCAR=0.0
Pod documented
133  
134 457 ▶sub quiet_limit { (_game_variant($_[0]->_ptr))[0] }
Subroutine quiet_limit: called CC=1 SCAR=0.0
Pod documented
135 26 ▶sub repeat { (_game_variant($_[0]->_ptr))[1] }
Subroutine repeat: called CC=1 SCAR=0.0
Pod documented
136 27 ▶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 3212252 ▶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 ? : 7052 3205200 3212252
152 605 ▶sub how { $HOW[ _game_outcome($_[0]->_ptr) ] }
Subroutine how: called CC=1 SCAR=0.0
Pod documented
153 6829 ▶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 75329 ▶sub steps {
Subroutine steps: called CC=2 SCAR=6.9
Pod documented
161 75329 my ($self) = @_;
162 75329 my @raw = _game_steps($self->_ptr);
163 75329 ▶ return wantarray ? map { $step->($_) } @raw : scalar @raw;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 75325 4 75329
164 }
165  
166 11783 ▶sub can_stop { _game_can_stop($_[0]->_ptr) }
Subroutine can_stop: called CC=1 SCAR=0.0
Pod documented
167  
168 2315910 ▶sub step {
Subroutine step: called CC=2 SCAR=6.9
Pod documented
169 2315910 my $self = shift;
170 2315910 my ($answer, $why) = _game_step($self->_ptr, $triple->(@_));
171 2315910 $self->_refused($answer);
172 2315910 $self->_reason($why);
173 2315910 ▶ return $answer == PLAY_OK ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$answer == 0 ? : 2315878 32 2315910
174 }
175  
176 13475 ▶sub stop {
Subroutine stop: called CC=2 SCAR=6.9
Pod documented
177 13475 my ($self) = @_;
178 13475 my $answer = _game_stop($self->_ptr);
179 13475 $self->_refused($answer);
180 13475 $self->_reason(0);
181 13475 ▶ return $answer == PLAY_OK ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$answer == 0 ? : 13473 2 13475
182 }
183  
184 30 ▶sub refused { $_[0]->_refused }
Subroutine refused: called CC=1 SCAR=0.0
Pod documented
185 32 ▶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 461085 ▶sub moves {
Subroutine moves: called CC=3 SCAR=11.0
Pod documented
205 461085 my ($self, $limit) = @_;
206 461085 ▶ return if $self->over || $self->in_chain;
Branch: 1 branch
BranchTrueFalseTotal
if $self->over or $self->in_chain 6 461079 461085
Condition100%3/3
$self->over or $self->in_chain
l!l&&r!l&&!r
24461079
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 461079 my ($engine) = Game::Fanorona::Engine->of_string($self->position);
208 461079 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 36 my @WEIGHT = qw(stone strong centre room);
233  
234 2590 ▶sub weights {
Subroutine weights: called CC=1 SCAR=0.0
Pod documented
235 2590 my %weight;
236 2590 @weight{@WEIGHT} = _weights_default();
237 2590 return \%weight;
238 }
239  
240 2589 ▶my $weights = sub {
Subroutine __ANON__: called CC=7 SCAR=19.9
241 2589 my ($given) = @_;
242 2589 my $all = weights();
243 2589 ▶ return @{$all}{@WEIGHT} unless defined $given;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $given 2581 8 2589
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 36 };
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 2564 ▶sub search {
Subroutine search: called CC=23 SCAR=32.8
Pod documented
260 2564 my ($self, %with) = @_;
261 2564 my %known = map { $_ => 1 } qw(budget seed depth weights);
262 2564 for my $key (sort keys %with) {
263 Carp::croak("Game::Fanorona::Rules: search takes budget, seed, depth and weights, not '$key'")
264 2874 ▶ unless $known{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$key} 1 2873 2874
265 }
266 2563 ▶ my $budget = defined $with{budget} ? $with{budget} : 10_000;
Branch: 1 branch
BranchTrueFalseTotal
defined $with{'budget'} ? : 2563 0 2563
267 2563 ▶ my $seed = defined $with{seed} ? $with{seed} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $with{'seed'} ? : 292 2271 2563
268 2563 ▶ my $depth = defined $with{depth} ? $with{depth} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $with{'depth'} ? : 18 2545 2563
269 2563 ▶ 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 2562 2563
Condition50%3/6
not ref $budget and $budget =~ /\A[0-9]{1,9}\z/u and $budget >= 1
!ll&&!rl&&r
012562
not ref $budget and $budget =~ /\A[0-9]{1,9}\z/u
!ll&&!rl&&r
002563
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 2562 ▶ 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 2561 2562
Condition66%4/6
not ref $seed and $seed =~ /\A[0-9]{1,10}\z/u and $seed <= 4294967295
!ll&&!rl&&r
102561
not ref $seed and $seed =~ /\A[0-9]{1,10}\z/u
!ll&&!rl&&r
012561
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 2561 ▶ 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 2561 2561
Condition33%1/3
not ref $depth and $depth =~ /\A[0-9]{1,3}\z/u
!ll&&!rl&&r
002561
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 2561 = _game_search($self->_ptr, $budget, $seed, $depth, $weights->($with{weights}));
278 2561 ▶ return undef unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 2561 2561
279  
280 2561 my $copy = $self->clone;
281 2561 my @steps;
282 2561 ▶ while (@pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs) 2804 2561 5365
283 2804 my ($dir, $kind) = splice @pairs, 0, 2;
284 2804 ▶ my ($s) = grep { $_->{from} == $from && $_->{dir} == $dir && $_->{kind} == $kind } $copy->steps;
Condition100%6/6
$_->{'from'} == $from && $_->{'dir'} == $dir && $_->{'kind'} == $kind
!ll&&!rl&&r
10977322804
$_->{"from"} == $from and $_->{"dir"} == $dir
!ll&&!rl&&r
538755902836
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 2804 ▶ 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 2804 2804
Condition33%1/3
$s and $copy->step($s)
!ll&&!rl&&r
002804
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 2804 push @steps, $s;
287 2804 $from = $s->{to};
288 }
289 return {
290 2561 ▶ steps => \@steps,
Branch: 2 branches
BranchTrueFalseTotal
$copy->in_chain || !@steps ? : 39 2522 2561
$stopped ? : 1570 991 2561
Condition66%2/3
$copy->in_chain or not @steps
l!l&&r!l&&!r
3902522
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 36 1;
302  
303 __END__
« blib/lib/Game/Fanorona/Terminal.pm ↑ Summary blib/lib/Game/Fanorona/Variant.pm »