| 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
MC/DC0%0/1
shift() || 8
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$tx >= 0 and $b->[$tx][$y] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 342820 | ▶ | if ($tx >= 0 && $tx != $x - 1 && $b->[$tx][$y] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me
$tx >= 0 and $tx != $x - 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$tx < $size and $b->[$tx][$y] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 325402 | ▶ | if ($tx < $size && $tx != $x + 1 && $b->[$tx][$y] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me
$tx < $size and $tx != $x + 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$ty >= 0 and $b->[$x][$ty] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 314940 | ▶ | if ($ty >= 0 && $ty != $y - 1 && $b->[$x][$ty] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me
$ty >= 0 and $ty != $y - 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$ty < $size and $b->[$x][$ty] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 299842 | ▶ | if ($ty < $size && $ty != $y + 1 && $b->[$x][$ty] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me
$ty < $size and $ty != $y + 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx >= 0 and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 37196 | $tx--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 37196 | $ty--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 280902 | ▶ | if ($tx >= 0 && $ty >= 0 && $tx != $x - 1 && $ty != $y - 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1
$tx >= 0 and $ty >= 0 and $tx != $x - 1
$tx >= 0 and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
$tx >= 0 and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 53430 | $tx--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 53430 | $ty++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 269470 | ▶ | if ($tx >= 0 && $ty < $size && $tx != $x - 1 && $ty != $y + 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1
$tx >= 0 and $ty < $size and $tx != $x - 1
$tx >= 0 and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
$tx < $size and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 30522 | $tx++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 30522 | $ty++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 256460 | ▶ | if ($tx < $size && $ty < $size && $tx != $x + 1 && $ty != $y + 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1
$tx < $size and $ty < $size and $tx != $x + 1
$tx < $size and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx < $size and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 33596 | $tx++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 33596 | $ty--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 248736 | ▶ | if ($tx < $size && $ty >= 0 && $tx != $x + 1 && $ty != $y - 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1
$tx < $size and $ty >= 0 and $tx != $x + 1
$tx < $size and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
@moves or $own_call
MC/DC100%2/2
@moves or $own_call
@moves
$own_call
Truth table100%3/3
A or B
A= @movesB= $own_call
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 50 | $self->player(3 - $self->player); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 50 | ▶ | if ($self->findmoves(1)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%3/9
$x < 0 or $x >= $size or $y < 0 or $y >= $size
$x < 0 or $x >= $size or $y < 0
$x < 0 or $x >= $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$tx >= 0 and $b->[$tx][$y] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 5574 | ▶ | if ($tx >= 0 && $tx != $x - 1 && $b->[$tx][$y] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$tx >= 0 and $tx != $x - 1 and $b->[$tx][$y] == $me
$tx >= 0 and $tx != $x - 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 794 | $tx = $x - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 794 | ▶ | while ($tx >= 0 && $b->[$tx][$y] == $not_me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tx >= 0 and $b->[$tx][$y] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$tx < $size and $b->[$tx][$y] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 5574 | ▶ | if ($tx < $size && $tx != $x + 1 && $b->[$tx][$y] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$tx < $size and $tx != $x + 1 and $b->[$tx][$y] == $me
$tx < $size and $tx != $x + 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 804 | $tx = $x + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 804 | ▶ | while ($tx < $size && $b->[$tx][$y] == $not_me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tx < $size and $b->[$tx][$y] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$ty >= 0 and $b->[$x][$ty] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 5574 | ▶ | if ($ty >= 0 && $ty != $y - 1 && $b->[$x][$ty] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$ty >= 0 and $ty != $y - 1 and $b->[$x][$ty] == $me
$ty >= 0 and $ty != $y - 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 942 | $ty = $y - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 942 | ▶ | while ($ty >= 0 && $b->[$x][$ty] == $not_me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ty >= 0 and $b->[$x][$ty] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$ty < $size and $b->[$x][$ty] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 5574 | ▶ | if ($ty < $size && $ty != $y + 1 && $b->[$x][$ty] == $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$ty < $size and $ty != $y + 1 and $b->[$x][$ty] == $me
$ty < $size and $ty != $y + 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1334 | $ty = $y + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1334 | ▶ | while ($ty < $size && $b->[$x][$ty] == $not_me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ty < $size and $b->[$x][$ty] == $not_me
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx >= 0 and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1612 | $tx--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1612 | $ty--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 5574 | ▶ | if ($tx >= 0 && $ty >= 0 && $tx != $x - 1 && $ty != $y - 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx >= 0 and $ty >= 0 and $tx != $x - 1 and $ty != $y - 1
$tx >= 0 and $ty >= 0 and $tx != $x - 1
$tx >= 0 and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
$tx >= 0 and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx >= 0 and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
$tx >= 0 and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 2328 | $tx--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2328 | $ty++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 5574 | ▶ | if ($tx >= 0 && $ty < $size && $tx != $x - 1 && $ty != $y + 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx >= 0 and $ty < $size and $tx != $x - 1 and $ty != $y + 1
$tx >= 0 and $ty < $size and $tx != $x - 1
$tx >= 0 and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
$tx >= 0 and $ty < $size and $b->[$tx][$ty] == $not_me
$tx >= 0 and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
$tx < $size and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 2580 | $tx++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 2580 | $ty++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 5574 | ▶ | if ($tx < $size && $ty < $size && $tx != $x + 1 && $ty != $y + 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1 and $b->[$tx][$ty] == $me
$tx < $size and $ty < $size and $tx != $x + 1 and $ty != $y + 1
$tx < $size and $ty < $size and $tx != $x + 1
$tx < $size and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
$tx < $size and $ty < $size and $b->[$tx][$ty] == $not_me
$tx < $size and $ty < $size
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx < $size and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1890 | $tx++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1890 | $ty--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 5574 | ▶ | if ($tx < $size && $ty >= 0 && $tx != $x + 1 && $ty != $y - 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1 and $b->[$tx][$ty] == $me
$tx < $size and $ty >= 0 and $tx != $x + 1 and $ty != $y - 1
$tx < $size and $ty >= 0 and $tx != $x + 1
$tx < $size and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
$tx < $size and $ty >= 0 and $b->[$tx][$ty] == $not_me
$tx < $size and $ty >= 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||