line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 . |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
17
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Games::Checkers::Move; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
4
|
use Games::Checkers::Constants; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new ($$$$) { |
24
|
1
|
|
|
1
|
0
|
2
|
my $class = shift; |
25
|
1
|
|
|
|
|
2
|
my ($is_beat, $src, $dsts) = @_; |
26
|
|
|
|
|
|
|
|
27
|
1
|
50
|
|
|
|
31
|
die "Games::Checkers::Move constructor, third arg should be array" |
28
|
|
|
|
|
|
|
unless ref($dsts) eq 'ARRAY'; |
29
|
1
|
50
|
33
|
|
|
21
|
die "No destinations in Move construction" unless $src == NL || @$dsts; |
30
|
1
|
|
|
|
|
3
|
my $self = [ $is_beat, $src, [@$dsts] ]; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
2
|
bless $self, $class; |
33
|
1
|
|
|
|
|
306
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
6
|
use constant NoMove => Games::Checkers::Move->new(0, NL, []); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub num_steps ($) { |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
return scalar @{$self->[2]}; |
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub is_beat ($) { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
return $self->[0]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub source ($) { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
return $self->[1]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub destin ($$) { |
54
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my $num = shift; |
56
|
0
|
0
|
0
|
|
|
|
return $num < 0 || $num >= @{$self->[2]} ? NL : $self->[2]->[$num]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub clone ($) { |
60
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
61
|
0
|
|
|
|
|
|
return Games::Checkers::Move->new(@$self); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub dump ($$) { |
65
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
66
|
0
|
|
0
|
|
|
|
my $board = shift || die; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
0
|
|
|
|
my $delim = $self->is_beat ? $::RULES{CAPTURE_SEPARATOR} || ":" : "-"; |
69
|
0
|
|
|
|
|
|
my $str = $board->loc_to_str($self->source); |
70
|
0
|
|
|
|
|
|
for (my $i = 0; $i < $self->num_steps; $i++) { |
71
|
0
|
|
|
|
|
|
$str .= $delim . $board->loc_to_str($self->destin($i)); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $str; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |