blib/lib/Games/AlphaBeta/Reversi.pm

filter: Statementstmt 98.5% 208 / 211 Branchbran 95.8% 92 / 96 Conditioncond 88.3% 235 / 266 MC/DCmcdc 80.9% 106 / 131 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 91.2% 655 / 718 CC 145 SCAR 42.3
CC
145
Cov
93%
apply
87.2
findmoves
59.0
init
5.0
CRAP 68.7
↑ Summary blib/lib/Games/AlphaBeta.pm »
1 package Games::AlphaBeta::Reversi;
2 3 ▶use base qw(Games::AlphaBeta::Position);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '0.1.5';
9  
10 =head1 NAME
11  
12 Games::AlphaBeta::Reversi - Reversi position class for use with
13 Games::AlphaBeta
14  
15 =head1 SYNOPSIS
16  
17 package My::Reversi;
18 use base qw(Games::AlphaBeta::Reversi);
19  
20 # implement drawing routine
21 sub draw { ... }
22  
23 package main;
24 use My::Reversi;
25 use Games::AlphaBeta;
26  
27 my ($p, $g);
28 $p = My::Reversi->new;
29 $g = Games::AlphaBeta->new($p);
30  
31 while ($p = $g->abmove) {
32 $p->draw;
33 }
34  
35 =head1 DESCRIPTION
36  
37 This module implements a position-object suitable for use with
38 L<Games::AlphaBeta>. It inherits from the
39 L<Games::AlphaBeta::Position> base class, so be sure to read its
40 documentation. The methods implemented there will not be
41 described here.
42  
43  
44 =head1 METHODS
45  
46 =over 4
47  
48 =item init()
49  
50 Initialize the initial state. Call SUPER::init(@_) to do part of
51 the work.
52  
53 =cut
54  
55 3 ▶sub init {
Subroutine init: called CC=5 SCAR=16.2
Pod documented
56 3 my $self = shift;
57  
58 3 ▶ my $size = shift || 8;
Condition50%1/2
shift() || 8
l!l
03
MC/DC0%0/1
shift() || 8
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
59 3 my $half = abs($size / 2);
60 3 my %config = (
61 player => 1,
62 size => $size,
63 board => undef,
64 );
65  
66 # Create a blank board
67 3 $size--;
68 3 for my $x (0 .. $size) {
69 24 for my $y (0 .. $size) {
70 192 $config{board}[$x][$y] = 0;
71 }
72 }
73  
74 # Put initial pieces on board
75 3 $config{board}[$size - $half][$size - $half] = 1;
76 3 $config{board}[$half][$half] = 1;
77 3 $config{board}[$size - $half][$half] = 2;
78 3 $config{board}[$half][$size - $half] = 2;
79  
80 3 @$self{keys %config} = values %config;
81  
82 3 ▶ $self->SUPER::init(@_) or croak "failed to call SUPER:init()";
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or croak("failed to call SUPER:init()") 3 0 3
83 3 return $self;
84 }
85  
86 =item as_string
87  
88 Return a plain-text representation of the current game position
89 as a string.
90  
91 =cut
92  
93 122 ▶sub as_string {
Subroutine as_string: called CC=4 SCAR=13.9
Pod documented
94 122 my $self = shift;
95  
96 # Header
97 122 my ($c, $str) = "a";
98 122 $str .= " " . $c++ for (1 .. $self->{size});
99 122 $str = sprintf(" %s\n", $str);
100 122 $str .= sprintf(" +%s\n", "--" x $self->{size});
101  
102 # Actual board (with numbers down the left side)
103 122 my $i;
104 122 for (@{$self->{board}}) {
105 976 for (join " ", @$_) {
106 976 tr/012/.ox/;
107 976 $str .= sprintf("%2d | %s\n", ++$i, $_);
108 }
109 }
110
111 # Footer
112 122 $str .= "Player " . $self->{player} . " to move.\n";
113 122 return $str;
114 }
115  
116  
117 =item findmoves [$own_call]
118  
119 Return an array of all legal moves at the current position for
120 the current player.
121  
122 If $own_call is true, we have been recursively called by ourself
123 to find out if the other player could move. If neither player can
124 move, return undef to denote this as an ending position.
125 Otherwise return a pass move.
126  
127 =cut
128  
129 10120 ▶sub findmoves {
Subroutine findmoves: called CC=59 SCAR=40.8
Pod documented
130 10120 my ($self, $own_call) = @_;
131  
132 10120 my $b = $self->{board};
133 10120 my $size = $self->{size};
134 10120 my @moves;
135  
136 10120 for my $x (0 .. $size - 1) {
137 80960 INNER: for my $y (0 .. $size - 1) {
138 647680 ▶ unless ($b->[$x][$y]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($b->[$x][$y]) 342820 304860 647680
139 # Define some convenient names.
140 342820 my $me = $self->{player};
141 342820 my $not_me = 3 - $me;
142  
143 342820 my ($tx, $ty);
144  
145 # Check left
146 342820 ▶ for ($tx = $x - 1; $tx >= 0 && $b->[$tx][$y] == $not_me; $tx--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $b->[$tx][$y] == $not_me) 59414 342820 402234
Condition100%3/3
$tx >= 0 and $b->[$tx][$y] == $not_me
!ll&&!rl&&r
5183429098659414
MC/DC100%2/2
$tx >= 0 and $b->[$tx][$y] == $not_me
$tx >= 0 $b->[$tx][$y] == $not_me
Truth table100%3/3
A and B
A= $tx >= 0B= $b->[$tx][$y] == $not_me
ABresult
0X0
100
111
147 ;
148 }
149 342820 ▶ if ($tx >= 0 && $tx != $x - 1 && $b->[$tx][$y] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me) 17418 325402 342820
Condition100%6/6
$tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me
!ll&&!rl&&r
316490891217418
$tx >= 0 and $tx != $x - 1
!ll&&!rl&&r
5183426465626330
MC/DC100%3/3
$tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me
$tx >= 0 $tx != $x - 1 $b->[$tx][$y] == $me
Truth table100%4/4
A and B and C
A= $tx >= 0B= $tx != $x - 1C= $b->[$tx][$y] == $me
ABCresult
0XX0
10X0
1100
1111
150 17418 push @moves, [$x, $y];
151 17418 next INNER;
152 }
153  
154 # Check right
155 325402 ▶ for ($tx = $x + 1; $tx < $size && $b->[$tx][$y] == $not_me; $tx++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $b->[$tx][$y] == $not_me) 34930 325402 360332
Condition100%3/3
$tx < $size and $b->[$tx][$y] == $not_me
!ll&&!rl&&r
6226426313834930
MC/DC100%2/2
$tx < $size and $b->[$tx][$y] == $not_me
$tx < $size $b->[$tx][$y] == $not_me
Truth table100%3/3
A and B
A= $tx < $sizeB= $b->[$tx][$y] == $not_me
ABresult
0X0
100
111
156 ;
157 }
158 325402 ▶ if ($tx < $size && $tx != $x + 1 && $b->[$tx][$y] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me) 10462 314940 325402
Condition100%6/6
$tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me
!ll&&!rl&&r
306268867210462
$tx < $size and $tx != $x + 1
!ll&&!rl&&r
6226424400419134
MC/DC100%3/3
$tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me
$tx < $size $tx != $x + 1 $b->[$tx][$y] == $me
Truth table100%4/4
A and B and C
A= $tx < $sizeB= $tx != $x + 1C= $b->[$tx][$y] == $me
ABCresult
0XX0
10X0
1100
1111
159 10462 push @moves, [$x, $y];
160 10462 next INNER;
161 }
162  
163 # Check up
164 314940 ▶ for ($ty = $y - 1; $ty >= 0 && $b->[$x][$ty] == $not_me; $ty--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty >= 0 and $b->[$x][$ty] == $not_me) 42622 314940 357562
Condition100%3/3
$ty >= 0 and $b->[$x][$ty] == $not_me
!ll&&!rl&&r
7456424037642622
MC/DC100%2/2
$ty >= 0 and $b->[$x][$ty] == $not_me
$ty >= 0 $b->[$x][$ty] == $not_me
Truth table100%3/3
A and B
A= $ty >= 0B= $b->[$x][$ty] == $not_me
ABresult
0X0
100
111
165 ;
166 }
167 314940 ▶ if ($ty >= 0 && $ty != $y - 1 && $b->[$x][$ty] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me) 15098 299842 314940
Condition100%6/6
$ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me
!ll&&!rl&&r
292192765015098
$ty >= 0 and $ty != $y - 1
!ll&&!rl&&r
7456421762822748
MC/DC100%3/3
$ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me
$ty >= 0 $ty != $y - 1 $b->[$x][$ty] == $me
Truth table100%4/4
A and B and C
A= $ty >= 0B= $ty != $y - 1C= $b->[$x][$ty] == $me
ABCresult
0XX0
10X0
1100
1111
168 15098 push @moves, [$x, $y];
169 15098 next INNER;
170 }
171  
172 # Check down
173 299842 ▶ for ($ty = $y + 1; $ty < $size && $b->[$x][$ty] == $not_me; $ty++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty < $size and $b->[$x][$ty] == $not_me) 58244 299842 358086
Condition100%3/3
$ty < $size and $b->[$x][$ty] == $not_me
!ll&&!rl&&r
5614424369858244
MC/DC100%2/2
$ty < $size and $b->[$x][$ty] == $not_me
$ty < $size $b->[$x][$ty] == $not_me
Truth table100%3/3
A and B
A= $ty < $sizeB= $b->[$x][$ty] == $not_me
ABresult
0X0
100
111
174 ;
175 }
176 299842 ▶ if ($ty < $size && $ty != $y + 1 && $b->[$x][$ty] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me) 18940 280902 299842
Condition100%6/6
$ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me
!ll&&!rl&&r
273018788418940
$ty < $size and $ty != $y + 1
!ll&&!rl&&r
5614421687426824
MC/DC100%3/3
$ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me
$ty < $size $ty != $y + 1 $b->[$x][$ty] == $me
Truth table100%4/4
A and B and C
A= $ty < $sizeB= $ty != $y + 1C= $b->[$x][$ty] == $me
ABCresult
0XX0
10X0
1100
1111
177 18940 push @moves, [$x, $y];
178 18940 next INNER;
179 }
180  
181 # Check up/left
182 280902 $tx = $x - 1;
183 280902 $ty = $y - 1;
184 280902 ▶ while ($tx >= 0 && $ty >= 0 && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me) 37196 280902 318098
Condition100%6/6
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
10825817264437196
$tx >= 0 and $ty >= 0
!ll&&!rl&&r
4552262736209840
MC/DC100%3/3
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx >= 0 $ty >= 0 $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx >= 0B= $ty >= 0C= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
185 37196 $tx--;
186 37196 $ty--;
187 }
188 280902 ▶ if ($tx >= 0 && $ty >= 0 && $tx != $x - 1 && $ty != $y - 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me) 11432 269470 280902
Condition91%11/12
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
261282818811432
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1
!ll&&!rl&&r
261282019620
$tx >= 0 and $ty >= 0 and $tx != $x - 1
!ll&&!rl&&r
10825815302419620
$tx >= 0 and $ty >= 0
!ll&&!rl&&r
4552262736172644
MC/DC80%4/5
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx >= 0 $ty >= 0 $tx != $x - 1 $ty != $y - 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx >= 0B= $ty >= 0C= $tx != $x - 1D= $ty != $y - 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
189 $b->[$tx][$ty] == $me) {
190 11432 push @moves, [$x, $y];
191 11432 next INNER;
192 }
193  
194  
195 # Check up/right
196 269470 $tx = $x - 1;
197 269470 $ty = $y + 1;
198 269470 ▶ while ($tx >= 0 && $ty < $size && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me) 53430 269470 322900
Condition100%6/6
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
9414817532253430
$tx >= 0 and $ty < $size
!ll&&!rl&&r
5104443104228752
MC/DC100%3/3
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
$tx >= 0 $ty < $size $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx >= 0B= $ty < $sizeC= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
199 53430 $tx--;
200 53430 $ty++;
201 }
202 269470 ▶ if ($tx >= 0 && $ty < $size && $tx != $x - 1 && $ty != $y + 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me) 13010 256460 269470
Condition91%11/12
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
247480898013010
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1
!ll&&!rl&&r
247480021990
$tx >= 0 and $ty < $size and $tx != $x - 1
!ll&&!rl&&r
9414815333221990
$tx >= 0 and $ty < $size
!ll&&!rl&&r
5104443104175322
MC/DC80%4/5
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx >= 0 $ty < $size $tx != $x - 1 $ty != $y + 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx >= 0B= $ty < $sizeC= $tx != $x - 1D= $ty != $y + 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
203 $b->[$tx][$ty] == $me) {
204 13010 push @moves, [$x, $y];
205 13010 next INNER;
206 }
207  
208 # Check down/right
209 256460 $tx = $x + 1;
210 256460 $ty = $y + 1;
211 256460 ▶ while ($tx < $size && $ty < $size && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me) 30522 256460 286982
Condition100%6/6
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
9850215795830522
$tx < $size and $ty < $size
!ll&&!rl&&r
5370244800188480
MC/DC100%3/3
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
$tx < $size $ty < $size $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx < $sizeB= $ty < $sizeC= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
212 30522 $tx++;
213 30522 $ty++;
214 }
215 256460 ▶ if ($tx < $size && $ty < $size && $tx != $x + 1 && $ty != $y + 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me) 7724 248736 256460
Condition91%11/12
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
24191668207724
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1
!ll&&!rl&&r
241916014544
$tx < $size and $ty < $size and $tx != $x + 1
!ll&&!rl&&r
9850214341414544
$tx < $size and $ty < $size
!ll&&!rl&&r
5370244800157958
MC/DC80%4/5
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx < $size $ty < $size $tx != $x + 1 $ty != $y + 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx < $sizeB= $ty < $sizeC= $tx != $x + 1D= $ty != $y + 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
216 $b->[$tx][$ty] == $me) {
217 7724 push @moves, [$x, $y];
218 7724 next INNER;
219 }
220  
221 # Check down/left
222 248736 $tx = $x + 1;
223 248736 $ty = $y - 1;
224 248736 ▶ while ($tx < $size && $ty >= 0 && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me) 33596 248736 282332
Condition100%6/6
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
10897213976433596
$tx < $size and $ty >= 0
!ll&&!rl&&r
5371655256173360
MC/DC100%3/3
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx < $size $ty >= 0 $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx < $sizeB= $ty >= 0C= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
225 33596 $tx++;
226 33596 $ty--;
227 }
228 248736 ▶ if ($tx < $size && $ty >= 0 && $tx != $x + 1 && $ty != $y - 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me) 9472 239264 248736
Condition91%11/12
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
23163476309472
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1
!ll&&!rl&&r
231634017102
$tx < $size and $ty >= 0 and $tx != $x + 1
!ll&&!rl&&r
10897212266217102
$tx < $size and $ty >= 0
!ll&&!rl&&r
5371655256139764
MC/DC80%4/5
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx < $size $ty >= 0 $tx != $x + 1 $ty != $y - 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx < $sizeB= $ty >= 0C= $tx != $x + 1D= $ty != $y - 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
229 $b->[$tx][$ty] == $me) {
230 9472 push @moves, [$x, $y];
231 9472 next INNER;
232 }
233 }
234 }
235 }
236  
237 # If current player cannot move, check if other player can
238 # move. If she can't, the game is over. If she can, let the
239 # current player do a pass move.
240 10120 ▶ unless (@moves || $own_call) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@moves or $own_call) 50 10070 10120
Condition100%3/3
@moves or $own_call
l!l&&r!l&&!r
100541650
MC/DC100%2/2
@moves or $own_call
@moves $own_call
Truth table100%3/3
A or B
A= @movesB= $own_call
ABresult
1X1
011
000
241 50 $self->player(3 - $self->player);
242 50 ▶ if ($self->findmoves(1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->findmoves(1)) 34 16 50
243 34 @moves = undef;
244 }
245 50 $self->player(3 - $self->player);
246 }
247  
248 10120 return @moves;
249 }
250  
251  
252 =item evaluate
253  
254 Evaluate a game position and return its fitness value.
255  
256 =cut
257  
258 4482 ▶sub evaluate {
Subroutine evaluate: called CC=1 SCAR=0.0
Pod documented
259 4482 my $self = shift;
260 4482 my $player = $self->{player};
261 4482 my ($me, $not_me);
262  
263 4482 $me = scalar $self->findmoves;
264 4482 $self->{player} = 3 - $player;
265 4482 $not_me = scalar $self->findmoves;
266 4482 $self->{player} = $player;
267  
268 4482 return $me - $not_me;
269 }
270  
271  
272 =item apply $move
273  
274 Apply a move to the current position, transforming it into the
275 next position. Return reference to itself on succes, undef on
276 error.
277  
278 =cut
279  
280 5584 ▶sub apply ($) {
Subroutine apply: called CC=80 SCAR=44.7
Pod documented
281 5584 my ($self, $move) = @_;
282  
283 5584 my $me = $self->{player};
284 5584 my $not_me = 3 - $self->{player};
285  
286 # null or pass move
287 5584 ▶ unless ($move) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($move) 10 5574 5584
288 10 $self->{player} = $not_me;
289 10 return $self;
290 }
291  
292 5574 my $size = $self->{size};
293 5574 my $b = $self->{board};
294 5574 my ($x, $y) = @$move;
295  
296 5574 my ($tx, $ty, $flipped);
297  
298 # slot must not be outside the board, or already occupied
299 5574 ▶ if ($x < 0 || $x >= $size || $y < 0 || $y >= $size) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x < 0 or $x >= $size or $y < 0 or $y >= $size) { } 0 5574 5574
elsif ($b->[$x][$y]) { } 0 5574 5574
Condition33%3/9
$x < 0 or $x >= $size or $y < 0 or $y >= $size
l!l&&r!l&&!r
005574
$x < 0 or $x >= $size or $y < 0
l!l&&r!l&&!r
005574
$x < 0 or $x >= $size
l!l&&r!l&&!r
005574
MC/DC0%0/4
$x < 0 or $x >= $size or $y < 0 or $y >= $size
$x < 0 $x >= $size $y < 0 $y >= $size
Truth table20%1/5
A or B or C or D
A= $x < 0B= $x >= $sizeC= $y < 0D= $y >= $size
ABCDresult
1XXX1
01XX1
001X1
00011
00000
300 0 return undef;
301 }
302 elsif ($b->[$x][$y]) {
303 0 return undef;
304 }
305  
306 # left
307 5574 ▶ for ($tx = $x - 1; $tx >= 0 && $b->[$tx][$y] == $not_me; $tx--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $b->[$tx][$y] == $not_me) 2586 5574 8160
Condition100%3/3
$tx >= 0 and $b->[$tx][$y] == $not_me
!ll&&!rl&&r
91846562586
MC/DC100%2/2
$tx >= 0 and $b->[$tx][$y] == $not_me
$tx >= 0 $b->[$tx][$y] == $not_me
Truth table100%3/3
A and B
A= $tx >= 0B= $b->[$tx][$y] == $not_me
ABresult
0X0
100
111
308 ;
309 }
310 5574 ▶ if ($tx >= 0 && $tx != $x - 1 && $b->[$tx][$y] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me) 794 4780 5574
Condition100%6/6
$tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me
!ll&&!rl&&r
4624156794
$tx >= 0 and $tx != $x - 1
!ll&&!rl&&r
9183706950
MC/DC100%3/3
$tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me
$tx >= 0 $tx != $x - 1 $b->[$tx][$y] == $me
Truth table100%4/4
A and B and C
A= $tx >= 0B= $tx != $x - 1C= $b->[$tx][$y] == $me
ABCresult
0XX0
10X0
1100
1111
311 794 $tx = $x - 1;
312 794 ▶ while ($tx >= 0 && $b->[$tx][$y] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $b->[$tx][$y] == $not_me) 1432 794 2226
Condition66%2/3
$tx >= 0 and $b->[$tx][$y] == $not_me
!ll&&!rl&&r
07941432
MC/DC50%1/2
$tx >= 0 and $b->[$tx][$y] == $not_me
$tx >= 0 $b->[$tx][$y] == $not_me
Truth table66%2/3
A and B
A= $tx >= 0B= $b->[$tx][$y] == $not_me
ABresult
0X0
100
111
313 1432 $b->[$tx][$y] = $me;
314 1432 $tx--;
315 }
316 794 $flipped++;
317 }
318  
319 # right
320 5574 ▶ for ($tx = $x + 1; $tx < $size && $b->[$tx][$y] == $not_me; $tx++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $b->[$tx][$y] == $not_me) 2128 5574 7702
Condition100%3/3
$tx < $size and $b->[$tx][$y] == $not_me
!ll&&!rl&&r
60449702128
MC/DC100%2/2
$tx < $size and $b->[$tx][$y] == $not_me
$tx < $size $b->[$tx][$y] == $not_me
Truth table100%3/3
A and B
A= $tx < $sizeB= $b->[$tx][$y] == $not_me
ABresult
0X0
100
111
321 ;
322 }
323 5574 ▶ if ($tx < $size && $tx != $x + 1 && $b->[$tx][$y] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me) 804 4770 5574
Condition100%6/6
$tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me
!ll&&!rl&&r
4492278804
$tx < $size and $tx != $x + 1
!ll&&!rl&&r
60438881082
MC/DC100%3/3
$tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me
$tx < $size $tx != $x + 1 $b->[$tx][$y] == $me
Truth table100%4/4
A and B and C
A= $tx < $sizeB= $tx != $x + 1C= $b->[$tx][$y] == $me
ABCresult
0XX0
10X0
1100
1111
324 804 $tx = $x + 1;
325 804 ▶ while ($tx < $size && $b->[$tx][$y] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $b->[$tx][$y] == $not_me) 1622 804 2426
Condition66%2/3
$tx < $size and $b->[$tx][$y] == $not_me
!ll&&!rl&&r
08041622
MC/DC50%1/2
$tx < $size and $b->[$tx][$y] == $not_me
$tx < $size $b->[$tx][$y] == $not_me
Truth table66%2/3
A and B
A= $tx < $sizeB= $b->[$tx][$y] == $not_me
ABresult
0X0
100
111
326 1622 $b->[$tx][$y] = $me;
327 1622 $tx++;
328 }
329 804 $flipped++;
330 }
331  
332 # up
333 5574 ▶ for ($ty = $y - 1; $ty >= 0 && $b->[$x][$ty] == $not_me; $ty--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty >= 0 and $b->[$x][$ty] == $not_me) 2186 5574 7760
Condition100%3/3
$ty >= 0 and $b->[$x][$ty] == $not_me
!ll&&!rl&&r
73848362186
MC/DC100%2/2
$ty >= 0 and $b->[$x][$ty] == $not_me
$ty >= 0 $b->[$x][$ty] == $not_me
Truth table100%3/3
A and B
A= $ty >= 0B= $b->[$x][$ty] == $not_me
ABresult
0X0
100
111
334 ;
335 }
336 5574 ▶ if ($ty >= 0 && $ty != $y - 1 && $b->[$x][$ty] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me) 942 4632 5574
Condition100%6/6
$ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me
!ll&&!rl&&r
4254378942
$ty >= 0 and $ty != $y - 1
!ll&&!rl&&r
73835161320
MC/DC100%3/3
$ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me
$ty >= 0 $ty != $y - 1 $b->[$x][$ty] == $me
Truth table100%4/4
A and B and C
A= $ty >= 0B= $ty != $y - 1C= $b->[$x][$ty] == $me
ABCresult
0XX0
10X0
1100
1111
337 942 $ty = $y - 1;
338 942 ▶ while ($ty >= 0 && $b->[$x][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty >= 0 and $b->[$x][$ty] == $not_me) 1334 942 2276
Condition66%2/3
$ty >= 0 and $b->[$x][$ty] == $not_me
!ll&&!rl&&r
09421334
MC/DC50%1/2
$ty >= 0 and $b->[$x][$ty] == $not_me
$ty >= 0 $b->[$x][$ty] == $not_me
Truth table66%2/3
A and B
A= $ty >= 0B= $b->[$x][$ty] == $not_me
ABresult
0X0
100
111
339 1334 $b->[$x][$ty] = $me;
340 1334 $ty--;
341 }
342 942 $flipped++;
343 }
344
345 # down
346 5574 ▶ for ($ty = $y + 1; $ty < $size && $b->[$x][$ty] == $not_me; $ty++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty < $size and $b->[$x][$ty] == $not_me) 3488 5574 9062
Condition100%3/3
$ty < $size and $b->[$x][$ty] == $not_me
!ll&&!rl&&r
73648383488
MC/DC100%2/2
$ty < $size and $b->[$x][$ty] == $not_me
$ty < $size $b->[$x][$ty] == $not_me
Truth table100%3/3
A and B
A= $ty < $sizeB= $b->[$x][$ty] == $not_me
ABresult
0X0
100
111
347 ;
348 }
349 5574 ▶ if ($ty < $size && $ty != $y + 1 && $b->[$x][$ty] == $me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me) 1334 4240 5574
Condition100%6/6
$ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me
!ll&&!rl&&r
39083321334
$ty < $size and $ty != $y + 1
!ll&&!rl&&r
73631721666
MC/DC100%3/3
$ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me
$ty < $size $ty != $y + 1 $b->[$x][$ty] == $me
Truth table100%4/4
A and B and C
A= $ty < $sizeB= $ty != $y + 1C= $b->[$x][$ty] == $me
ABCresult
0XX0
10X0
1100
1111
350 1334 $ty = $y + 1;
351 1334 ▶ while ($ty < $size && $b->[$x][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ty < $size and $b->[$x][$ty] == $not_me) 2504 1334 3838
Condition66%2/3
$ty < $size and $b->[$x][$ty] == $not_me
!ll&&!rl&&r
013342504
MC/DC50%1/2
$ty < $size and $b->[$x][$ty] == $not_me
$ty < $size $b->[$x][$ty] == $not_me
Truth table66%2/3
A and B
A= $ty < $sizeB= $b->[$x][$ty] == $not_me
ABresult
0X0
100
111
352 2504 $b->[$x][$ty] = $me;
353 2504 $ty++;
354 }
355 1334 $flipped++;
356 }
357
358 # up/left
359 5574 $tx = $x - 1;
360 5574 $ty = $y - 1;
361 5574 ▶ while ($tx >= 0 && $ty >= 0 && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me) 1612 5574 7186
Condition100%6/6
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
128242921612
$tx >= 0 and $ty >= 0
!ll&&!rl&&r
7445385904
MC/DC100%3/3
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx >= 0 $ty >= 0 $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx >= 0B= $ty >= 0C= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
362 1612 $tx--;
363 1612 $ty--;
364 }
365 5574 ▶ if ($tx >= 0 && $ty >= 0 && $tx != $x - 1 && $ty != $y - 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me) 690 4884 5574
Condition91%11/12
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
4718166690
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1
!ll&&!rl&&r
47180856
$tx >= 0 and $ty >= 0 and $tx != $x - 1
!ll&&!rl&&r
12823436856
$tx >= 0 and $ty >= 0
!ll&&!rl&&r
7445384292
MC/DC80%4/5
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx >= 0 $ty >= 0 $tx != $x - 1 $ty != $y - 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx >= 0B= $ty >= 0C= $tx != $x - 1D= $ty != $y - 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
366 $b->[$tx][$ty] == $me) {
367 690 $tx = $x - 1;
368 690 $ty = $y - 1;
369 690 ▶ while ($tx >= 0 && $ty >= 0 && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me) 1148 690 1838
Condition50%3/6
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
06901148
$tx >= 0 and $ty >= 0
!ll&&!rl&&r
001838
MC/DC33%1/3
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx >= 0 $ty >= 0 $b->[$tx][$ty] == $not_me
Truth table50%2/4
A and B and C
A= $tx >= 0B= $ty >= 0C= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
370 1148 $b->[$tx][$ty] = $me;
371 1148 $tx--;
372 1148 $ty--;
373 }
374 690 $flipped++;
375 }
376  
377 # up/right
378 5574 $tx = $x - 1;
379 5574 $ty = $y + 1;
380 5574 ▶ while ($tx >= 0 && $ty < $size && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me) 2328 5574 7902
Condition100%6/6
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
152040542328
$tx >= 0 and $ty < $size
!ll&&!rl&&r
8466746382
MC/DC100%3/3
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
$tx >= 0 $ty < $size $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx >= 0B= $ty < $sizeC= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
381 2328 $tx--;
382 2328 $ty++;
383 }
384 5574 ▶ if ($tx >= 0 && $ty < $size && $tx != $x - 1 && $ty != $y + 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me) 1140 4434 5574
Condition91%11/12
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
42481861140
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1
!ll&&!rl&&r
424801326
$tx >= 0 and $ty < $size and $tx != $x - 1
!ll&&!rl&&r
152027281326
$tx >= 0 and $ty < $size
!ll&&!rl&&r
8466744054
MC/DC80%4/5
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx >= 0 $ty < $size $tx != $x - 1 $ty != $y + 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx >= 0B= $ty < $sizeC= $tx != $x - 1D= $ty != $y + 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
385 $b->[$tx][$ty] == $me) {
386 1140 $tx = $x - 1;
387 1140 $ty = $y + 1;
388 1140 ▶ while ($tx >= 0 && $ty < $size && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me) 1552 1140 2692
Condition50%3/6
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
011401552
$tx >= 0 and $ty < $size
!ll&&!rl&&r
002692
MC/DC33%1/3
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
$tx >= 0 $ty < $size $b->[$tx][$ty] == $not_me
Truth table50%2/4
A and B and C
A= $tx >= 0B= $ty < $sizeC= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
389 1552 $b->[$tx][$ty] = $me;
390 1552 $tx--;
391 1552 $ty++;
392 }
393 1140 $flipped++;
394 }
395
396 # down/right
397 5574 $tx = $x + 1;
398 5574 $ty = $y + 1;
399 5574 ▶ while ($tx < $size && $ty < $size && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me) 2580 5574 8154
Condition100%6/6
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
131042642580
$tx < $size and $ty < $size
!ll&&!rl&&r
7145966844
MC/DC100%3/3
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
$tx < $size $ty < $size $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx < $sizeB= $ty < $sizeC= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
400 2580 $tx++;
401 2580 $ty++;
402 }
403 5574 ▶ if ($tx < $size && $ty < $size && $tx != $x + 1 && $ty != $y + 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me) 934 4640 5574
Condition91%11/12
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
4320320934
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1
!ll&&!rl&&r
432001254
$tx < $size and $ty < $size and $tx != $x + 1
!ll&&!rl&&r
131030101254
$tx < $size and $ty < $size
!ll&&!rl&&r
7145964264
MC/DC80%4/5
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx < $size $ty < $size $tx != $x + 1 $ty != $y + 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx < $sizeB= $ty < $sizeC= $tx != $x + 1D= $ty != $y + 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
404 $b->[$tx][$ty] == $me) {
405 934 $tx = $x + 1;
406 934 $ty = $y + 1;
407 934 ▶ while ($tx < $size && $ty < $size && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me) 1608 934 2542
Condition50%3/6
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
09341608
$tx < $size and $ty < $size
!ll&&!rl&&r
002542
MC/DC33%1/3
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
$tx < $size $ty < $size $b->[$tx][$ty] == $not_me
Truth table50%2/4
A and B and C
A= $tx < $sizeB= $ty < $sizeC= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
408 1608 $b->[$tx][$ty] = $me;
409 1608 $tx++;
410 1608 $ty++;
411 }
412 934 $flipped++;
413 }
414  
415 # down/left
416 5574 $tx = $x + 1;
417 5574 $ty = $y - 1;
418 5574 ▶ while ($tx < $size && $ty >= 0 && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me) 1890 5574 7464
Condition100%6/6
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
133442401890
$tx < $size and $ty >= 0
!ll&&!rl&&r
6466886130
MC/DC100%3/3
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx < $size $ty >= 0 $b->[$tx][$ty] == $not_me
Truth table100%4/4
A and B and C
A= $tx < $sizeB= $ty >= 0C= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
419 1890 $tx++;
420 1890 $ty--;
421 }
422 5574 ▶ if ($tx < $size && $ty >= 0 && $tx != $x + 1 && $ty != $y - 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me) 860 4714 5574
Condition91%11/12
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
!ll&&!rl&&r
4394320860
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1
!ll&&!rl&&r
439401180
$tx < $size and $ty >= 0 and $tx != $x + 1
!ll&&!rl&&r
133430601180
$tx < $size and $ty >= 0
!ll&&!rl&&r
6466884240
MC/DC80%4/5
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx < $size $ty >= 0 $tx != $x + 1 $ty != $y - 1 $b->[$tx][$ty] == $me
Truth table83%5/6
A and B and C and D and E
A= $tx < $sizeB= $ty >= 0C= $tx != $x + 1D= $ty != $y - 1E= $b->[$tx][$ty] == $me
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
423 $b->[$tx][$ty] == $me) {
424 860 $tx = $x + 1;
425 860 $ty = $y - 1;
426 860 ▶ while ($tx < $size && $ty >= 0 && $b->[$tx][$ty] == $not_me) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me) 1160 860 2020
Condition50%3/6
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
!ll&&!rl&&r
08601160
$tx < $size and $ty >= 0
!ll&&!rl&&r
002020
MC/DC33%1/3
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx < $size $ty >= 0 $b->[$tx][$ty] == $not_me
Truth table50%2/4
A and B and C
A= $tx < $sizeB= $ty >= 0C= $b->[$tx][$ty] == $not_me
ABCresult
0XX0
10X0
1100
1111
427 1160 $b->[$tx][$ty] = $me;
428 1160 $tx++;
429 1160 $ty--;
430 }
431 860 $flipped++;
432 }
433  
434 5574 ▶ unless ($flipped) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flipped) 0 5574 5574
435 0 return undef;
436 }
437  
438 5574 $b->[$x][$y] = $me;
439 5574 $self->{player} = $not_me;
440  
441 5574 return $self;
442 }
443  
444 =back
445  
446 =head1 BUGS
447  
448 The C<findmoves()> method is too slow. This method is critical to
449 performance when running under Games::AlphaBeta, as more than 60%
450 of the execution time is spent there (when searching to ply 3).
451 Both the C<evaluate()> and C<endpos()> routines use
452 C<findmoves()> internally, so by speeding this routine up we
453 could gain a lot of speed.
454  
455  
456 =head1 SEE ALSO
457  
458 The author's website, describing this and other projects:
459 L<http://brautaset.org/projects/>
460  
461  
462 =head1 AUTHOR
463  
464 Stig Brautaset, E<lt>stig@brautaset.orgE<gt>
465  
466 =head1 COPYRIGHT AND LICENCE
467  
468 Copyright (C) 2004 by Stig Brautaset
469  
470 This library is free software; you can redistribute it and/or modify
471 it under the same terms as Perl itself, either Perl version 5.8.3 or,
472 at your option, any later version of Perl 5 you may have available.
473  
474 =cut
475  
476 # vim: shiftwidth=4 tabstop=4 softtabstop=4 expandtab
↑ Summary blib/lib/Games/AlphaBeta.pm »