line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Chess::Piece::Rook - an object representation of a rook in a game of chess |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$rook = Chess::Piece::Rook->new("a1", "white", |
8
|
|
|
|
|
|
|
"White Queen's rook"); |
9
|
|
|
|
|
|
|
$true = $rook->can_reach("h1"); |
10
|
|
|
|
|
|
|
$true = $rook->can_reach("a8"); |
11
|
|
|
|
|
|
|
$false = $rook->can_reach("d4"); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
The Chess module provides a framework for writing chess programs with Perl. |
16
|
|
|
|
|
|
|
This class forms part of that framework, representing a rook in a |
17
|
|
|
|
|
|
|
L. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 Construction |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=item new() |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Constructs a new Chess::Piece::Rook. Requires two scalar parameters |
26
|
|
|
|
|
|
|
containing the initial square and color of the piece. Optionally takes a |
27
|
|
|
|
|
|
|
third parameter containing a description of the piece. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 Class methods |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
There are no class methods for this class. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 Object methods |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item reachable_squares() |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Overrides base class version. Returns a list of squares that this pawn can |
38
|
|
|
|
|
|
|
reach from its current position. See L |
39
|
|
|
|
|
|
|
for more details on this method. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This module produces no warning messages. See |
44
|
|
|
|
|
|
|
L or |
45
|
|
|
|
|
|
|
L for possible |
46
|
|
|
|
|
|
|
errors or warnings the program may produce. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 BUGS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Please report any bugs to the author. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 AUTHOR |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Brian Richardson |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 COPYRIGHT |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Copyright (c) 2002, 2005 Brian Richardson. All rights reserved. This module is |
59
|
|
|
|
|
|
|
Free Software. It may be modified and redistributed under the same terms as |
60
|
|
|
|
|
|
|
Perl itself. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
package Chess::Piece::Rook; |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
4
|
|
20111
|
use Chess::Board; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
113
|
|
66
|
4
|
|
|
4
|
|
1552
|
use Chess::Piece; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
92
|
|
67
|
4
|
|
|
4
|
|
21
|
use base 'Chess::Piece'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
347
|
|
68
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1316
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
17
|
|
|
17
|
1
|
45
|
my ($caller, $sq, $color, $desc) = @_; |
72
|
17
|
|
33
|
|
|
169
|
my $class = ref($caller) || $caller; |
73
|
17
|
|
|
|
|
89
|
my $self = $caller->SUPER::new($sq, $color, $desc); |
74
|
17
|
|
|
|
|
60
|
return bless $self, $class; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub reachable_squares { |
78
|
655
|
|
|
655
|
1
|
899
|
my ($self) = @_; |
79
|
655
|
|
|
|
|
1653
|
my $csq = $self->get_current_square(); |
80
|
655
|
|
|
|
|
2312
|
my $x = Chess::Board->horz_distance("a4", $csq); |
81
|
655
|
|
|
|
|
2160
|
my $y = Chess::Board->vert_distance("d1", $csq); |
82
|
655
|
|
|
|
|
1347
|
my $row_start = 'a' . ($y + 1); |
83
|
655
|
|
|
|
|
1112
|
my $row_end = 'h' . ($y + 1); |
84
|
655
|
|
|
|
|
1370
|
my $col_start = chr(ord('a') + $x) . '1'; |
85
|
655
|
|
|
|
|
1118
|
my $col_end = chr(ord('a') + $x) . '8'; |
86
|
655
|
|
|
|
|
2124
|
my @row = Chess::Board->squares_in_line($row_start, $row_end); |
87
|
655
|
|
|
|
|
2401
|
my @col = Chess::Board->squares_in_line($col_start, $col_end); |
88
|
655
|
|
|
|
|
3768
|
my @squares = (@row, @col); |
89
|
655
|
|
|
|
|
50277
|
return grep !/^$csq$/, @squares; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |