line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w
|
2
|
|
|
|
|
|
|
####-----------------------------------
|
3
|
|
|
|
|
|
|
### File : Move.pm
|
4
|
|
|
|
|
|
|
### Author : Ch.Minc
|
5
|
|
|
|
|
|
|
### Purpose : Package for ChessKit
|
6
|
|
|
|
|
|
|
### Version : 1.1 2005/8/10
|
7
|
|
|
|
|
|
|
### copyright GNU license
|
8
|
|
|
|
|
|
|
####-----------------------------------
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Move ;
|
11
|
|
|
|
|
|
|
#package Chess::ChessKit::Move;
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
4691
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
14
|
1
|
|
|
1
|
|
7
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.1';
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
ChessKit::Move
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 VERSION
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Version 1.1
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
see ChessKit
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# remainder How are built the moves
|
35
|
|
|
|
|
|
|
#tour
|
36
|
|
|
|
|
|
|
#iter=>7 dir =>3
|
37
|
|
|
|
|
|
|
#my @inc_l=(0,0,-1,1) ;
|
38
|
|
|
|
|
|
|
#my @inc_c=(-1,1,0,0) ;
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#fou
|
41
|
|
|
|
|
|
|
#iter=>7 dir =>3
|
42
|
|
|
|
|
|
|
#my @inc_l=(1,1,-1,-1) ;
|
43
|
|
|
|
|
|
|
#my @inc_c=(1,-1,-1,1) ;
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#cavalier
|
46
|
|
|
|
|
|
|
#iter=>0 dir =>7
|
47
|
|
|
|
|
|
|
#my @inc_l=(-2,-2,2,2,-1,1,-1,1) ;
|
48
|
|
|
|
|
|
|
#my @inc_c=(-1,1,-1,1,-2,-2,2,2) ;
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#dame= fou+tour
|
51
|
|
|
|
|
|
|
#iter=>7 dir =>3
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#roi=fou+tour
|
54
|
|
|
|
|
|
|
#iter=>0 dir =>3
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#pion
|
57
|
|
|
|
|
|
|
#iter=>1 dir =>1
|
58
|
|
|
|
|
|
|
#my @inc_l=(0) ;
|
59
|
|
|
|
|
|
|
#my @inc_c=(1) ;
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#iter=>0 dir =>1 cds prise
|
62
|
|
|
|
|
|
|
#my @inc_l=(1,1) ;
|
63
|
|
|
|
|
|
|
#my @inc_c=(1,-1) ;
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#en_passant
|
66
|
|
|
|
|
|
|
#alpha7-alpha5 || alpha2-alpha4
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#queenroq
|
69
|
|
|
|
|
|
|
#states a1 || a8 && king + echec c1-d1-e1
|
70
|
|
|
|
|
|
|
#kingroq
|
71
|
|
|
|
|
|
|
#states h1 || h8 && king + echec e1-f1-g1
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
require Exporter ;
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
1603
|
use vars qw(
|
77
|
|
|
|
|
|
|
@ISA
|
78
|
1
|
|
|
1
|
|
14
|
@EXPORT );
|
|
1
|
|
|
|
|
3
|
|
79
|
|
|
|
|
|
|
@ISA =qw(Exporter) ;
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
@EXPORT = qw( %gmv );
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
our %gmv=(
|
84
|
|
|
|
|
|
|
n=>\&Knight,
|
85
|
|
|
|
|
|
|
r=>\&Rook,
|
86
|
|
|
|
|
|
|
b=>\&Bishop,
|
87
|
|
|
|
|
|
|
q=>\&Queen,
|
88
|
|
|
|
|
|
|
p=>\&Pawn,
|
89
|
|
|
|
|
|
|
k=>\&King,
|
90
|
|
|
|
|
|
|
u=>\&PawnCatch,
|
91
|
|
|
|
|
|
|
N=>\&Knight,
|
92
|
|
|
|
|
|
|
R=>\&Rook,
|
93
|
|
|
|
|
|
|
B=>\&Bishop,
|
94
|
|
|
|
|
|
|
Q=>\&Queen,
|
95
|
|
|
|
|
|
|
P=>\&Pawn,
|
96
|
|
|
|
|
|
|
K=>\&King,
|
97
|
|
|
|
|
|
|
U=>\&PawnCatch) ;
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 sub Rook
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
get the move of the Rook
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub Rook{
|
106
|
0
|
|
|
0
|
|
|
my %default=(qw/row 0 col 0 lim 7 dir 3/,
|
107
|
|
|
|
|
|
|
inc_l => [0,0,-1,1],
|
108
|
|
|
|
|
|
|
inc_c=>[-1,1,0,0] ) ;
|
109
|
0
|
|
|
|
|
|
my %arg=@_ ;
|
110
|
0
|
|
|
|
|
|
%arg=(%default,%arg) ;
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
lookup(%arg) ;
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 sub Bishop
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
get the move of the Bishop
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub Bishop{
|
123
|
0
|
|
|
0
|
|
|
my %default=(qw/row 0 col 0 lim 7 dir 3/,
|
124
|
|
|
|
|
|
|
inc_l => [1,1,-1,-1],
|
125
|
|
|
|
|
|
|
inc_c=>[1,-1,-1,1]) ;
|
126
|
0
|
|
|
|
|
|
my %arg=@_ ;
|
127
|
0
|
|
|
|
|
|
%arg=(%default,%arg) ;
|
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
lookup(%arg) ;
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 sub Queen
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
get the move of the Queen
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub Queen{
|
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
0
|
|
|
my $arr1=[[]] ;
|
142
|
0
|
|
|
|
|
|
my %arg=@_ ;
|
143
|
0
|
|
|
|
|
|
my $mov=$arg{mov} ;
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$arg{mov}=$arr1 ;
|
147
|
0
|
|
|
|
|
|
Bishop(%arg) ;
|
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
foreach (0..3){
|
150
|
0
|
0
|
|
|
|
|
push( @{$mov->[$_]}, @{$arr1->[$_]} ) if (defined( @{$arr1->[$_]})) ;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $arr2=[[]] ;
|
154
|
0
|
|
|
|
|
|
$arg{mov}=$arr2 ;
|
155
|
0
|
|
|
|
|
|
Rook(%arg) ;
|
156
|
0
|
|
|
|
|
|
foreach (0..3){
|
157
|
0
|
0
|
|
|
|
|
push( @{$mov->[$_+4]}, @{$arr2->[$_]} ) if (defined( @{$arr2->[$_]})) ;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
}
|
159
|
|
|
|
|
|
|
}
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 sub King
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
get the move of the King
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub King{
|
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
0
|
|
|
my %default=(lim=>0) ;
|
170
|
0
|
|
|
|
|
|
my %arg=@_ ;
|
171
|
0
|
|
|
|
|
|
%arg=(%default,%arg) ;
|
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
Queen(%arg) ;
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
}
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 sub Knight
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
get the move of the Knight
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub Knight{
|
185
|
0
|
|
|
0
|
|
|
my %default=(qw/row 0 col 0 lim 0 dir 7/,
|
186
|
|
|
|
|
|
|
inc_l => [-2,-2,2,2,-1,1,-1,1],
|
187
|
|
|
|
|
|
|
inc_c=>[-1,1,-1,1,-2,-2,2,2] ) ;
|
188
|
0
|
|
|
|
|
|
my (%arg)=@_ ;
|
189
|
0
|
|
|
|
|
|
%arg=(%default,%arg) ;
|
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
lookup(%arg) ;
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
}
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 sub Pawn
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
get the move of the Pawn
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub Pawn{
|
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
0
|
|
|
my %default=(qw/row 1 col 0 lim 1 dir 0 color P/,
|
204
|
|
|
|
|
|
|
inc_l => [1],
|
205
|
|
|
|
|
|
|
inc_c=>[0] ) ;
|
206
|
0
|
|
|
|
|
|
my (%arg)=@_ ;
|
207
|
0
|
0
|
|
|
|
|
if($arg{color} eq 'p') {
|
208
|
0
|
|
|
|
|
|
$arg{inc_l}=[-1] ;
|
209
|
0
|
0
|
|
|
|
|
$arg{lim}=0 if $arg{row} != 6 ;}
|
210
|
0
|
0
|
|
|
|
|
else{ $arg{lim}=0 if $arg{row} != 1 ;}
|
211
|
0
|
|
|
|
|
|
%arg=(%default,%arg) ;
|
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
lookup(%arg) ;
|
214
|
0
|
|
|
|
|
|
return ;
|
215
|
|
|
|
|
|
|
}
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 sub PawnCatch
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
get the move of the PawnCatch
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub PawnCatch{
|
224
|
|
|
|
|
|
|
# can_take + e.p. ?
|
225
|
0
|
|
|
0
|
|
|
my %default=(qw/row 1 col 0 lim 0 dir 1 color U/,
|
226
|
|
|
|
|
|
|
inc_l =>[1,1], #color -1,-1
|
227
|
|
|
|
|
|
|
inc_c=>[1,-1] ) ;
|
228
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
my (%arg)=@_ ;
|
230
|
0
|
0
|
|
|
|
|
if($arg{color} eq 'u') {
|
231
|
0
|
|
|
|
|
|
$arg{inc_l}=[-1,-1] ;}
|
232
|
0
|
|
|
|
|
|
%arg=(%default,%arg) ;
|
233
|
0
|
|
|
|
|
|
lookup(%arg) ;
|
234
|
|
|
|
|
|
|
}
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 sub lookup
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
generate the move datas
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub lookup{
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
row=>'numeric', col =>' numeric , lim=>'limite de mouvement',
|
245
|
|
|
|
|
|
|
dir => 'nombre de direction',mov=>'ref avec les cases[dir][]'
|
246
|
|
|
|
|
|
|
}
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub lookup{
|
251
|
|
|
|
|
|
|
|
252
|
0
|
|
|
0
|
|
|
my %arg=@_ ;
|
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
my $row=$arg{row} ;
|
255
|
0
|
|
|
|
|
|
my $col=$arg{col} ;
|
256
|
0
|
|
|
|
|
|
my $iter=$arg{lim} ;
|
257
|
0
|
|
|
|
|
|
my $dir=$arg{dir} ;
|
258
|
0
|
|
|
|
|
|
my $mov=$arg{mov} ;
|
259
|
0
|
|
|
|
|
|
my @inc_c=@{$arg{inc_c}} ;
|
|
0
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
my @inc_l=@{$arg{inc_l}} ;
|
|
0
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
my $l ;
|
263
|
|
|
|
|
|
|
my $c ;
|
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
for ( my $j=0 ; $j<=$dir ; $j++) {
|
266
|
0
|
|
|
|
|
|
my $k=0 ;
|
267
|
|
|
|
|
|
|
|
268
|
0
|
|
0
|
|
|
|
do {
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
269
|
0
|
|
|
|
|
|
$l=$col+ $inc_c[$j]*($k+1);
|
270
|
0
|
|
|
|
|
|
$c= $row + $inc_l[$j]*($k+1) ;
|
271
|
0
|
0
|
0
|
|
|
|
$mov->[$j][$k]=chr(ord('a')+$l).($c+1) if ( $l >=0 && $l <=7 && $c >=0 && $c <=7 ) ;
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
272
|
0
|
|
|
|
|
|
$k++ ;
|
273
|
|
|
|
|
|
|
}
|
274
|
|
|
|
|
|
|
until ($k > $iter || $l <0 || $l > 7 || $c < 0 || $c > 7 ) ;
|
275
|
|
|
|
|
|
|
}
|
276
|
|
|
|
|
|
|
}
|
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head1 AUTHOR
|
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Charles Minc, C<< >>
|
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 BUGS
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Please report any bugs or feature requests to
|
285
|
|
|
|
|
|
|
C, or through the web interface at
|
286
|
|
|
|
|
|
|
L.
|
287
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on
|
288
|
|
|
|
|
|
|
your bug as I make changes.
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE
|
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Copyright 2005 Charles Minc, all rights reserved.
|
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
297
|
|
|
|
|
|
|
under the same terms as Perl itself.
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=cut
|
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
1;
|
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
|