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