File Coverage

lib/Games/Checkers/BoardConstants.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 32 32 100.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             package Games::Checkers::BoardConstants;
17              
18 1     1   4 use constant NL => 32;
  1         2  
  1         81  
19              
20             use Games::Checkers::DeclareConstant {
21 1         9 MAX_LOCATION => 31,
22             NL => NL, # no location
23             ML => NL + 1, # multiple locations
24             DIRECTION_NUM => 4,
25             DEFAULT_LEVEL => 6,
26 1     1   450 };
  1         2  
27              
28 1         22 use Games::Checkers::DeclareConstant loc_directions => [
29             [ NL, 4, NL, NL], [ 4, 5, NL, NL], [ 5, 6, NL, NL], [ 6, 7, NL, NL],
30             [ 8, 9, 0, 1], [ 9, 10, 1, 2], [ 10, 11, 2, 3], [ 11, NL, 3, NL],
31             [ NL, 12, NL, 4], [ 12, 13, 4, 5], [ 13, 14, 5, 6], [ 14, 15, 6, 7],
32             [ 16, 17, 8, 9], [ 17, 18, 9, 10], [ 18, 19, 10, 11], [ 19, NL, 11, NL],
33             [ NL, 20, NL, 12], [ 20, 21, 12, 13], [ 21, 22, 13, 14], [ 22, 23, 14, 15],
34             [ 24, 25, 16, 17], [ 25, 26, 17, 18], [ 26, 27, 18, 19], [ 27, NL, 19, NL],
35             [ NL, 28, NL, 20], [ 28, 29, 20, 21], [ 29, 30, 21, 22], [ 30, 31, 22, 23],
36             [ NL, NL, 24, 25], [ NL, NL, 25, 26], [ NL, NL, 26, 27], [ NL, NL, 27, NL],
37 1     1   6 ];
  1         1  
38              
39 1         5 use Games::Checkers::DeclareConstant convert_type => [
40             # pawn king
41             [ 0xF0000000, 0x00000000 ], # white
42             [ 0x0000000F, 0x00000000 ], # black
43 1     1   12 ];
  1         2  
44              
45 1         44 use Games::Checkers::DeclareConstant pawn_step => [
46             [
47             [ NL, 4], [ 4, 5], [ 5, 6], [ 6, 7],
48             [ 8, 9], [ 9, 10], [ 10, 11], [ 11, NL],
49             [ NL, 12], [ 12, 13], [ 13, 14], [ 14, 15],
50             [ 16, 17], [ 17, 18], [ 18, 19], [ 19, NL],
51             [ NL, 20], [ 20, 21], [ 21, 22], [ 22, 23],
52             [ 24, 25], [ 25, 26], [ 26, 27], [ 27, NL],
53             [ NL, 28], [ 28, 29], [ 29, 30], [ 30, 31],
54             [ NL, NL], [ NL, NL], [ NL, NL], [ NL, NL],
55             ], [
56             [ NL, NL], [ NL, NL], [ NL, NL], [ NL, NL],
57             [ 0, 1], [ 1, 2], [ 2, 3], [ 3, NL],
58             [ NL, 4], [ 4, 5], [ 5, 6], [ 6, 7],
59             [ 8, 9], [ 9, 10], [ 10, 11], [ 11, NL],
60             [ NL, 12], [ 12, 13], [ 13, 14], [ 14, 15],
61             [ 16, 17], [ 17, 18], [ 18, 19], [ 19, NL],
62             [ NL, 20], [ 20, 21], [ 21, 22], [ 22, 23],
63             [ 24, 25], [ 25, 26], [ 26, 27], [ 27, NL],
64             ]
65 1     1   5 ];
  1         1  
66              
67 1         22 use Games::Checkers::DeclareConstant pawn_beat => [
68             [ NL, 9, NL, NL], [ 8, 10, NL, NL], [ 9, 11, NL, NL], [ 10, NL, NL, NL],
69             [ NL, 13, NL, NL], [ 12, 14, NL, NL], [ 13, 15, NL, NL], [ 14, NL, NL, NL],
70             [ NL, 17, NL, 1], [ 16, 18, 0, 2], [ 17, 19, 1, 3], [ 18, NL, 2, NL],
71             [ NL, 21, NL, 5], [ 20, 22, 4, 6], [ 21, 23, 5, 7], [ 22, NL, 6, NL],
72             [ NL, 25, NL, 9], [ 24, 26, 8, 10], [ 25, 27, 9, 11], [ 26, NL, 10, NL],
73             [ NL, 29, NL, 13], [ 28, 30, 12, 14], [ 29, 31, 13, 15], [ 30, NL, 14, NL],
74             [ NL, NL, NL, 17], [ NL, NL, 16, 18], [ NL, NL, 17, 19], [ NL, NL, 18, NL],
75             [ NL, NL, NL, 21], [ NL, NL, 20, 22], [ NL, NL, 21, 23], [ NL, NL, 22, NL],
76 1     1   5 ];
  1         1  
77              
78 1         45 use Games::Checkers::DeclareConstant king_step => [
79             [ 4, 9, 13, 18, 22, 27, 31, NL, NL, NL, NL, NL, NL],
80             [ 4, 8, 5, 10, 14, 19, 23, NL, NL, NL, NL, NL, NL],
81             [ 5, 9, 12, 16, 6, 11, 15, NL, NL, NL, NL, NL, NL],
82             [ 6, 10, 13, 17, 20, 24, 7, NL, NL, NL, NL, NL, NL],
83             [ 8, 9, 13, 18, 22, 27, 31, 0, 1, NL, NL, NL, NL],
84             [ 9, 12, 16, 10, 14, 19, 23, 1, 2, NL, NL, NL, NL],
85             [ 10, 13, 17, 20, 24, 11, 15, 2, 3, NL, NL, NL, NL],
86             [ 11, 14, 18, 21, 25, 28, 3, NL, NL, NL, NL, NL, NL],
87             [ 12, 17, 21, 26, 30, 4, 1, NL, NL, NL, NL, NL, NL],
88             [ 12, 16, 13, 18, 22, 27, 31, 4, 0, 5, 2, NL, NL],
89             [ 13, 17, 20, 24, 14, 19, 23, 5, 1, 6, 3, NL, NL],
90             [ 14, 18, 21, 25, 28, 15, 6, 2, 7, NL, NL, NL, NL],
91             [ 16, 17, 21, 26, 30, 8, 9, 5, 2, NL, NL, NL, NL],
92             [ 17, 20, 24, 18, 22, 27, 31, 9, 4, 0, 10, 6, 3],
93             [ 18, 21, 25, 28, 19, 23, 10, 5, 1, 11, 7, NL, NL],
94             [ 19, 22, 26, 29, 11, 6, 2, NL, NL, NL, NL, NL, NL],
95             [ 20, 25, 29, 12, 9, 5, 2, NL, NL, NL, NL, NL, NL],
96             [ 20, 24, 21, 26, 30, 12, 8, 13, 10, 6, 3, NL, NL],
97             [ 21, 25, 28, 22, 27, 31, 13, 9, 4, 0, 14, 11, 7],
98             [ 22, 26, 29, 23, 14, 10, 5, 1, 15, NL, NL, NL, NL],
99             [ 24, 25, 29, 16, 17, 13, 10, 6, 3, NL, NL, NL, NL],
100             [ 25, 28, 26, 30, 17, 12, 8, 18, 14, 11, 7, NL, NL],
101             [ 26, 29, 27, 31, 18, 13, 9, 4, 0, 19, 15, NL, NL],
102             [ 27, 30, 19, 14, 10, 5, 1, NL, NL, NL, NL, NL, NL],
103             [ 28, 20, 17, 13, 10, 6, 3, NL, NL, NL, NL, NL, NL],
104             [ 28, 29, 20, 16, 21, 18, 14, 11, 7, NL, NL, NL, NL],
105             [ 29, 30, 21, 17, 12, 8, 22, 19, 15, NL, NL, NL, NL],
106             [ 30, 31, 22, 18, 13, 9, 4, 0, 23, NL, NL, NL, NL],
107             [ 24, 25, 21, 18, 14, 11, 7, NL, NL, NL, NL, NL, NL],
108             [ 25, 20, 16, 26, 22, 19, 15, NL, NL, NL, NL, NL, NL],
109             [ 26, 21, 17, 12, 8, 27, 23, NL, NL, NL, NL, NL, NL],
110             [ 27, 22, 18, 13, 9, 4, 0, NL, NL, NL, NL, NL, NL],
111 1     1   5 ];
  1         1  
112              
113 1         46 use Games::Checkers::DeclareConstant king_beat => [
114             [ 9, 13, 18, 22, 27, 31, NL, NL, NL],
115             [ 8, 10, 14, 19, 23, NL, NL, NL, NL],
116             [ 9, 12, 16, 11, 15, NL, NL, NL, NL],
117             [ 10, 13, 17, 20, 24, NL, NL, NL, NL],
118             [ 13, 18, 22, 27, 31, NL, NL, NL, NL],
119             [ 12, 16, 14, 19, 23, NL, NL, NL, NL],
120             [ 13, 17, 20, 24, 15, NL, NL, NL, NL],
121             [ 14, 18, 21, 25, 28, NL, NL, NL, NL],
122             [ 17, 21, 26, 30, 1, NL, NL, NL, NL],
123             [ 16, 18, 22, 27, 31, 0, 2, NL, NL],
124             [ 17, 20, 24, 19, 23, 1, 3, NL, NL],
125             [ 18, 21, 25, 28, 2, NL, NL, NL, NL],
126             [ 21, 26, 30, 5, 2, NL, NL, NL, NL],
127             [ 20, 24, 22, 27, 31, 4, 0, 6, 3],
128             [ 21, 25, 28, 23, 5, 1, 7, NL, NL],
129             [ 22, 26, 29, 6, 2, NL, NL, NL, NL],
130             [ 25, 29, 9, 5, 2, NL, NL, NL, NL],
131             [ 24, 26, 30, 8, 10, 6, 3, NL, NL],
132             [ 25, 28, 27, 31, 9, 4, 0, 11, 7],
133             [ 26, 29, 10, 5, 1, NL, NL, NL, NL],
134             [ 29, 13, 10, 6, 3, NL, NL, NL, NL],
135             [ 28, 30, 12, 8, 14, 11, 7, NL, NL],
136             [ 29, 31, 13, 9, 4, 0, 15, NL, NL],
137             [ 30, 14, 10, 5, 1, NL, NL, NL, NL],
138             [ 17, 13, 10, 6, 3, NL, NL, NL, NL],
139             [ 16, 18, 14, 11, 7, NL, NL, NL, NL],
140             [ 17, 12, 8, 19, 15, NL, NL, NL, NL],
141             [ 18, 13, 9, 4, 0, NL, NL, NL, NL],
142             [ 21, 18, 14, 11, 7, NL, NL, NL, NL],
143             [ 20, 16, 22, 19, 15, NL, NL, NL, NL],
144             [ 21, 17, 12, 8, 23, NL, NL, NL, NL],
145             [ 22, 18, 13, 9, 4, 0, NL, NL, NL],
146 1     1   5 ];
  1         1  
147              
148             1;