File Coverage

lib/Games/Checkers/ExpandMoveList.pm
Criterion Covered Total %
statement 12 38 31.5
branch 0 12 0.0
condition n/a
subroutine 4 9 44.4
pod 0 5 0.0
total 16 64 25.0


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   6 use strict;
  1         2  
  1         21  
17 1     1   3 use warnings;
  1         1  
  1         25  
18              
19             package Games::Checkers::ExpandMoveList;
20              
21 1     1   3 use base 'Games::Checkers::MoveLocationConstructor';
  1         2  
  1         338  
22 1     1   6 use Games::Checkers::Constants;
  1         2  
  1         3  
23              
24             sub new ($$$) {
25 0     0 0   my $class = shift;
26 0           my $board = shift;
27 0           my $color = shift;
28 0           my $self = $class->SUPER::new($board, $color);
29              
30             $self->{figure_iterator} =
31 0           new Games::Checkers::FigureIterator($board, $color);
32 0           $self->{status} = Ok;
33 0           return $self;
34             }
35              
36             sub status ($) {
37 0     0 0   my $self = shift;
38 0           return $self->{status};
39             }
40              
41             sub build ($) {
42 0     0 0   my $self = shift;
43 0           while ($self->{figure_iterator}->left) {
44 0 0         if ($self->source($self->{figure_iterator}->next) == Ok) {
45 0           $self->build_continue;
46 0 0         return if $self->{status} == Err;
47             }
48             }
49             }
50              
51             sub build_continue ($) {
52 0     0 0   my $self = shift;
53              
54 0 0         my $method = $self->{must_beat} ? 'beat_destinations' : 'step_destinations';
55 0           my $destinations = $self->{work_board}->$method($self->dst_1, $self->{piece}, $self->{color});
56              
57 0           for my $dst (@$destinations) {
58 0 0         next if $self->add_dst($dst) == Err;
59 0 0         if ($self->can_create_move) {
60 0           $self->{status} = $self->gather_move;
61             } else {
62 0           $self->build_continue;
63             }
64 0           $self->del_dst;
65 0 0         last if $self->{status} == Err;
66             }
67             }
68              
69             sub gather_move ($) {
70 0     0 0   my $self = shift;
71 0           die "Pure virtual method is called";
72             }
73              
74             1;