blib/lib/Game/Fanorona/Engine.pm

filter: Statementstmt 100% 231 / 231 Branchbran 95.5% 65 / 68 Conditioncond 80.0% 12 / 15 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 100% 78 / 78 Podpod 98.4% 62 / 63 totaltotal 97.8% 454 / 464 CC 44 SCAR 14.1
CC
44
Cov
98%
BUILD
17.0
play_move
8.0
size_of
3.0
CRAP 4.1
« blib/lib/Game/Fanorona.pm ↑ Summary blib/lib/Game/Fanorona/Error.pm »
1 package Game::Fanorona::Engine;
2  
3 43 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 43 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 43 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 43 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 43 ▶use Game::Fanorona::Move ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 43 our $VERSION = '0.01';
14  
15 43 require XSLoader;
16 43 XSLoader::load('Game::Fanorona', $VERSION);
17  
18 43 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
19 43 EMPTY => 0,
20 WHITE => 1,
21 BLACK => 2,
22 BORDER => 3,
23 43 };
24  
25 43 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 43 N => 0,
27 NE => 1,
28 E => 2,
29 SE => 3,
30 S => 4,
31 SW => 5,
32 W => 6,
33 NW => 7,
34 43 };
35  
36 43 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
37 43 POS_OK => 0,
38 POS_NULL => 1,
39 POS_LONG => 2,
40 POS_LETTER => 3,
41 POS_ROWS => 4,
42 POS_WIDTH => 5,
43 POS_SIDE => 6,
44 43 };
45  
46 43 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
47 43 PAIKA => 0,
48 APPROACH => 1,
49 WITHDRAWAL => 2,
50 43 };
51  
52 43 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
53 43 WHY_OK => 0,
54 WHY_OFF_BOARD => 1,
55 WHY_BAD_STEP => 2,
56 WHY_NO_STONE => 3,
57 WHY_NOT_YOURS => 4,
58 WHY_NO_LINE => 5,
59 WHY_OCCUPIED => 6,
60 WHY_TAKES_NOTHING => 7,
61 WHY_NOT_A_PAIKA => 8,
62 WHY_MUST_CAPTURE => 9,
63 WHY_NOT_THE_STONE => 10,
64 WHY_SAME_DIRECTION => 11,
65 WHY_REVISIT => 12,
66 WHY_PAIKA_IN_CHAIN => 13,
67 43 };
68  
69 43 our @EXPORT_OK = qw(
70 EMPTY WHITE BLACK BORDER
71 N NE E SE S SW W NW
72 POS_OK POS_NULL POS_LONG POS_LETTER POS_ROWS POS_WIDTH POS_SIDE
73 PAIKA APPROACH WITHDRAWAL
74 WHY_OK WHY_OFF_BOARD WHY_BAD_STEP WHY_NO_STONE WHY_NOT_YOURS WHY_NO_LINE
75 WHY_OCCUPIED WHY_TAKES_NOTHING WHY_NOT_A_PAIKA WHY_MUST_CAPTURE
76 WHY_NOT_THE_STONE WHY_SAME_DIRECTION WHY_REVISIT WHY_PAIKA_IN_CHAIN
77 other
78 );
79 43 our %EXPORT_TAGS = (all => \@EXPORT_OK);
80  
81 18242 ▶sub other { $_[0] == WHITE ? BLACK : WHITE }
Subroutine other: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 ? : 10019 8223 18242
82  
83 43 my %SIZE = (
84 sivy => [ 9, 5 ],
85 dimy => [ 5, 5 ],
86 telo => [ 3, 3 ],
87 );
88  
89 43 has _ptr => (is => 'rw', private => 1);
90  
91 43 has _hold => (is => 'rw', private => 1);
92  
93 43 has _want_empty => (is => 'ro', init_arg => 'empty', private => 1, default => 0);
94  
95 43 has _want_position => (is => 'ro', init_arg => 'position', private => 1);
96  
97 43 has _want_board => (is => 'ro', init_arg => 'board', private => 1);
98  
99 43 has _want_cols => (is => 'ro', init_arg => 'cols', private => 1);
100  
101 43 has _want_rows => (is => 'ro', init_arg => 'rows', private => 1);
102  
103 43 my %ADOPTING;
104  
105 472196 ▶sub BUILD {
Subroutine BUILD: called CC=17 SCAR=28.3
Pod undocumented
106 472196 my ($self) = @_;
107 472196 my $given = $self->_ptr;
108 472196 ▶ if ($given) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given) 469668 2528 472196
109 469668 ▶ if (delete $ADOPTING{$given}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $ADOPTING{$given}) 469667 1 469668
110 469667 $self->_hold(_hold_board($given));
111 469667 return;
112 }
113 1 $self->_ptr(0);
114 1 Carp::croak("Game::Fanorona::Engine: a board is made by new, of_string or clone");
115 }
116  
117 2528 my $position = $self->_want_position;
118 2528 ▶ if (defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position) 2 2526 2528
119 2 my ($ptr, $err) = _of_string($position);
120 2 ▶ Carp::croak("Game::Fanorona::Engine: the position was refused, code $err")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ptr 1 1 2
121 unless defined $ptr;
122 1 $self->_ptr($ptr);
123 1 $self->_hold(_hold_board($ptr));
124 1 return;
125 }
126  
127 2526 my ($cols, $rows) = ($self->_want_cols, $self->_want_rows);
128 2526 my $name = $self->_want_board;
129 2526 ▶ if (defined $name) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $name) { } 7 2519 2526
elsif (defined $cols or defined $rows) { } 1698 821 2519
130 7 ▶ Carp::croak("Game::Fanorona::Engine: give a board by name or by cols and rows, not both")
Branch: 1 branch
BranchTrueFalseTotal
if defined $cols or defined $rows 1 6 7
Condition66%2/3
defined $cols or defined $rows
l!l&&r!l&&!r
106
MC/DC50%1/2
defined $cols or defined $rows
defined $cols defined $rows
Truth table66%2/3
A or B
A= defined $colsB= defined $rows
ABresult
1X1
011
000
131 if defined $cols || defined $rows;
132 6 ▶ my $size = $SIZE{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $size = $SIZE{$name} or Carp::croak("Game::Fanorona::Engine: no board is called '${name}'") 5 1 6
133 or Carp::croak("Game::Fanorona::Engine: no board is called '$name'");
134 5 ($cols, $rows) = @$size;
135 }
136 ▶ elsif (defined $cols || defined $rows) {
Condition66%2/3
defined $cols or defined $rows
l!l&&r!l&&!r
16980821
MC/DC50%1/2
defined $cols or defined $rows
defined $cols defined $rows
Truth table66%2/3
A or B
A= defined $colsB= defined $rows
ABresult
1X1
011
000
137 1698 ▶ Carp::croak("Game::Fanorona::Engine: a size is both cols and rows")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cols and defined $rows 1 1697 1698
Condition66%2/3
defined $cols and defined $rows
!ll&&!rl&&r
011697
MC/DC50%1/2
defined $cols and defined $rows
defined $cols defined $rows
Truth table66%2/3
A and B
A= defined $colsB= defined $rows
ABresult
0X0
100
111
138 unless defined $cols && defined $rows;
139 }
140 else {
141 821 ($cols, $rows) = @{ $SIZE{sivy} };
142 }
143 2523 ▶ Carp::croak("Game::Fanorona::Engine: no board is $cols by $rows")
Branch: 1 branch
BranchTrueFalseTotal
unless $cols =~ /\A[0-9]+\z/u and $rows =~ /\A[0-9]+\z/u and _size_ok($cols, $rows) 11 2512 2523
Condition100%6/6
$cols =~ /\A[0-9]+\z/u and $rows =~ /\A[0-9]+\z/u and _size_ok($cols, $rows)
!ll&&!rl&&r
382512
$cols =~ /\A[0-9]+\z/u and $rows =~ /\A[0-9]+\z/u
!ll&&!rl&&r
212520
MC/DC100%3/3
$cols =~ /\A[0-9]+\z/u and $rows =~ /\A[0-9]+\z/u and _size_ok($cols, $rows)
$cols =~ /\A[0-9]+\z/u $rows =~ /\A[0-9]+\z/u _size_ok($cols, $rows)
Truth table100%4/4
A and B and C
A= $cols =~ /\A[0-9]+\z/uB= $rows =~ /\A[0-9]+\z/uC= _size_ok($cols, $rows)
ABCresult
0XX0
10X0
1100
1111
144 unless $cols =~ /\A[0-9]+\z/ && $rows =~ /\A[0-9]+\z/ && _size_ok($cols, $rows);
145  
146 2512 ▶ $self->_ptr($self->_want_empty ? _new_empty($cols, $rows) : _new_board($cols, $rows));
Branch: 1 branch
BranchTrueFalseTotal
$self->_want_empty ? : 593 1919 2512
147 2512 $self->_hold(_hold_board($self->_ptr));
148 2512 return;
149 }
150  
151 469667 ▶my $adopt = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
152 469667 my ($class, $ptr) = @_;
153 469667 $ADOPTING{$ptr} = 1;
154 469667 return $class->new(_ptr => $ptr);
155 43 };
156  
157 473383 ▶sub of_string {
Subroutine of_string: called CC=3 SCAR=11.0
Pod documented
158 473383 my ($class, $position) = @_;
159 473383 ▶ my ($ptr, $err) = _of_string(defined $position ? $position : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $position ? : 473382 1 473383
160 473383 ▶ return (undef, $err) unless defined $ptr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ptr 3720 469663 473383
161 469663 return ($adopt->($class, $ptr), POS_OK);
162 }
163  
164 4 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
165 4 my ($self) = @_;
166 4 return $adopt->(ref($self), _copy_board($self->_ptr));
167 }
168  
169 409870 ▶sub at { _at($_[0]->_ptr, $_[1]) }
Subroutine at: called CC=1 SCAR=0.0
Pod documented
170 192742 ▶sub put { _put($_[0]->_ptr, $_[1], $_[2]); return $_[0] }
Subroutine put: called CC=1 SCAR=0.0
Pod documented
171 181702 ▶sub lift { _lift($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine lift: called CC=1 SCAR=0.0
Pod documented
172 17996 ▶sub side { _side($_[0]->_ptr) }
Subroutine side: called CC=1 SCAR=0.0
Pod documented
173 1862 ▶sub set_side { _set_side($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine set_side: called CC=1 SCAR=0.0
Pod documented
174 30113 ▶sub count { _count($_[0]->_ptr, $_[1]) }
Subroutine count: called CC=1 SCAR=0.0
Pod documented
175 200453 ▶sub to_string { _to_string($_[0]->_ptr) }
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
176 28146 ▶sub key_hex { _key_hex($_[0]->_ptr) }
Subroutine key_hex: called CC=1 SCAR=0.0
Pod documented
177 8007 ▶sub key_full_hex { _key_full_hex($_[0]->_ptr) }
Subroutine key_full_hex: called CC=1 SCAR=0.0
Pod documented
178  
179 6599 ▶sub cols { _board_cols($_[0]->_ptr) }
Subroutine cols: called CC=1 SCAR=0.0
Pod documented
180 6597 ▶sub rows { _board_rows($_[0]->_ptr) }
Subroutine rows: called CC=1 SCAR=0.0
Pod documented
181 4 ▶sub points { _board_points($_[0]->_ptr) }
Subroutine points: called CC=1 SCAR=0.0
Pod documented
182 38 ▶sub centre { _board_centre($_[0]->_ptr) }
Subroutine centre: called CC=1 SCAR=0.0
Pod documented
183 1052 ▶sub on_board { _on_board($_[0]->_ptr, $_[1]) }
Subroutine on_board: called CC=1 SCAR=0.0
Pod documented
184 3331 ▶sub next_to { _next($_[0]->_ptr, $_[1], $_[2]) }
Subroutine next_to: called CC=1 SCAR=0.0
Pod documented
185 12 ▶sub degree { _degree($_[0]->_ptr, $_[1]) }
Subroutine degree: called CC=1 SCAR=0.0
Pod documented
186  
187 3 ▶sub neighbours {
Subroutine neighbours: called CC=1 SCAR=0.0
Pod documented
188 3 my ($self, $sq) = @_;
189 3 my $ptr = $self->_ptr;
190 3 return grep { $_ >= 0 } map { _next($ptr, $sq, $_) } N .. NW;
191 }
192  
193 12 ▶sub segments {
Subroutine segments: called CC=2 SCAR=6.9
Pod documented
194 12 my ($self) = @_;
195 12 my @flat = _segments($self->_ptr);
196 12 my @pairs;
197 12 ▶ push @pairs, [ splice @flat, 0, 2 ] while @flat;
Branch: 1 branch
BranchTrueFalseTotal
@flat and do { push @pairs, [splice(@flat, 0, 2)] } 712 12 724
198 12 return @pairs;
199 }
200  
201 5319 ▶sub all_squares {
Subroutine all_squares: called CC=2 SCAR=6.9
Pod documented
202 5319 my ($self) = @_;
203 5319 my ($cols, $rows) = ($self->cols, $self->rows);
204 5319 my @squares;
205 5319 for my $rank (0 .. $rows - 1) {
206 26585 push @squares, map { _square_of($_, $rank) } 0 .. $cols - 1;
207 }
208 5319 return @squares;
209 }
210  
211 409 ▶sub square_of { my $c = shift; _square_of($_[0], $_[1]) }
Subroutine square_of: called CC=1 SCAR=0.0
Pod documented
212 407 ▶sub file_of { my $c = shift; _file_of($_[0]) }
Subroutine file_of: called CC=1 SCAR=0.0
Pod documented
213 286 ▶sub rank_of { my $c = shift; _rank_of($_[0]) }
Subroutine rank_of: called CC=1 SCAR=0.0
Pod documented
214 291 ▶sub is_strong { my $c = shift; _is_strong($_[0]) }
Subroutine is_strong: called CC=1 SCAR=0.0
Pod documented
215 225 ▶sub opposite { my $c = shift; _dir_opposite($_[0]) }
Subroutine opposite: called CC=1 SCAR=0.0
Pod documented
216 224 ▶sub is_diagonal { my $c = shift; _dir_is_diagonal($_[0]) }
Subroutine is_diagonal: called CC=1 SCAR=0.0
Pod documented
217 1445 ▶sub size_ok { my $c = shift; _size_ok($_[0], $_[1]) }
Subroutine size_ok: called CC=1 SCAR=0.0
Pod documented
218 1 ▶sub stride { _stride() }
Subroutine stride: called CC=1 SCAR=0.0
Pod documented
219  
220 4939 ▶sub size_of {
Subroutine size_of: called CC=3 SCAR=11.1
Pod documented
221 4939 my ($class, $name) = @_;
222 4939 ▶ my $size = defined $name ? $SIZE{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 4939 0 4939
223 4939 ▶ return $size ? @$size : ();
Branch: 1 branch
BranchTrueFalseTotal
$size ? : 4929 10 4939
224 }
225  
226 6 ▶sub zobrist_hex { my $c = shift; _zobrist_hex($_[0], $_[1]) }
Subroutine zobrist_hex: called CC=1 SCAR=0.0
Pod documented
227 1 ▶sub zobrist_side_hex { _zobrist_side_hex() }
Subroutine zobrist_side_hex: called CC=1 SCAR=0.0
Pod documented
228 3 ▶sub zobrist_size_hex { my $c = shift; _zobrist_size_hex($_[0], $_[1]) }
Subroutine zobrist_size_hex: called CC=1 SCAR=0.0
Pod documented
229 2 ▶sub abi_version { _abi_version() }
Subroutine abi_version: called CC=1 SCAR=0.0
Pod documented
230 12 ▶sub live { _live() }
Subroutine live: called CC=1 SCAR=0.0
Pod documented
231  
232 2638920 ▶my $step = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
233 2638920 my ($raw) = @_;
234 2638920 my ($from, $to, $dir, $kind, @taken) = @$raw;
235 2638920 return { from => $from, to => $to, dir => $dir, kind => $kind, taken => \@taken };
236 43 };
237  
238 186382 ▶my $triple = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
239 186382 ▶ return @{ $_[0] }{qw(from dir kind)} if ref $_[0] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 42663 143719 186382
240 143719 return @_[0 .. 2];
241 43 };
242  
243 5618 ▶sub steps {
Subroutine steps: called CC=2 SCAR=6.9
Pod documented
244 5618 my ($self) = @_;
245 5618 my @raw = _gen_steps($self->_ptr);
246 5618 ▶ return wantarray ? map { $step->($_) } @raw : scalar @raw;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5616 2 5618
247 }
248  
249 6 ▶sub steps_of {
Subroutine steps_of: called CC=1 SCAR=0.0
Pod documented
250 6 my ($self, $sq) = @_;
251 6 return map { $step->($_) } _steps_of($self->_ptr, $sq);
252 }
253  
254 9 ▶sub can_capture {
Subroutine can_capture: called CC=2 SCAR=6.9
Pod documented
255 9 my ($self, $side) = @_;
256 9 ▶ return _can_capture($self->_ptr, defined $side ? $side : _side($self->_ptr));
Branch: 1 branch
BranchTrueFalseTotal
defined $side ? : 6 3 9
257 }
258  
259 64830 ▶sub step_why {
Subroutine step_why: called CC=1 SCAR=0.0
Pod documented
260 64830 my $self = shift;
261 64830 return _step_why($self->_ptr, $triple->(@_));
262 }
263  
264 10 ▶sub step {
Subroutine step: called CC=2 SCAR=6.9
Pod documented
265 10 my $self = shift;
266 10 my ($raw) = _step_build($self->_ptr, $triple->(@_));
267 10 ▶ return $raw ? $step->($raw) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 2 8 10
268 }
269  
270 5014 ▶sub do_step {
Subroutine do_step: called CC=3 SCAR=11.0
Pod documented
271 5014 my $self = shift;
272 5014 my ($removed, $token) = _do_step($self->_ptr, $triple->(@_));
273 5014 ▶ return unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 1 5013 5014
274 5013 ▶ return wantarray ? ($token, $removed) : $token;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5001 12 5013
275 }
276  
277 5007 ▶sub undo_step { _undo_step($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine undo_step: called CC=1 SCAR=0.0
Pod documented
278  
279 10 ▶sub perft_steps { _perft_steps($_[0]->_ptr, $_[1]) }
Subroutine perft_steps: called CC=1 SCAR=0.0
Pod documented
280  
281 3 ▶sub steps_max { _steps_max() }
Subroutine steps_max: called CC=1 SCAR=0.0
Pod documented
282 2 ▶sub line_max { _line_max() }
Subroutine line_max: called CC=1 SCAR=0.0
Pod documented
283 2 ▶sub chain_max { _chain_max() }
Subroutine chain_max: called CC=1 SCAR=0.0
Pod documented
284  
285 23580 ▶sub in_chain { _chain_at($_[0]->_ptr) >= 0 ? 1 : 0 }
Subroutine in_chain: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
_chain_at($_[0]->_ptr) >= 0 ? : 5614 17966 23580
286 4 ▶sub chain_at { _chain_at($_[0]->_ptr) }
Subroutine chain_at: called CC=1 SCAR=0.0
Pod documented
287 5 ▶sub chain_dir { _chain_dir($_[0]->_ptr) }
Subroutine chain_dir: called CC=1 SCAR=0.0
Pod documented
288  
289 5 ▶sub chain_seen {
Subroutine chain_seen: called CC=1 SCAR=0.0
Pod documented
290 5 my ($self) = @_;
291 5 my $ptr = $self->_ptr;
292 5 return grep { _chain_seen($ptr, $_) } $self->all_squares;
293 }
294  
295 3111 ▶sub play_steps {
Subroutine play_steps: called CC=2 SCAR=6.9
Pod documented
296 3111 my ($self) = @_;
297 3111 my @raw = _play_steps($self->_ptr);
298 3111 ▶ return wantarray ? map { $step->($_) } @raw : scalar @raw;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3109 2 3111
299 }
300  
301 2 ▶sub can_stop { _can_stop($_[0]->_ptr) }
Subroutine can_stop: called CC=1 SCAR=0.0
Pod documented
302  
303 94706 ▶sub play_why {
Subroutine play_why: called CC=1 SCAR=0.0
Pod documented
304 94706 my $self = shift;
305 94706 return _play_why($self->_ptr, $triple->(@_));
306 }
307  
308 21822 ▶sub play {
Subroutine play: called CC=3 SCAR=11.0
Pod documented
309 21822 my $self = shift;
310 21822 my ($removed, $token) = _play_step($self->_ptr, $triple->(@_));
311 21822 ▶ return unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 21822 21822
312 21822 ▶ return wantarray ? ($token, $removed) : $token;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 21821 21822
313 }
314  
315 2960 ▶sub stop {
Subroutine stop: called CC=1 SCAR=0.0
Pod documented
316 2960 my ($self) = @_;
317 2960 my ($token) = _play_stop($self->_ptr);
318 2960 return $token;
319 }
320  
321 24761 ▶sub unplay { _play_undo($_[0]->_ptr, $_[1]); return $_[0] }
Subroutine unplay: called CC=1 SCAR=0.0
Pod documented
322  
323 406 ▶sub count_moves {
Subroutine count_moves: called CC=2 SCAR=6.9
Pod documented
324 406 my ($self, $cap) = @_;
325 406 ▶ return _count_moves($self->_ptr, defined $cap ? $cap : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $cap ? : 2 404 406
326 }
327  
328 462321 ▶sub moves {
Subroutine moves: called CC=2 SCAR=6.9
Pod documented
329 462321 my ($self, $limit) = @_;
330 462321 ▶ my @raw = _gen_moves($self->_ptr, defined $limit ? $limit : 100_000);
Branch: 1 branch
BranchTrueFalseTotal
defined $limit ? : 2 462319 462321
331 return map {
332 462320 my @steps = map { $step->($_) } @$_;
333 2358647 Game::Fanorona::Move->new(from => $steps[0]{from}, steps => \@steps);
334 } @raw;
335 }
336  
337 6663 ▶sub play_move {
Subroutine play_move: called CC=8 SCAR=20.8
Pod documented
338 6663 my ($self, $move) = @_;
339 6663 ▶ return if $self->in_chain;
Branch: 1 branch
BranchTrueFalseTotal
if $self->in_chain 2 6661 6663
340 6661 my @tokens;
341 6661 for my $s (@{ $move->steps }) {
342 15848 my $ok = $self->play_why($s) == WHY_OK;
343 15848 ▶ my $token = $ok ? $self->play($s) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 15846 2 15848
344 15848 ▶ if (!defined $token) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $token) 2 15846 15848
345 2 $self->unplay($_) for reverse @tokens;
346 2 return;
347 }
348 15846 push @tokens, $token;
349 }
350 6659 ▶ return unless @tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 0 6659 6659
351 6659 ▶ push @tokens, $self->stop if $self->in_chain;
Branch: 1 branch
BranchTrueFalseTotal
if $self->in_chain 2957 3702 6659
352 6659 return \@tokens;
353 }
354  
355 6658 ▶sub unplay_move {
Subroutine unplay_move: called CC=2 SCAR=6.9
Pod documented
356 6658 my ($self, $tokens) = @_;
357 6658 $self->unplay($_) for reverse @$tokens;
358 6658 return $self;
359 }
360  
361 18 ▶sub perft_moves { _perft_moves($_[0]->_ptr, $_[1]) }
Subroutine perft_moves: called CC=1 SCAR=0.0
Pod documented
362  
363 43 1;
364  
365 __END__
« blib/lib/Game/Fanorona.pm ↑ Summary blib/lib/Game/Fanorona/Error.pm »