blib/lib/Game/Senet/Engine.pm

filter: Statementstmt 100% 197 / 197 Branchbran 92.8% 52 / 56 Conditioncond 69.8% 37 / 53 MC/DCmcdc 48.3% 15 / 31 Subroutinesub 100% 65 / 65 Podpod 97.8% 45 / 46 totaltotal 91.7% 411 / 448 CC 51 SCAR 12.5
CC
51
Cov
93%
moves
8.0
search
8.0
BUILD
7.0
CRAP 3.5
« blib/lib/Game/Senet/Rules.pm ↑ Summary blib/lib/Game/Senet/Error.pm »
1 package Game::Senet::Engine;
2  
3 101 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 101 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 101 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 101 ▶use Carp ();
Subroutine __ANON__: called CC=1 SCAR=0.0
8 101 ▶use Exporter 'import';
Subroutine __ANON__: called CC=1 SCAR=0.0
9 101 ▶use Object::Proto::Sugar;
Subroutine __ANON__: called CC=1 SCAR=0.0
10 101 ▶use Scalar::Util ();
Subroutine __ANON__: called CC=1 SCAR=0.0
11  
12 101 ▶use Game::Senet::Move;
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 101 our $VERSION = '0.03';
15  
16 101 require XSLoader;
17 101 XSLoader::load('Game::Senet', $VERSION);
18  
19 101 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 101 EMPTY => 0,
21 LIGHT => 1,
22 DARK => 2,
23  
24 SIDE_LIGHT => 0,
25 SIDE_DARK => 1,
26  
27 HOUSES => 30,
28 ROWS => 3,
29 COLS => 10,
30 PIECES_MAX => 7,
31 ROLL_MAX => 5,
32 MOVES_MAX => 7,
33 WIN => 1_000_000,
34 DEPTH_MAX => 32,
35 CHAIN_MAX => 4,
36 REBIRTH => 15,
37 101 };
38  
39 101 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
40 101 PROTECT_NONE => 0,
41 PROTECT_RUN => 1,
42 PROTECT_ENDS => 2,
43  
44 REACH_EXACT => 0,
45 REACH_ANY => 1,
46  
47 X_END => 0,
48 X_OFF => 31,
49 X_WALK => 32,
50 X_STAY => 33,
51  
52 RULES_KENDALL => 0,
53 RULES_SKYRUK => 1,
54 101 };
55  
56 101 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
57 101 ONGOING => 0,
58 WON => 1,
59 DRAWN => 2,
60  
61 BY_HOME => 1,
62 BY_PLY_CAP => 2,
63 101 };
64  
65 101 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
66 101 POS_OK => 0,
67 POS_NULL => 1,
68 POS_GROUPS => 2,
69 POS_WIDTH => 3,
70 POS_LETTER => 4,
71 POS_SIDE => 5,
72 POS_PIECES => 6,
73 POS_EXCESS => 7,
74 POS_FIELD => 8,
75 POS_LONG => 9,
76 101 };
77  
78 101 our @EXPORT_OK = qw(
79 EMPTY LIGHT DARK
80 SIDE_LIGHT SIDE_DARK
81 HOUSES ROWS COLS PIECES_MAX ROLL_MAX MOVES_MAX CHAIN_MAX REBIRTH WIN DEPTH_MAX
82 PROTECT_NONE PROTECT_RUN PROTECT_ENDS
83 REACH_EXACT REACH_ANY
84 X_END X_OFF X_WALK X_STAY
85 RULES_KENDALL RULES_SKYRUK
86 POS_OK POS_NULL POS_GROUPS POS_WIDTH POS_LETTER POS_SIDE
87 POS_PIECES POS_EXCESS POS_FIELD POS_LONG
88 ONGOING WON DRAWN BY_HOME BY_PLY_CAP
89 other piece_of
90 );
91 101 our %EXPORT_TAGS = (all => \@EXPORT_OK);
92  
93 2 ▶sub other { $_[0] == SIDE_LIGHT ? SIDE_DARK : SIDE_LIGHT }
Subroutine other: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 0 ? : 1 1 2
94  
95 232653 ▶sub piece_of { $_[0] == SIDE_LIGHT ? LIGHT : DARK }
Subroutine piece_of: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 0 ? : 116460 116193 232653
96  
97 101 has _ptr => (is => 'rw', private => 1);
98  
99 101 has _hold => (is => 'rw', private => 1);
100  
101 101 has _given_pieces => (is => 'ro', init_arg => 'pieces', private => 1, default => 5);
102  
103 101 has _position => (is => 'ro', init_arg => 'position', private => 1);
104  
105 101 my %ADOPTING;
106  
107 764262 ▶sub BUILD {
Subroutine BUILD: called CC=7 SCAR=19.5
Pod undocumented
108 764262 my ($self) = @_;
109 764262 my $given = $self->_ptr;
110 764262 ▶ if ($given) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given) 588832 175430 764262
111 588832 ▶ if (delete $ADOPTING{$given}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $ADOPTING{$given}) 588831 1 588832
112 588831 $self->_hold(_hold_board($given));
113 588831 return;
114 }
115 1 $self->_ptr(0);
116 1 Carp::croak("Game::Senet::Engine: a board is made by new, of_string or clone");
117 }
118  
119 175430 my $position = $self->_position;
120 175430 ▶ if (defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position) 82479 92951 175430
121 82479 my ($ptr, $err) = _of_string($position);
122 82479 ▶ Carp::croak("Game::Senet::Engine: the position was refused, code $err")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ptr 1 82478 82479
123 unless defined $ptr;
124 82478 $self->_ptr($ptr);
125 82478 $self->_hold(_hold_board($ptr));
126 82478 return;
127 }
128  
129 92951 my $pieces = $self->_given_pieces;
130 92951 ▶ Carp::croak("Game::Senet::Engine: pieces is a whole number from 1 to 7")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pieces and $pieces =~ /\A[1-7]\z/ 6 92945 92951
Condition66%2/3
defined $pieces and $pieces =~ /\A[1-7]\z/
!ll&&!rl&&r
0692945
MC/DC50%1/2
defined $pieces and $pieces =~ /\A[1-7]\z/
defined $pieces $pieces =~ /\A[1-7]\z/
Truth table66%2/3
A and B
A= defined $piecesB= $pieces =~ /\A[1-7]\z/
ABresult
0X0
100
111
131 unless defined $pieces && $pieces =~ /\A[1-7]\z/;
132 92945 $self->_ptr(_new_board($pieces));
133 92945 $self->_hold(_hold_board($self->_ptr));
134 92945 return;
135 }
136  
137 588831 ▶my $adopt = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
138 588831 my ($class, $ptr) = @_;
139 588831 $ADOPTING{$ptr} = 1;
140 588831 return $class->new(_ptr => $ptr);
141 101 };
142  
143 1110 ▶sub of_string {
Subroutine of_string: called CC=3 SCAR=11.0
Pod documented
144 1110 my ($class, $position) = @_;
145 1110 ▶ my ($ptr, $err) = _of_string(defined $position ? $position : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $position ? : 1109 1 1110
146 1110 ▶ return (undef, $err) unless defined $ptr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ptr 87 1023 1110
147 1023 return ($adopt->($class, $ptr), POS_OK);
148 }
149  
150 587808 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
151 587808 my ($self) = @_;
152 587808 return $adopt->(ref($self), _copy_board($self->_ptr));
153 }
154  
155 709289 ▶sub at { _at($_[0]->_ptr, $_[1]) }
Subroutine at: called CC=1 SCAR=0.0
Pod documented
156 646381 ▶sub put { _put($_[0]->_ptr, $_[1], $_[2]); return $_[0] }
Subroutine put: called CC=1 SCAR=0.0
Pod documented
157 6 ▶sub lift { _lift($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine lift: called CC=1 SCAR=0.0
Pod documented
158 3408727 ▶sub side { _side($_[0]->_ptr) }
Subroutine side: called CC=1 SCAR=0.0
Pod documented
159 355944 ▶sub set_side { _set_side($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine set_side: called CC=1 SCAR=0.0
Pod documented
160 661 ▶sub pieces { _pieces($_[0]->_ptr) }
Subroutine pieces: called CC=1 SCAR=0.0
Pod documented
161 403522 ▶sub count { _count($_[0]->_ptr, $_[1]) }
Subroutine count: called CC=1 SCAR=0.0
Pod documented
162 15703 ▶sub home { _home($_[0]->_ptr, $_[1]) }
Subroutine home: called CC=1 SCAR=0.0
Pod documented
163 3 ▶sub consistent { _consistent($_[0]->_ptr) }
Subroutine consistent: called CC=1 SCAR=0.0
Pod documented
164 879665 ▶sub ply { _ply($_[0]->_ptr) }
Subroutine ply: called CC=1 SCAR=0.0
Pod documented
165 2007 ▶sub set_ply { _set_ply($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine set_ply: called CC=1 SCAR=0.0
Pod documented
166 116450 ▶sub to_string { _to_string($_[0]->_ptr) }
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
167 119370 ▶sub key_hex { _key_hex($_[0]->_ptr) }
Subroutine key_hex: called CC=1 SCAR=0.0
Pod documented
168  
169 36 ▶sub house_of { my $c = shift; _house_of($_[0], $_[1]) }
Subroutine house_of: called CC=1 SCAR=0.0
Pod documented
170 35 ▶sub row_of { my $c = shift; _row_of($_[0]) }
Subroutine row_of: called CC=1 SCAR=0.0
Pod documented
171 39 ▶sub col_of { my $c = shift; _col_of($_[0]) }
Subroutine col_of: called CC=1 SCAR=0.0
Pod documented
172 34 ▶sub is_marked { my $c = shift; _is_marked($_[0]) }
Subroutine is_marked: called CC=1 SCAR=0.0
Pod documented
173  
174 2 ▶sub all_houses { 1 .. HOUSES }
Subroutine all_houses: called CC=1 SCAR=0.0
Pod documented
175 1 ▶sub marked_houses { grep { _is_marked($_) } 1 .. HOUSES }
Subroutine marked_houses: called CC=1 SCAR=0.0
Pod documented
176  
177 101 my (@PROTECT_NAME, @REACH_NAME, %EXIT_WORD);
178 101 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
179 101 @PROTECT_NAME = ('none', 'run', 'ends');
180 101 @REACH_NAME = ('exact', 'any');
181 101 %EXIT_WORD = (31 => 'off', 32 => 'walk', 33 => 'stay');
182 }
183  
184 86047 ▶my $as_hash = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
185 86047 my ($pieces, $blockade, $protect, $backward, $reach26, $throw_on_26, $safe, @chain) = @_;
186 86047 my %exits;
187 86047 for my $h (0 .. 4) {
188 430235 for my $roll (1 .. ROLL_MAX) {
189 2151175 my @entries = splice @chain, 0, CHAIN_MAX;
190 $exits{ 26 + $h }{$roll} = [
191 2151175 ▶ map { $EXIT_WORD{$_} // $_ } grep { $_ != X_END } @entries
Condition66%2/3
$EXIT_WORD{$_} // $_
l!l&&r!l&&!r
9384594275490
MC/DC0%0/2
$EXIT_WORD{$_} // $_
$EXIT_WORD{$_} $_
Truth table66%2/3
A // B
A= $EXIT_WORD{$_}B= $_
ABresult
1X1
011
000
192 ];
193 }
194 }
195 return {
196 pieces => $pieces,
197 blockade => $blockade,
198 protect => $PROTECT_NAME[$protect],
199 backward => $backward,
200 reach26 => $REACH_NAME[$reach26],
201 throw_on_26 => $throw_on_26,
202 86047 safe => [ grep { $safe & (1 << $_) } 1 .. HOUSES ],
203 exits => \%exits,
204 };
205 101 };
206  
207 86056 ▶sub rules {
Subroutine rules: called CC=1 SCAR=0.0
Pod documented
208 86056 my ($class, $rules) = @_;
209 86056 return $as_hash->(_rules($rules));
210 }
211  
212 4 ▶sub rules_named {
Subroutine rules_named: called CC=2 SCAR=6.9
Pod documented
213 4 my ($class, $name) = @_;
214 4 my @flat = _rules_named($name);
215 4 ▶ return undef unless @flat;
Branch: 1 branch
BranchTrueFalseTotal
unless @flat 2 2 4
216 2 return $as_hash->(@flat);
217 }
218  
219 4 ▶sub rules_id { my $c = shift; _rules_id($_[0]) }
Subroutine rules_id: called CC=1 SCAR=0.0
Pod documented
220  
221 11892 ▶sub chances {
Subroutine chances: called CC=1 SCAR=0.0
Pod documented
222 11892 return map { [ _chance($_) ] } 0 .. _chance_count() - 1;
223 }
224  
225 8 ▶sub extra { my $c = shift; _extra($_[0]) }
Subroutine extra: called CC=1 SCAR=0.0
Pod documented
226  
227 101 my @SIDE_NAME;
228 101 ▶BEGIN { @SIDE_NAME = ('light', 'dark') }
Subroutine BEGIN: called CC=1 SCAR=0.0
229  
230 1227841 ▶sub moves {
Subroutine moves: called CC=8 SCAR=20.8
Pod documented
231 1227841 my ($self, $roll, $rules, $only) = @_;
232 1227841 ▶ Carp::croak('Game::Senet::Engine: a roll is a whole number of houses from 1 to 5')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll and $roll =~ /\A[1-5]\z/ 6 1227835 1227841
Condition66%2/3
defined $roll and $roll =~ /\A[1-5]\z/
!ll&&!rl&&r
061227835
MC/DC50%1/2
defined $roll and $roll =~ /\A[1-5]\z/
defined $roll $roll =~ /\A[1-5]\z/
Truth table66%2/3
A and B
A= defined $rollB= $roll =~ /\A[1-5]\z/
ABresult
0X0
100
111
233 unless defined $roll && $roll =~ /\A[1-5]\z/;
234 1227835 ▶ $only //= 0;
Condition100%2/2
$only //= 0
l!l
884047343788
MC/DC100%1/1
$only //= 0
$only
Truth table100%2/2
A
A= $only
Aresult
11
00
235 1227835 ▶ Carp::croak('Game::Senet::Engine: only is a house, 1 to 30, or 0 for any')
Branch: 1 branch
BranchTrueFalseTotal
unless $only =~ /\A\d{1,2}\z/ and $only <= 30 1 1227834 1227835
Condition66%2/3
$only =~ /\A\d{1,2}\z/ and $only <= 30
!ll&&!rl&&r
011227834
MC/DC50%1/2
$only =~ /\A\d{1,2}\z/ and $only <= 30
$only =~ /\A\d{1,2}\z/ $only <= 30
Truth table66%2/3
A and B
A= $only =~ /\A\d{1,2}\z/B= $only <= 30
ABresult
0X0
100
111
236 unless $only =~ /\A\d{1,2}\z/ && $only <= HOUSES;
237 1227834 my $side = $SIDE_NAME[ _side($self->_ptr) ];
238 my @moves = map {
239 1227834 my ($from, $to, $r, $swap, $back, $off, $walk) = @$_;
240 2461804 ▶ Game::Senet::Move->new(
Branch: 1 branch
BranchTrueFalseTotal
$off ? : 195144 2266660 2461804
241 side => $side,
242 roll => $r,
243 from => $from,
244 to => ($off ? 'off' : $to),
245 swap => $swap,
246 back => $back,
247 off => $off,
248 walk => $walk,
249 );
250 } _moves($self->_ptr, $roll, $rules, $only);
251 1227834 ▶ return wantarray ? @moves : scalar @moves;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1227827 7 1227834
252 }
253  
254 943291 ▶sub apply {
Subroutine apply: called CC=5 SCAR=16.7
Pod documented
255 943291 my ($self, $move, $rules) = @_;
256 943291 ▶ Carp::croak('Game::Senet::Engine: apply takes a move')
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($move) and $move->isa("Game::Senet::Move") 0 943291 943291
Condition33%1/3
builtin::blessed($move) and $move->isa("Game::Senet::Move")
!ll&&!rl&&r
00943291
MC/DC0%0/2
builtin::blessed($move) and $move->isa("Game::Senet::Move")
builtin::blessed($move) $move->isa("Game::Senet::Move")
Truth table33%1/3
A and B
A= builtin::blessed($move)B= $move->isa("Game::Senet::Move")
ABresult
0X0
100
111
257 unless Scalar::Util::blessed($move) && $move->isa('Game::Senet::Move');
258 943291 ▶ my ($undo, $bound) = _apply($self->_ptr, $rules, $move->from,
Branch: 1 branch
BranchTrueFalseTotal
$move->off ? : 149826 793465 943291
259 ($move->off ? -1 : $move->to), $move->roll, $move->off);
260 943291 ▶ return wantarray ? ($undo, $bound) : $undo;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 823280 120011 943291
261 }
262  
263 235686 ▶sub forfeit {
Subroutine forfeit: called CC=3 SCAR=11.0
Pod documented
264 235686 my ($self, $roll) = @_;
265 235686 ▶ Carp::croak('Game::Senet::Engine: a roll is a whole number of houses from 1 to 5')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll and $roll =~ /\A[1-5]\z/ 1 235685 235686
Condition66%2/3
defined $roll and $roll =~ /\A[1-5]\z/
!ll&&!rl&&r
01235685
MC/DC50%1/2
defined $roll and $roll =~ /\A[1-5]\z/
defined $roll $roll =~ /\A[1-5]\z/
Truth table66%2/3
A and B
A= defined $rollB= $roll =~ /\A[1-5]\z/
ABresult
0X0
100
111
266 unless defined $roll && $roll =~ /\A[1-5]\z/;
267 235685 return _forfeit($self->_ptr, $roll);
268 }
269  
270 71519 ▶sub unapply { _unapply($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine unapply: called CC=1 SCAR=0.0
Pod documented
271  
272 7384470 ▶sub status { _status($_[0]->_ptr) }
Subroutine status: called CC=1 SCAR=0.0
Pod documented
273 1413 ▶sub how { _how($_[0]->_ptr) }
Subroutine how: called CC=1 SCAR=0.0
Pod documented
274 62704 ▶sub winner { _winner($_[0]->_ptr) }
Subroutine winner: called CC=1 SCAR=0.0
Pod documented
275 3 ▶sub ply_cap { _ply_cap() }
Subroutine ply_cap: called CC=1 SCAR=0.0
Pod documented
276  
277 40 ▶sub walk { _walk($_[0]->_ptr, $_[1], $_[2]) }
Subroutine walk: called CC=1 SCAR=0.0
Pod documented
278  
279 84136 ▶my $check_roll = sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
280 84136 ▶ Carp::croak('Game::Senet::Engine: a roll is a whole number of houses from 1 to 5')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and $_[0] =~ /\A[1-5]\z/ 0 84136 84136
Condition33%1/3
defined $_[0] and $_[0] =~ /\A[1-5]\z/
!ll&&!rl&&r
0084136
MC/DC0%0/2
defined $_[0] and $_[0] =~ /\A[1-5]\z/
defined $_[0] $_[0] =~ /\A[1-5]\z/
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] =~ /\A[1-5]\z/
ABresult
0X0
100
111
281 unless defined $_[0] && $_[0] =~ /\A[1-5]\z/;
282 101 };
283  
284 55808 ▶my $check_options = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
285 55808 my ($what, $option, @allowed) = @_;
286 55808 my %ok = map { $_ => 1 } @allowed;
287 55808 for my $key (sort keys %$option) {
288 263594 ▶ Carp::croak("Game::Senet::Engine: $what has no option called '$key'") unless $ok{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $ok{$key} 1 263593 263594
289 }
290 101 };
291  
292 56188 ▶sub evaluate {
Subroutine evaluate: called CC=3 SCAR=12.5
Pod documented
293 56188 my ($self, $side, $rules, $weights) = @_;
294 56188 ▶ Carp::croak('Game::Senet::Engine: evaluate asks for a side')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $side and $side =~ /\A[01]\z/ 0 56188 56188
Condition33%1/3
defined $side and $side =~ /\A[01]\z/
!ll&&!rl&&r
0056188
MC/DC0%0/2
defined $side and $side =~ /\A[01]\z/
defined $side $side =~ /\A[01]\z/
Truth table33%1/3
A and B
A= defined $sideB= $side =~ /\A[01]\z/
ABresult
0X0
100
111
295 unless defined $side && $side =~ /\A[01]\z/;
296 56188 return _evaluate($self->_ptr, $rules, $weights, $side);
297 }
298  
299 6627 ▶my $check_house = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
300 6627 my ($house) = @_;
301 6627 ▶ Carp::croak('Game::Senet::Engine: a house is a whole number from 1 to 30')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $house and $house =~ /\A[0-9]{1,2}\z/ and $house >= 1 and $house <= 30 10 6617 6627
Condition100%9/9
defined $house and $house =~ /\A[0-9]{1,2}\z/ and $house >= 1 and $house <= 30
!ll&&!rl&&r
826617
defined $house and $house =~ /\A[0-9]{1,2}\z/ and $house >= 1
!ll&&!rl&&r
626619
defined $house and $house =~ /\A[0-9]{1,2}\z/
!ll&&!rl&&r
246621
MC/DC100%4/4
defined $house and $house =~ /\A[0-9]{1,2}\z/ and $house >= 1 and $house <= 30
defined $house $house =~ /\A[0-9]{1,2}\z/ $house >= 1 $house <= 30
Truth table100%5/5
A and B and C and D
A= defined $houseB= $house =~ /\A[0-9]{1,2}\z/C= $house >= 1D= $house <= 30
ABCDresult
0XXX0
10XX0
110X0
11100
11111
302 unless defined $house && $house =~ /\A[0-9]{1,2}\z/ && $house >= 1 && $house <= HOUSES;
303 101 };
304  
305 2360 ▶sub protected {
Subroutine protected: called CC=1 SCAR=0.0
Pod documented
306 2360 my ($self, $house, $rules) = @_;
307 2360 $check_house->($house);
308 2355 return _protected($self->_ptr, $rules, $house);
309 }
310  
311 4267 ▶sub in_blockade {
Subroutine in_blockade: called CC=1 SCAR=0.0
Pod documented
312 4267 my ($self, $house, $rules) = @_;
313 4267 $check_house->($house);
314 4262 return _in_blockade($self->_ptr, $rules, $house);
315 }
316  
317 30734 ▶sub greedy {
Subroutine greedy: called CC=2 SCAR=6.9
Pod documented
318 30734 my ($self, $roll, $rules, $only) = @_;
319 30734 $check_roll->($roll);
320 30734 ▶ return _greedy($self->_ptr, $roll, $rules, $only // 0);
Condition100%2/2
$only // 0
l!l
307295
MC/DC100%1/1
$only // 0
$only
Truth table100%2/2
A
A= $only
Aresult
11
00
321 }
322  
323 53402 ▶sub search {
Subroutine search: called CC=8 SCAR=20.8
Pod documented
324 53402 my ($self, $roll, %option) = @_;
325 53402 $check_roll->($roll);
326 53402 $check_options->('search', \%option, qw(rules weights budget depth only));
327 53401 ▶ my $budget = defined $option{budget} ? $option{budget} : 2_000_000_000;
Branch: 1 branch
BranchTrueFalseTotal
defined $option{'budget'} ? : 51318 2083 53401
328 53401 ▶ my $depth = defined $option{depth} ? $option{depth} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $option{'depth'} ? : 53276 125 53401
329 53401 ▶ Carp::croak('Game::Senet::Engine: a budget is a whole number of nodes from 0 to 2000000000')
Branch: 1 branch
BranchTrueFalseTotal
unless $budget =~ /\A\d{1,10}\z/ and $budget <= 2000000000 2 53399 53401
Condition100%3/3
$budget =~ /\A\d{1,10}\z/ and $budget <= 2000000000
!ll&&!rl&&r
1153399
MC/DC100%2/2
$budget =~ /\A\d{1,10}\z/ and $budget <= 2000000000
$budget =~ /\A\d{1,10}\z/ $budget <= 2000000000
Truth table100%3/3
A and B
A= $budget =~ /\A\d{1,10}\z/B= $budget <= 2000000000
ABresult
0X0
100
111
330 unless $budget =~ /\A\d{1,10}\z/ && $budget <= 2_000_000_000;
331 53399 ▶ Carp::croak('Game::Senet::Engine: a depth is a whole number from 0 to 32')
Branch: 1 branch
BranchTrueFalseTotal
unless $depth =~ /\A\d{1,2}\z/ and $depth <= 32 1 53398 53399
Condition66%2/3
$depth =~ /\A\d{1,2}\z/ and $depth <= 32
!ll&&!rl&&r
0153398
MC/DC50%1/2
$depth =~ /\A\d{1,2}\z/ and $depth <= 32
$depth =~ /\A\d{1,2}\z/ $depth <= 32
Truth table66%2/3
A and B
A= $depth =~ /\A\d{1,2}\z/B= $depth <= 32
ABresult
0X0
100
111
332 unless $depth =~ /\A\d{1,2}\z/ && $depth <= DEPTH_MAX;
333 my ($index, $nodes, $reached, $value, $stopped) =
334 53398 ▶ _search($self->_ptr, $roll, $option{rules}, $option{weights}, $budget, $depth, $option{only} // 0);
Condition100%2/2
$option{"only"} // 0
l!l
511952203
MC/DC100%1/1
$option{"only"} // 0
$option{"only"}
Truth table100%2/2
A
A= $option{"only"}
Aresult
11
00
335 53398 return { index => $index, nodes => $nodes, depth => $reached, value => $value, stopped => $stopped };
336 }
337  
338 2406 ▶sub expect {
Subroutine expect: called CC=6 SCAR=19.3
Pod documented
339 2406 my ($self, $depth, %option) = @_;
340 2406 $check_options->('expect', \%option, qw(rules weights only side));
341 2406 ▶ Carp::croak('Game::Senet::Engine: a depth is a whole number from 0 to 32')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $depth and $depth =~ /\A\d{1,2}\z/ and $depth <= 32 0 2406 2406
Condition33%2/6
defined $depth and $depth =~ /\A\d{1,2}\z/ and $depth <= 32
!ll&&!rl&&r
002406
defined $depth and $depth =~ /\A\d{1,2}\z/
!ll&&!rl&&r
002406
MC/DC0%0/3
defined $depth and $depth =~ /\A\d{1,2}\z/ and $depth <= 32
defined $depth $depth =~ /\A\d{1,2}\z/ $depth <= 32
Truth table25%1/4
A and B and C
A= defined $depthB= $depth =~ /\A\d{1,2}\z/C= $depth <= 32
ABCresult
0XX0
10X0
1100
1111
342 unless defined $depth && $depth =~ /\A\d{1,2}\z/ && $depth <= DEPTH_MAX;
343 2406 ▶ my $side = defined $option{side} ? $option{side} : _side($self->_ptr);
Branch: 1 branch
BranchTrueFalseTotal
defined $option{'side'} ? : 403 2003 2406
344 2406 ▶ return _expect($self->_ptr, $option{rules}, $option{weights}, $option{only} // 0, $depth, $side);
Condition100%2/2
$option{"only"} // 0
l!l
4002006
MC/DC100%1/1
$option{"only"} // 0
$option{"only"}
Truth table100%2/2
A
A= $option{"only"}
Aresult
11
00
345 }
346  
347 2 ▶sub abi_version { _abi_version() }
Subroutine abi_version: called CC=1 SCAR=0.0
Pod documented
348 5 ▶sub live { _live() }
Subroutine live: called CC=1 SCAR=0.0
Pod documented
349  
350 101 1;
351  
352 __END__
« blib/lib/Game/Senet/Rules.pm ↑ Summary blib/lib/Game/Senet/Error.pm »