blib/lib/Game/Sternhalma.pm

filter: Statementstmt 99.5% 213 / 214 Branchbran 88.1% 104 / 118 Conditioncond 94.7% 36 / 38 MC/DCmcdc 86.3% 19 / 22 Subroutinesub 97.5% 40 / 41 Podpod 96.3% 26 / 27 totaltotal 95.2% 438 / 460 CC 76 SCAR 20.8
CC
76
Cov
95%
_parse
18.1
_play
16.0
BUILD
12.0
CRAP 8.0
« blib/lib/Game/Sternhalma/Bot.pm ↑ Summary blib/lib/Game/Sternhalma/Layout.pm »
1 package Game::Sternhalma;
2  
3 30 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 ▶use Game::Sternhalma::Engine qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 30 ▶use Game::Sternhalma::Error ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 30 ▶use Game::Sternhalma::Layout ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 30 ▶use Game::Sternhalma::Notation ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 30 ▶use Game::Sternhalma::Result ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 30 our $VERSION = '0.01';
16  
17 30 our %REASON = (
18 bad_string => 'that is not a move',
19 no_such_hole => 'that names a hole the star does not have',
20 no_piece => 'there is no piece there',
21 not_your_piece => 'that piece is not yours to move',
22 must_pass => 'you have no move, and must pass',
23 occupied => 'a piece is standing there',
24 not_reachable => 'that piece cannot get there this turn',
25 pass_not_allowed => 'you have a move, so you may not pass',
26 no_such_seat => 'the game has no such seat',
27 seat_finished => 'that seat is home already',
28 seat_resigned => 'that seat has resigned already',
29 game_over => 'the game is over',
30 );
31  
32 30 my %HOW = (BY_HOME, 'home', BY_CAP, 'cap', BY_DEADLOCK, 'deadlock', BY_RESIGN, 'resign');
33  
34 30 has _want_seats => (is => 'ro', init_arg => 'seats', private => 1, default => 2);
35  
36 30 has _want_pieces => (is => 'ro', init_arg => 'pieces', private => 1, default => 10);
37  
38 30 has _want_first => (is => 'ro', init_arg => 'first', private => 1);
39  
40 30 has _want_position => (is => 'ro', init_arg => 'position', private => 1);
41  
42 30 has _start => (is => 'rw', private => 1);
43  
44 30 has solo => (is => 'ro', default => 0);
45  
46 30 has _want_cap => (is => 'ro', init_arg => 'cap', private => 1);
47  
48 30 has _board => (is => 'rw', private => 1);
49  
50 30 has _undo => (is => 'rw', private => 1);
51  
52 30 has _moves => (is => 'rw', private => 1);
53  
54 30 has _keys => (is => 'rw', private => 1);
55  
56 30 has _movers => (is => 'rw', private => 1);
57  
58 182 ▶sub BUILD {
Subroutine BUILD: called CC=12 SCAR=24.8
Pod undocumented
59 182 my ($self) = @_;
60 182 my $position = $self->_want_position;
61 182 my $board;
62 182 ▶ if (defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position) { } 15 167 182
63 15 ▶ Game::Sternhalma::Error->throw(bad_first => 'a game from a position starts with its seat to move')
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_want_first 1 14 15
64 if defined $self->_want_first;
65 14 my ($read, $code) = Game::Sternhalma::Engine->from_string($position);
66 14 ▶ Game::Sternhalma::Error->throw(bad_position => Game::Sternhalma::Engine->reason($code)) unless $read;
Branch: 1 branch
BranchTrueFalseTotal
unless $read 1 13 14
67 13 my $why = Game::Sternhalma::Layout::why_not($read->seats, $read->pieces, $self->solo);
68 13 ▶ Game::Sternhalma::Error->throw(bad_layout => $why) if defined $why;
Branch: 1 branch
BranchTrueFalseTotal
if defined $why 0 13 13
69 13 $board = $read;
70 13 $self->_start($position);
71 }
72 else {
73 167 my ($seats, $pieces) = ($self->_want_seats, $self->_want_pieces);
74 167 my $why = Game::Sternhalma::Layout::why_not($seats, $pieces, $self->solo);
75 167 ▶ Game::Sternhalma::Error->throw(bad_layout => $why) if defined $why;
Branch: 1 branch
BranchTrueFalseTotal
if defined $why 5 162 167
76 162 ▶ my $first = $self->_want_first // 0;
Condition100%2/2
$self->_want_first // 0
l!l
17145
MC/DC100%1/1
$self->_want_first // 0
$self->_want_first
Truth table100%2/2
A
A= $self->_want_first
Aresult
11
00
77 162 ▶ Game::Sternhalma::Error->throw(bad_first => "the first seat must be 0 to " . ($seats - 1))
Branch: 1 branch
BranchTrueFalseTotal
unless $first =~ /\A[0-9]+\z/u and $first < $seats 2 160 162
Condition100%3/3
$first =~ /\A[0-9]+\z/u and $first < $seats
!ll&&!rl&&r
11160
MC/DC100%2/2
$first =~ /\A[0-9]+\z/u and $first < $seats
$first =~ /\A[0-9]+\z/u $first < $seats
Truth table100%3/3
A and B
A= $first =~ /\A[0-9]+\z/uB= $first < $seats
ABresult
0X0
100
111
78 unless $first =~ /\A[0-9]+\z/ && $first < $seats;
79 160 $board = Game::Sternhalma::Engine->new(seats => $seats, pieces => $pieces);
80 160 $board->set_to_move($first);
81 }
82 173 my $cap = $self->_want_cap;
83 173 ▶ if (defined $cap) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cap) 27 146 173
84 27 ▶ Game::Sternhalma::Error->throw(bad_cap => 'the cap is a number of plies above 0')
Branch: 1 branch
BranchTrueFalseTotal
unless $cap =~ /\A[0-9]+\z/u and $cap > 0 2 25 27
Condition100%3/3
$cap =~ /\A[0-9]+\z/u and $cap > 0
!ll&&!rl&&r
1125
MC/DC100%2/2
$cap =~ /\A[0-9]+\z/u and $cap > 0
$cap =~ /\A[0-9]+\z/u $cap > 0
Truth table100%3/3
A and B
A= $cap =~ /\A[0-9]+\z/uB= $cap > 0
ABresult
0X0
100
111
85 unless $cap =~ /\A[0-9]+\z/ && $cap > 0;
86 25 $board->set_cap($cap);
87 }
88 171 $self->_board($board);
89 171 $self->_undo([]);
90 171 $self->_moves([]);
91 171 $self->_keys([ map { [ $board->own_key($_) ] } 0 .. $board->seats - 1 ]);
92 171 $self->_movers([]);
93 171 return;
94 }
95  
96 # ---- reading the game -------------------------------------------------------------------
97  
98 24329 ▶sub seats { $_[0]->_board->seats }
Subroutine seats: called CC=1 SCAR=0.0
Pod documented
99 251 ▶sub pieces { $_[0]->_board->pieces }
Subroutine pieces: called CC=1 SCAR=0.0
Pod documented
100 234 ▶sub first { defined $_[0]->_start ? undef : $_[0]->_want_first // 0 }
Subroutine first: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->_start ? : 28 206 234
Condition100%2/2
$_[0]->_want_first // 0
l!l
13193
MC/DC100%1/1
$_[0]->_want_first // 0
$_[0]->_want_first
Truth table100%2/2
A
A= $_[0]->_want_first
Aresult
11
00
101 0 ▶sub start { $_[0]->_start }
Subroutine start: not called CC=1 SCAR=6.9
Pod documented
102 8788 ▶sub to_move { $_[0]->_board->to_move }
Subroutine to_move: called CC=1 SCAR=0.0
Pod documented
103 6565 ▶sub over { $_[0]->_board->over }
Subroutine over: called CC=1 SCAR=0.0
Pod documented
104 526 ▶sub ply { $_[0]->_board->ply }
Subroutine ply: called CC=1 SCAR=0.0
Pod documented
105 238 ▶sub cap { $_[0]->_board->cap }
Subroutine cap: called CC=1 SCAR=0.0
Pod documented
106 624 ▶sub places { $_[0]->_board->places }
Subroutine places: called CC=1 SCAR=0.0
Pod documented
107 20 ▶sub position { $_[0]->_board->to_string }
Subroutine position: called CC=1 SCAR=0.0
Pod documented
108 24 ▶sub key { $_[0]->_board->key }
Subroutine key: called CC=1 SCAR=0.0
Pod documented
109 40880 ▶sub board { $_[0]->_board->clone }
Subroutine board: called CC=1 SCAR=0.0
Pod documented
110 1610 ▶sub distance_left { $_[0]->_board->distance_left($_[1]) }
Subroutine distance_left: called CC=1 SCAR=0.0
Pod documented
111 61712 ▶sub at { $_[0]->_board->at(Game::Sternhalma::Notation::hole_of($_[1]) // $_[1]) }
Subroutine at: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
Game::Sternhalma::Notation::hole_of($_[1]) // $_[1]
l!l&&r!l&&!r
1617110
MC/DC0%0/2
Game::Sternhalma::Notation::hole_of($_[1]) // $_[1]
Game::Sternhalma::Notation::hole_of($_[1]) $_[1]
Truth table66%2/3
A // B
A= Game::Sternhalma::Notation::hole_of($_[1])B= $_[1]
ABresult
1X1
011
000
112  
113 40 ▶sub how {
Subroutine how: called CC=2 SCAR=7.2
Pod documented
114 40 my ($self) = @_;
115 40 ▶ return $self->over ? $HOW{ $self->_board->how } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->over ? : 40 0 40
116 }
117  
118 1234 ▶sub finished {
Subroutine finished: called CC=1 SCAR=0.0
Pod documented
119 1234 my ($self) = @_;
120 1234 my $bd = $self->_board;
121 1234 my @home = grep { $bd->finished($_) } 0 .. $self->seats - 1;
122 1234 return sort { $bd->place_of($a) <=> $bd->place_of($b) } @home;
123 }
124  
125 5 ▶sub result {
Subroutine result: called CC=2 SCAR=7.1
Pod documented
126 5 my ($self) = @_;
127 5 ▶ return undef unless $self->over;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->over 0 5 5
128 5 return Game::Sternhalma::Result->new(
129 how => $self->how, places => [ $self->places ], ply => $self->ply, position => $self->position,
130 );
131 }
132  
133 2033 ▶sub legal {
Subroutine legal: called CC=3 SCAR=11.0
Pod documented
134 2033 my ($self) = @_;
135 2033 my $bd = $self->_board;
136 2033 ▶ return () if $bd->over;
Branch: 1 branch
BranchTrueFalseTotal
if $bd->over 0 2033 2033
137 2033 ▶ return ({ kind => 'pass', text => 'pass' }) if $bd->can_pass;
Branch: 1 branch
BranchTrueFalseTotal
if $bd->can_pass 1 2032 2033
138 return map {
139 2032 my ($from, $to) = @$_;
140 79851 { kind => 'move', from => $from, to => $to, path => [ $bd->path($from, $to) ], text => $bd->move_text($from, $to) }
141 } $bd->legal;
142 }
143  
144 1001 ▶sub moves { @{ $_[0]->_moves } }
Subroutine moves: called CC=1 SCAR=0.0
Pod documented
145  
146 4214 ▶sub history {
Subroutine history: called CC=3 SCAR=11.4
Pod documented
147 4214 my ($self, $seat) = @_;
148 4214 ▶ $seat = $self->to_move unless defined $seat;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat 0 4214 4214
149 4214 ▶ my $k = $self->_keys->[$seat] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $k = $self->_keys->[$seat] or return 4214 0 4214
150 4214 return @$k;
151 }
152  
153 18 ▶sub reason {
Subroutine reason: called CC=2 SCAR=7.2
Pod documented
154 18 my (undef, $flag) = @_;
155 18 ▶ return defined $flag ? $REASON{$flag} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $flag ? : 18 0 18
156 }
157  
158 # ---- playing ------------------------------------------------------------------------------
159 #
160 # PLAY RETURNS A FLAG AND NEVER THROWS. Undef when the move was made; otherwise
161 # one name, one reason. A caller maps the names, and nothing here is a second
162 # opinion on the engine's.
163  
164 5673 ▶sub play {
Subroutine play: called CC=2 SCAR=7.0
Pod documented
165 5673 my ($self, $move) = @_;
166 5673 my $flag = eval { $self->_play($move) };
167 5673 ▶ return $@ ? 'bad_string' : $flag;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 5673 5673
168 }
169  
170 5673 ▶sub _play {
Subroutine _play: called CC=16 SCAR=27.7
171 5673 my ($self, $move) = @_;
172 5673 my $bd = $self->_board;
173 5673 ▶ return 'game_over' if $bd->over;
Branch: 1 branch
BranchTrueFalseTotal
if $bd->over 1 5672 5673
174 5672 my ($kind, $from, $to, $path, $seat) = _parse($move);
175 5672 ▶ return $kind if $kind ne 'move' && $kind ne 'pass' && $kind ne 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "move" and $kind ne "pass" and $kind ne "resign" 18 5654 5672
Condition100%6/6
$kind ne "move" and $kind ne "pass" and $kind ne "resign"
!ll&&!rl&&r
5652218
$kind ne "move" and $kind ne "pass"
!ll&&!rl&&r
5650220
MC/DC100%3/3
$kind ne "move" and $kind ne "pass" and $kind ne "resign"
$kind ne "move" $kind ne "pass" $kind ne "resign"
Truth table100%4/4
A and B and C
A= $kind ne "move"B= $kind ne "pass"C= $kind ne "resign"
ABCresult
0XX0
10X0
1100
1111
176 5654 ▶ return $self->_resign($seat) if $kind eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "resign" 2 5652 5654
177 5652 ▶ if ($kind eq 'pass') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "pass") 2 5650 5652
178 2 ▶ return 'pass_not_allowed' unless $bd->can_pass;
Branch: 1 branch
BranchTrueFalseTotal
unless $bd->can_pass 1 1 2
179 1 my $mover = $bd->to_move;
180 1 my ($why, $undo) = $bd->pass;
181 1 return $self->_done($undo, 'pass', $mover);
182 }
183 5650 my $piece = $bd->at($from);
184 5650 ▶ return 'no_piece' unless defined $piece;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $piece 2 5648 5650
185 5648 ▶ return 'not_your_piece' unless $piece == $bd->to_move;
Branch: 1 branch
BranchTrueFalseTotal
unless $piece == $bd->to_move 1 5647 5648
186 5647 ▶ return 'must_pass' if $bd->can_pass;
Branch: 1 branch
BranchTrueFalseTotal
if $bd->can_pass 1 5646 5647
187 5646 ▶ return 'occupied' if defined $bd->at($to);
Branch: 1 branch
BranchTrueFalseTotal
if defined $bd->at($to) 1 5645 5646
188 5645 ▶ if ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 867 4778 5645
189 867 for my $i (1 .. $#$path) {
190 2044 ▶ return 'not_reachable' unless grep { $_ == $path->[$i] } $bd->hops($path->[ $i - 1 ], $from);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ == $path->[$i];} $bd->hops($$path[$i - 1], $from) 1 2043 2044
191 }
192 }
193 5644 my $text = $bd->move_text($from, $to);
194 5644 my $mover = $bd->to_move;
195 5644 my ($why, $undo) = $bd->play($from, $to);
196 5644 ▶ return 'not_reachable' unless $why == PLAY_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $why == 0 3 5641 5644
197 5641 return $self->_done($undo, $text, $mover);
198 }
199  
200 14 ▶sub resign {
Subroutine resign: called CC=3 SCAR=11.0
Pod documented
201 14 my ($self, $seat) = @_;
202 14 ▶ my $flag = eval { $self->_board->over ? 'game_over' : $self->_resign($seat) };
Branch: 1 branch
BranchTrueFalseTotal
$self->_board->over ? : 1 13 14
203 14 ▶ return $@ ? 'no_such_seat' : $flag;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 14 14
204 }
205  
206 15 ▶sub _resign {
Subroutine _resign: called CC=7 SCAR=19.5
207 15 my ($self, $seat) = @_;
208 15 my $bd = $self->_board;
209 15 ▶ return 'no_such_seat' unless defined $seat && $seat =~ /\A[0-9]+\z/ && $seat < $self->seats;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats 7 8 15
Condition100%6/6
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats
!ll&&!rl&&r
528
defined $seat and $seat =~ /\A[0-9]+\z/u
!ll&&!rl&&r
1410
MC/DC100%3/3
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats
defined $seat $seat =~ /\A[0-9]+\z/u $seat < $self->seats
Truth table100%4/4
A and B and C
A= defined $seatB= $seat =~ /\A[0-9]+\z/uC= $seat < $self->seats
ABCresult
0XX0
10X0
1100
1111
210 8 ▶ return 'seat_finished' if $bd->finished($seat);
Branch: 1 branch
BranchTrueFalseTotal
if $bd->finished($seat) 1 7 8
211 7 my ($why, $undo) = $bd->resign($seat);
212 7 ▶ return 'seat_resigned' if $why == WHY_SEAT_DONE;
Branch: 1 branch
BranchTrueFalseTotal
if $why == 8 1 6 7
213 6 ▶ return 'no_such_seat' unless $why == PLAY_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $why == 0 0 6 6
214 6 return $self->_done($undo, "resign $seat");
215 }
216  
217 5648 ▶sub _done {
Subroutine _done: called CC=2 SCAR=6.9
218 5648 my ($self, $undo, $text, $mover) = @_;
219 5648 push @{ $self->_undo }, $undo;
220 5648 push @{ $self->_moves }, $text;
221 5648 push @{ $self->_movers }, $mover;
222 5648 ▶ push @{ $self->_keys->[$mover] }, $self->_board->own_key($mover) if defined $mover;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mover 5642 6 5648
223 5648 return undef;
224 }
225  
226 # A move as text, a hash of holes or names, or a pass or resignation. Answers
227 # the kind and its parts, or a flag naming what is wrong with it.
228 5672 ▶sub _parse {
Subroutine _parse: called CC=18 SCAR=29.0
229 5672 my ($move) = @_;
230 5672 ▶ return ('bad_string') unless defined $move;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $move 1 5671 5672
231 5671 ▶ if (ref $move) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $move) 4091 1580 5671
232 4091 ▶ return ('bad_string') unless ref $move eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $move eq "HASH" 3 4088 4091
233 4088 ▶ my $kind = $move->{kind} // 'move';
Condition100%2/2
$move->{"kind"} // "move"
l!l
407216
MC/DC100%1/1
$move->{"kind"} // "move"
$move->{"kind"}
Truth table100%2/2
A
A= $move->{"kind"}
Aresult
11
00
234 4088 ▶ return ('pass') if $kind eq 'pass';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "pass" 0 4088 4088
235 4088 ▶ return ('resign', undef, undef, undef, $move->{seat}) if $kind eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "resign" 1 4087 4088
236 4087 ▶ return ('bad_string') unless $kind eq 'move';
Branch: 1 branch
BranchTrueFalseTotal
unless $kind eq "move" 1 4086 4087
237 4086 my ($from, $to) = map { _hole($_) } $move->{from}, $move->{to};
238 4086 ▶ return ('no_such_hole') unless defined $from && defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from and defined $to 3 4083 4086
Condition66%2/3
defined $from and defined $to
!ll&&!rl&&r
304083
MC/DC50%1/2
defined $from and defined $to
defined $from defined $to
Truth table66%2/3
A and B
A= defined $fromB= defined $to
ABresult
0X0
100
111
239 4083 ▶ return ('bad_string') if $from == $to;
Branch: 1 branch
BranchTrueFalseTotal
if $from == $to 0 4083 4083
240 4083 return ('move', $from, $to);
241 }
242 1580 ▶ return ('bad_string') if length $move > 200;
Branch: 1 branch
BranchTrueFalseTotal
if length $move > 200 1 1579 1580
243 1579 my $m = Game::Sternhalma::Notation::parse_move($move);
244 1579 ▶ unless ($m) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($m) 9 1570 1579
245 9 ▶ return ('bad_string') unless $move =~ /\A[a-z][0-9]+(?:[-:][a-z][0-9]+)+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $move =~ /\A[a-z][0-9]+(?:[-:][a-z][0-9]+)+\z/u 8 1 9
246 1 my @names = split /[-:]/, $move;
247 1 ▶ return (grep { !defined Game::Sternhalma::Notation::hole_of($_) } @names) ? ('no_such_hole') : ('bad_string');
Branch: 1 branch
BranchTrueFalseTotal
grep({not defined Game::Sternhalma::Notation::hole_of($_);} @names) ? : 1 0 1
248 }
249 1570 ▶ return ('pass') if $m->{kind} eq 'pass';
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"kind"} eq "pass" 2 1568 1570
250 1568 ▶ return ('resign', undef, undef, undef, $m->{seat}) if $m->{kind} eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"kind"} eq "resign" 1 1567 1568
251 1567 my @h = @{ $m->{holes} };
252 1567 ▶ return ('move', $h[0], $h[-1], $m->{kind} eq 'chain' ? \@h : undef);
Branch: 1 branch
BranchTrueFalseTotal
$m->{'kind'} eq 'chain' ? : 868 699 1567
253 }
254  
255 8172 ▶sub _hole {
Subroutine _hole: called CC=5 SCAR=16.1
256 8172 my ($h) = @_;
257 8172 ▶ return undef unless defined $h && !ref $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h and not ref $h 4 8168 8172
Condition100%3/3
defined $h and not ref $h
!ll&&!rl&&r
228168
MC/DC100%2/2
defined $h and not ref $h
defined $h not ref $h
Truth table100%3/3
A and not(B)
A= defined $hB= not ref $h
ABresult
0X0
100
111
258 8168 ▶ return $h + 0 if $h =~ /\A[0-9]+\z/ && $h < HOLES;
Branch: 1 branch
BranchTrueFalseTotal
if $h =~ /\A[0-9]+\z/u and $h < 121 8165 3 8168
Condition100%3/3
$h =~ /\A[0-9]+\z/u and $h < 121
!ll&&!rl&&r
218165
MC/DC100%2/2
$h =~ /\A[0-9]+\z/u and $h < 121
$h =~ /\A[0-9]+\z/u $h < 121
Truth table100%3/3
A and B
A= $h =~ /\A[0-9]+\z/uB= $h < 121
ABresult
0X0
100
111
259 3 return Game::Sternhalma::Notation::hole_of($h);
260 }
261  
262 752 ▶sub undo {
Subroutine undo: called CC=3 SCAR=11.0
Pod documented
263 752 my ($self) = @_;
264 752 ▶ my $undo = pop @{ $self->_undo } or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $undo = pop @{$self->_undo;} or return 0 748 4 752
265 748 pop @{ $self->_moves };
266 748 my $mover = pop @{ $self->_movers };
267 748 ▶ pop @{ $self->_keys->[$mover] } if defined $mover;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mover 748 0 748
268 748 return $self->_board->unplay($undo);
269 }
270  
271 # ---- the log ---------------------------------------------------------------------------------
272  
273 233 ▶sub log {
Subroutine log: called CC=3 SCAR=11.0
Pod documented
274 233 my ($self) = @_;
275 233 ▶ return Game::Sternhalma::Notation::format_game({
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_start ? : 27 206 233
Condition100%2/2
$self->first // 0
l!l
20627
MC/DC100%1/1
$self->first // 0
$self->first
Truth table100%2/2
A
A= $self->first
Aresult
11
00
276 seats => $self->seats, pieces => $self->pieces, cap => $self->cap, first => $self->first // 0,
277 (defined $self->_start ? (start => $self->_start) : ()),
278 moves => [ $self->moves ],
279 });
280 }
281  
282 20 ▶sub replay {
Subroutine replay: called CC=5 SCAR=16.1
Pod documented
283 20 my ($class, $text) = @_;
284 20 my ($g, $why) = Game::Sternhalma::Notation::parse_game($text);
285 20 ▶ Game::Sternhalma::Error->throw(bad_log => $why) unless $g;
Branch: 1 branch
BranchTrueFalseTotal
unless $g 2 18 20
286 my $game = defined $g->{start}
287 ? $class->new(position => $g->{start}, cap => $g->{cap})
288 18 ▶ : $class->new(seats => $g->{seats}, pieces => $g->{pieces}, cap => $g->{cap}, first => $g->{first});
Branch: 1 branch
BranchTrueFalseTotal
defined $g->{'start'} ? : 4 14 18
289 18 my $n = 0;
290 18 for my $move (@{ $g->{moves} }) {
291 767 $n++;
292 767 my $flag = $game->play($move);
293 767 ▶ Game::Sternhalma::Error->throw(bad_log => "move $n, $move: " . $REASON{$flag}) if defined $flag;
Branch: 1 branch
BranchTrueFalseTotal
if defined $flag 1 766 767
294 }
295 17 return $game;
296 }
297  
298 30 1;
299  
300 __END__
« blib/lib/Game/Sternhalma/Bot.pm ↑ Summary blib/lib/Game/Sternhalma/Layout.pm »