| 1 | # Games::Checkers, Copyright (C) 1996-2012 Mikhael Goikhman, migo@cpan.org | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 5 | # the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package Games::Checkers::Move; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Games::Checkers::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub new ($$$$) { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 25 | 1 | my ($is_beat, $src, $dsts) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | die "Games::Checkers::Move constructor, third arg should be array" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | unless ref($dsts) eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | die "No destinations in Move construction" unless $src == NL || @$dsts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$src == &NL() or @$dsts
MC/DC0%0/2
$src == &NL() or @$dsts
$src == &NL()
@$dsts
Truth table33%1/3
A or B
A= $src == &NL()B= @$dsts
| |||||||||||||||||||||||||||||
| 30 | 1 | my $self = [ $is_beat, $src, [@$dsts] ]; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 33 | 1 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use constant NoMove => Games::Checkers::Move->new(0, NL, []); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub num_steps ($) { | ||||||||||||||||||||||||||
|
Subroutine
num_steps: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 0 | return scalar @{$self->[2]}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub is_beat ($) { | ||||||||||||||||||||||||||
|
Subroutine
is_beat: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | 0 | return $self->[0]; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub source ($) { | ||||||||||||||||||||||||||
|
Subroutine
source: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 0 | return $self->[1]; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub destin ($$) { | ||||||||||||||||||||||||||
|
Subroutine
destin: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 0 | my $num = shift; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | return $num < 0 || $num >= @{$self->[2]} ? NL : $self->[2]->[$num]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$num < 0 or $num >= @{$self->[2];}
MC/DC0%0/2
$num < 0 or $num >= @{$self->[2];}
$num < 0
$num >= @{$self->[2];}
Truth table0%0/3
A or B
A= $num < 0B= $num >= @{$self->[2];}
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub clone ($) { | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | return Games::Checkers::Move->new(@$self); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub dump ($$) { | ||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $board = shift || die; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || die()
MC/DC0%0/1
shift() || die()
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $delim = $self->is_beat ? $::RULES{CAPTURE_SEPARATOR} || ":" : "-"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$main::RULES{"CAPTURE_SEPARATOR"} or ":"
MC/DC0%0/1
$main::RULES{"CAPTURE_SEPARATOR"} or ":"
$main::RULES{"CAPTURE_SEPARATOR"}
Truth table0%0/2
A
A= $main::RULES{"CAPTURE_SEPARATOR"}
| |||||||||||||||||||||||||||||
| 69 | 0 | my $str = $board->loc_to_str($self->source); | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | for (my $i = 0; $i < $self->num_steps; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $str .= $delim . $board->loc_to_str($self->destin($i)); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | return $str; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | 1; | |||||||||||||||||||||||||||