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
|
|
|
|
|
28
|
|
17
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Games::Checkers::ExpandMoveList; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
5
|
use base 'Games::Checkers::MoveLocationConstructor'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
546
|
|
22
|
1
|
|
|
1
|
|
5
|
use Games::Checkers::Constants; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
23
|
1
|
|
|
1
|
|
6
|
use Games::Checkers::IteratorConstants; |
|
1
|
|
|
|
|
81
|
|
|
1
|
|
|
|
|
8
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new ($$$) { |
26
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
27
|
0
|
|
|
|
|
|
my $board = shift; |
28
|
0
|
|
|
|
|
|
my $color = shift; |
29
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($board, $color); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$self->{figure_iterator} = |
32
|
|
|
|
|
|
|
new Games::Checkers::FigureIterator($board, $color); |
33
|
0
|
|
|
|
|
|
$self->{status} = Ok; |
34
|
0
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub status ($) { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
return $self->{status}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub build ($) { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
while ($self->{figure_iterator}->left) { |
45
|
0
|
0
|
|
|
|
|
if ($self->source($self->{figure_iterator}->next) == Ok) { |
46
|
0
|
|
|
|
|
|
$self->build_continue; |
47
|
0
|
0
|
|
|
|
|
return if $self->{status} == Err; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub build_continue ($) { |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $iterator_class = "Games::Checkers::"; |
56
|
0
|
|
|
|
|
|
$iterator_class .= (qw(PawnStepIterator PawnBeatIterator KingStepIterator KingBeatIterator)) |
57
|
|
|
|
|
|
|
[($self->{piece} == King) * 2 + $self->{must_beat}]; |
58
|
0
|
|
|
|
|
|
my $rule_iterator = $iterator_class->new($self->dst_1, $self->{color}); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# if (type == Pawn && must_beat) rule_iterator = &pawn_beat_iterator; |
61
|
|
|
|
|
|
|
# if (type == Pawn && !must_beat) rule_iterator = &pawn_step_iterator; |
62
|
|
|
|
|
|
|
# if (type == King && must_beat) rule_iterator = &king_beat_iterator; |
63
|
|
|
|
|
|
|
# if (type == King && !must_beat) rule_iterator = &king_step_iterator; |
64
|
|
|
|
|
|
|
# rule_iterator->init(dst_1(), color); |
65
|
|
|
|
|
|
|
# if (type == Pawn && !must_beat) rule_iterator = new PawnStepIterator(dst_1(), color); |
66
|
|
|
|
|
|
|
# if (type == Pawn && must_beat) rule_iterator = new PawnBeatIterator(dst_1(), color); |
67
|
|
|
|
|
|
|
# if (type == King && !must_beat) rule_iterator = new KingStepIterator(dst_1(), color); |
68
|
|
|
|
|
|
|
# if (type == King && must_beat) rule_iterator = new KingBeatIterator(dst_1(), color); |
69
|
|
|
|
|
|
|
# if (type == King && must_beat) rule_iterator = new ValidKingBeatIterator(dst_1(), color, *this); |
70
|
|
|
|
|
|
|
# unless ($rule_iterator) |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
while ($rule_iterator->left) { |
73
|
0
|
0
|
|
|
|
|
next if $self->add_dst($rule_iterator->next) == Err; |
74
|
0
|
0
|
|
|
|
|
if ($self->can_create_move) { |
75
|
0
|
|
|
|
|
|
$self->{status} = $self->add_move; |
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
|
|
|
|
|
$self->build_continue; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
$self->del_dst; |
80
|
0
|
0
|
|
|
|
|
last if $self->{status} == Err; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub add_move ($) { |
85
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
86
|
0
|
|
|
|
|
|
die "Pure virtual method is called"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |