lib/Games/Checkers/Rules.pm

filter: Statementstmt 90.6% 29 / 32 Branchbran 45.8% 11 / 24 Conditioncond 31.2% 5 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 75.0% 3 / 4 Podpod 0.0% 0 / 2 totaltotal 55.1% 48 / 87 CC 21 SCAR 33.7
CC
21
Cov
62%
set_variant
34.7
get_main_variants
12.0
BEGIN
1.0
CRAP 29.1
« lib/Games/Checkers/MoveLocationConstructor.pm ↑ Summary lib/Games/Checkers/ExpandMoveList.pm »
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 <http://www.gnu.org/licenses/>.
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 package main;
20  
21 1 our %RULES;
22  
23 package Games::Checkers::Rules;
24  
25 1 our %variant_rules = (
26 international => {
27 BOARD_SIZE => '10x10',
28 BOARD_NOTATION => 'TL',
29 CAPTURE_SEPARATOR => 'x',
30 STARTING_ROWS => 4,
31 BOTTOM_LEFT_CELL => 1,
32 PDN_GAME_TYPE => 20,
33 WHITE_STARTS => 1,
34 KINGS_LONG_RANGED => 1,
35 PAWNS_CAPTURING_BACKWARDS => 1,
36 CAPTURING_LARGEST => 1,
37 CAPTURING_POSTPONED => 1,
38 CROWNING_DURING_CAPTURE => 0,
39 PAWNS_CANT_CAPTURE_KINGS => 0,
40 CAPTURING_LEAVES_NO_GAP => 0,
41 GIVE_AWAY => 0,
42 CAPTURING_IN_8_DIRECTIONS => 0,
43 },
44 russian => {
45 base => 'international',
46 BOARD_SIZE => '8x8',
47 BOARD_NOTATION => 'A1',
48 CAPTURE_SEPARATOR => ':',
49 STARTING_ROWS => 3,
50 PDN_GAME_TYPE => 25,
51 CAPTURING_LARGEST => 0,
52 CROWNING_DURING_CAPTURE => 1,
53 },
54 russian_give_away => {
55 base => 'russian',
56 PDN_GAME_TYPE => 00,
57 GIVE_AWAY => 1,
58 },
59 russian_10x8 => {
60 base => 'russian',
61 BOARD_SIZE => '10x8',
62 PDN_GAME_TYPE => 41,
63 },
64 english => {
65 base => 'international',
66 BOARD_SIZE => '8x8',
67 BOARD_NOTATION => 'TL',
68 STARTING_ROWS => 3,
69 PDN_GAME_TYPE => 21,
70 WHITE_STARTS => 0,
71 KINGS_LONG_RANGED => 0,
72 PAWNS_CAPTURING_BACKWARDS => 0,
73 CAPTURING_LARGEST => 0,
74 CAPTURING_POSTPONED => 0,
75 CROWNING_DURING_CAPTURE => 'S',
76 },
77 english_give_away => {
78 base => 'english',
79 PDN_GAME_TYPE => 00,
80 GIVE_AWAY => 1,
81 },
82 italian => {
83 base => 'english',
84 BOARD_NOTATION => 'TR',
85 BOTTOM_LEFT_CELL => 0,
86 PDN_GAME_TYPE => 22,
87 WHITE_STARTS => 1,
88 CAPTURING_LARGEST => 2,
89 PAWNS_CANT_CAPTURE_KINGS => 1,
90 },
91 spanish => {
92 base => 'english',
93 BOARD_NOTATION => 'BR',
94 BOTTOM_LEFT_CELL => 0,
95 PDN_GAME_TYPE => 24,
96 WHITE_STARTS => 1,
97 KINGS_LONG_RANGED => 1,
98 CAPTURING_LARGEST => 3,
99 CAPTURING_POSTPONED => 1,
100 },
101 argentinian => {
102 base => 'spanish',
103 CAPTURING_LEAVES_NO_GAP => 1,
104 PDN_GAME_TYPE => 00,
105 },
106 portuguese => {
107 base => 'spanish',
108 BOTTOM_LEFT_CELL => 1,
109 PDN_GAME_TYPE => 28,
110 },
111 czech => {
112 base => 'portuguese',
113 BOARD_NOTATION => 'A1',
114 CAPTURING_LARGEST => -1,
115 PDN_GAME_TYPE => 29,
116 },
117 german => {
118 base => 'czech',
119 CAPTURING_LARGEST => 0,
120 PDN_GAME_TYPE => 00,
121 },
122 thai => {
123 base => 'english',
124 BOARD_NOTATION => 'BR',
125 CAPTURE_SEPARATOR => '-',
126 STARTING_ROWS => 2,
127 PDN_GAME_TYPE => 31,
128 KINGS_LONG_RANGED => 1,
129 CAPTURING_LEAVES_NO_GAP => 1,
130 },
131 pool => {
132 base => 'english',
133 BOARD_NOTATION => 'BR',
134 PDN_GAME_TYPE => 23,
135 KINGS_LONG_RANGED => 1,
136 CROWNING_DURING_CAPTURE => 0,
137 PAWNS_CAPTURING_BACKWARDS => 1,
138 },
139 brazilian => {
140 base => 'international',
141 BOARD_SIZE => '8x8',
142 BOARD_NOTATION => 'A1',
143 STARTING_ROWS => 3,
144 PDN_GAME_TYPE => 26,
145 },
146 frisian => {
147 base => 'international',
148 PDN_GAME_TYPE => 40,
149 CAPTURING_IN_8_DIRECTIONS => 1,
150 },
151 canadian => {
152 base => 'international',
153 BOARD_SIZE => '12x12',
154 STARTING_ROWS => 5,
155 PDN_GAME_TYPE => 27,
156 },
157 sri_lankian => {
158 base => 'canadian',
159 BOTTOM_LEFT_CELL => 0,
160 PDN_GAME_TYPE => 00,
161 },
162 default => 'russian',
163 british => 'english',
164 internt => 'international',
165 int => 'international',
166 polish => 'international',
167 '8x8' => 'brazilian',
168 '10x10' => 'international',
169 '12x12' => 'canadian',
170 shashki => 'russian',
171 poddavki => 'russian_give_away',
172 american => 'english',
173 give_away => 'english_give_away',
174 spantsiretti => 'russian_10x8',
175 american_pool => 'pool',
176 spanish_pool => 'spanish',
177 20 => 'international',
178 21 => 'english',
179 22 => 'italian',
180 23 => 'pool',
181 24 => 'spanish',
182 25 => 'russian',
183 26 => 'brazilian',
184 27 => 'canadian',
185 28 => 'portuguese',
186 29 => 'czech',
187 31 => 'thai',
188 40 => 'frisian',
189 41 => 'russian_10x8',
190 );
191  
192 1 ▶sub set_variant ($%) {
Subroutine set_variant: called CC=19 SCAR=35.5
Pod undocumented
193 1 ▶ my $name = shift || 'default';
Condition50%1/2
shift() || 'default'
l!l
10
MC/DC0%0/1
shift() || 'default'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
194 1 my %params = @_;
195  
196 # support GameType specification from PDN
197 1 my ($base, $starting_color, $size_x, $size_y, $notation, $invert) =
198 split(',', $name);
199 1 ▶ $params{WHITE_STARTS} = $starting_color eq 'W' ? 1 : 0
Branch: 2 branches
BranchTrueFalseTotal
if defined $starting_color 0 1 1
$starting_color eq 'W' ? : 0 0 0
200 if defined $starting_color;
201 1 ▶ $params{BOARD_SIZE} = "${size_x}x$size_y"
Branch: 1 branch
BranchTrueFalseTotal
if $size_x and $size_y and "$size_x$size_y" =~ /^\d+$/ 0 1 1
Condition33%2/6
$size_x and $size_y and "$size_x$size_y" =~ /^\d+$/
!ll&&!rl&&r
100
$size_x and $size_y
!ll&&!rl&&r
100
MC/DC0%0/3
$size_x and $size_y and "$size_x$size_y" =~ /^\d+$/
$size_x $size_y "$size_x$size_y" =~ /^\d+$/
Truth table25%1/4
A and B and C
A= $size_xB= $size_yC= "$size_x$size_y" =~ /^\d+$/
ABCresult
0XX0
10X0
1100
1111
202 if $size_x && $size_y && "$size_x$size_y" =~ /^\d+$/;
203 1 ▶ $params{BOARD_NOTATION} = $1 eq 'N' ? [ qw(BL BR TL TR) ]->[$2] : "$1$2"
Branch: 2 branches
BranchTrueFalseTotal
if defined $notation and $notation =~ /^([ANS])([0-3])$/ 0 1 1
$1 eq 'N' ? : 0 0 0
Condition33%1/3
defined $notation and $notation =~ /^([ANS])([0-3])$/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $notation and $notation =~ /^([ANS])([0-3])$/
defined $notation $notation =~ /^([ANS])([0-3])$/
Truth table33%1/3
A and B
A= defined $notationB= $notation =~ /^([ANS])([0-3])$/
ABresult
0X0
100
111
204 if defined $notation && $notation =~ /^([ANS])([0-3])$/;
205 1 ▶ $params{BOTTOM_LEFT_CELL} = $invert ? 0 : 1
Branch: 2 branches
BranchTrueFalseTotal
if defined $invert 0 1 1
$invert ? : 0 0 0
206 if defined $invert;
207  
208 1 %::RULES = (variant => $base, base => $base);
209 1 for (keys %{$variant_rules{international}}) {
210 16 ▶ $::RULES{$_} = defined $params{$_} ? $params{$_} : $ENV{$_};
Branch: 1 branch
BranchTrueFalseTotal
defined $params{$_} ? : 0 16 16
211 }
212  
213 1 ▶ while (my $base = delete $::RULES{base}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $base = delete $main::RULES{"base"}) 3 1 4
214 3 $base = lc($base); $base =~ s/[\s-]+/_/g;
215 3 ▶ my $rules = $variant_rules{$base} || die "Checkers variant '$base' is unknown\n";
Condition50%1/2
$Games::Checkers::Rules::variant_rules{$base} || die("Checkers variant '${base}' is unknown\n")
l!l
30
MC/DC0%0/1
$Games::Checkers::Rules::variant_rules{$base} || die("Checkers variant '${base}' is unknown\n")
$Games::Checkers::Rules::variant_rules{$base}
Truth table50%1/2
A
A= $Games::Checkers::Rules::variant_rules{$base}
Aresult
11
00
216 3 ▶ $rules = { base => $rules } unless ref($rules);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rules 1 2 3
217 3 for (keys %$rules) {
218 25 ▶ $::RULES{$_} = $rules->{$_} unless defined $::RULES{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $main::RULES{$_} 18 7 25
219 }
220 }
221  
222 1 return 1;
223 }
224  
225 0 ▶sub get_main_variants () {
Subroutine get_main_variants: not called CC=3 SCAR=24.8
Pod undocumented
226 return sort map {
227 0 my $entry = $variant_rules{$_};
228 ref($entry) eq 'HASH' && defined $entry->{PDN_GAME_TYPE}
229 0 ▶ ? ($_) : ()
Branch: 1 branch
BranchTrueFalseTotal
ref $entry eq 'HASH' && defined $entry->{'PDN_GAME_TYPE'} ? : 0 0 0
Condition0%0/3
ref $entry eq "HASH" and defined $entry->{"PDN_GAME_TYPE"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $entry eq "HASH" and defined $entry->{"PDN_GAME_TYPE"}
ref $entry eq "HASH" defined $entry->{"PDN_GAME_TYPE"}
Truth table0%0/3
A and B
A= ref $entry eq "HASH"B= defined $entry->{"PDN_GAME_TYPE"}
ABresult
0X0
100
111
230 } keys %variant_rules;
231 }
232  
233 1 set_variant('default');
234  
235 1 1;
« lib/Games/Checkers/MoveLocationConstructor.pm ↑ Summary lib/Games/Checkers/ExpandMoveList.pm »