Cribbage/Board.pm

filter: Statementstmt 84.8% 151 / 178 Branchbran 46.1% 12 / 26 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 88.7% 55 / 62 Podpod 100% 56 / 56 totaltotal 83.6% 276 / 330 CC 20 SCAR 10.0
CC
20
Cov
79%
force_to_crib
12.0
start_game
10.4
force_draw_card
4.4
CRAP 2.7
« Cribbage/Round.pm ↑ Summary Cribbage/Deck/Card.pm »
1 package Game::Cribbage::Board;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Game::Cribbage::Player;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Game::Cribbage::Deck;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Game::Cribbage::Rounds;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 has players => (
12 is => 'rw',
13 isa => ArrayRef,
14 default => [],
15 12 );
16  
17 has [qw/deck rounds/] => (
18 is => 'rw',
19 isa => Object,
20 12 );
21  
22 131 ▶sub add_player {
Subroutine add_player: called CC=1 SCAR=0.0
Pod documented
23 131 my ($self, %player) = @_;
24 131 push @{$self->players}, Game::Cribbage::Player->new(
25 131 number => scalar @{$self->players} + 1,
26 %player
27 );
28 131 return $self;
29 }
30  
31 2 ▶sub add_player_if_not_exists {
Subroutine add_player_if_not_exists: called CC=2 SCAR=6.9
Pod documented
32 2 my ($self, %player) = @_;
33 2 my $exists = $self->get_player(%player);
34 2 ▶ if (!$exists) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($exists) 1 1 2
35 1 $self->add_player(%player);
36 1 $exists = $self->get_player(%player);
37 1 return ($exists, 0);
38 }
39 1 return ($exists, 1);
40 }
41  
42 5 ▶sub get_player {
Subroutine get_player: called CC=3 SCAR=11.0
Pod documented
43 5 my ($self, %player) = @_;
44 5 my $exists = 0;
45 5 for (@{$self->players}) {
46 6 ▶ if ($_->name =~ m/^$player{name}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->name =~ /^$player{"name"}$/) 3 3 6
47 3 return $_;
48 }
49 }
50 }
51  
52 64 ▶sub build_deck {
Subroutine build_deck: called CC=1 SCAR=0.0
Pod documented
53 64 $_[0]->deck(Game::Cribbage::Deck->new());
54 }
55  
56 61 ▶sub build_rounds {
Subroutine build_rounds: called CC=1 SCAR=0.0
Pod documented
57 61 $_[0]->rounds(Game::Cribbage::Rounds->new(
58 number => $_[1]
59 ));
60 }
61  
62 61 ▶sub start_game {
Subroutine start_game: called CC=7 SCAR=23.4
Pod documented
63 61 my ($self, %args) = @_;
64 61 ▶ $self->build_deck() if (!$self->deck);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->deck 61 0 61
65 61 ▶ $self->build_rounds($args{rounds} || 1) if (!$self->rounds);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->rounds 61 0 61
Condition50%1/2
$args{'rounds'} || 1
l!l
061
MC/DC0%0/1
$args{'rounds'} || 1
$args{'rounds'}
Truth table50%1/2
A
A= $args{'rounds'}
Aresult
11
00
66 61 ▶ $self->rounds->next_round($self, ($args{id} ? (id => $args{id}) : ())) if (!$self->rounds->current_round || $self->rounds->current_round->complete);
Branch: 2 branches
BranchTrueFalseTotal
if not $self->rounds->current_round or $self->rounds->current_round->complete 61 0 61
$args{'id'} ? : 0 61 61
Condition33%1/3
not $self->rounds->current_round or $self->rounds->current_round->complete
l!l&&r!l&&!r
6100
MC/DC0%0/2
not $self->rounds->current_round or $self->rounds->current_round->complete
not $self->rounds->current_round $self->rounds->current_round->complete
Truth table33%1/3
not(A) or B
A= not $self->rounds->current_roundB= $self->rounds->current_round->complete
ABresult
1X1
011
000
67 }
68  
69 0 ▶sub next_hands {
Subroutine next_hands: not called CC=1 SCAR=6.9
Pod documented
70 0 my ($self, %args) = @_;
71 0 $self->rounds->current_round->next_hands(%args);
72 }
73  
74 0 ▶sub force_to_crib {
Subroutine force_to_crib: not called CC=3 SCAR=24.8
Pod documented
75 0 my ($self, $card) = @_;
76  
77 0 my $crib = $self->crib_player_identifier;
78  
79 0 my $round = $self->rounds->current_round;
80  
81 0 ▶ if ($self->deck->card_exists($card)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->deck->card_exists($card)) 0 0 0
82 0 $round->add_crib_card(
83 $self->deck->force_draw($card)
84 );
85 0 return 1;
86 }
87  
88 # confirm it exists in the players hand
89 0 ▶ if ($round->card_exists($crib, $card)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($round->card_exists($crib, $card)) 0 0 0
90 0 return 1;
91 }
92  
93 $round->add_crib_card(
94 0 $self->deck->generate_card($card)
95 );
96  
97 0 return 1;
98 }
99  
100 1 ▶sub force_draw_card {
Subroutine force_draw_card: called CC=3 SCAR=14.8
Pod documented
101 1 my ($self, $player, $index, $card) = @_;
102  
103 1 my $round = $self->rounds->current_round;
104  
105 1 ▶ if ($self->deck->card_exists($card)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->deck->card_exists($card)) 1 0 1
106 1 $round->add_player_card(
107 $player,
108 $self->deck->force_draw($card)
109 );
110 1 return 1;
111 }
112  
113 # confirm it exists in the players hand
114 0 ▶ if ($round->card_exists($player, $card)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($round->card_exists($player, $card)) 0 0 0
115 0 return 1;
116 }
117  
118 $round->add_player_card_by_index(
119 0 $index,
120 $player,
121 $self->deck->generate_card($card)
122 );
123  
124 0 return 1;
125 }
126  
127 2 ▶sub draw_hands {
Subroutine draw_hands: called CC=3 SCAR=11.0
Pod documented
128 2 my ($self) = @_;
129  
130 2 my $round = $self->rounds->current_round;
131  
132 2 for (0 .. 5) {
133 12 for (@{$self->players}) {
134 24 $round->add_player_card(
135 $_,
136 $self->deck->draw
137 );
138 }
139 }
140 }
141  
142 3 ▶sub add_starter_card {
Subroutine add_starter_card: called CC=1 SCAR=0.0
Pod documented
143 3 my ($self, $player, $card) = @_;
144 3 $self->rounds->current_round->current_hands->add_starter_card($player, $card);
145 }
146  
147 43 ▶sub get_hands {
Subroutine get_hands: called CC=1 SCAR=0.0
Pod documented
148 43 my ($self) = @_;
149 43 return $self->rounds->current_round->current_hands;
150 }
151  
152 0 ▶sub identify_worst_cards {
Subroutine identify_worst_cards: not called CC=1 SCAR=6.9
Pod documented
153 0 my ($self, $player) = @_;
154 0 $self->rounds->current_round->identify_worst_cards($player);
155 }
156  
157 1 ▶sub validate_crib_cards {
Subroutine validate_crib_cards: called CC=1 SCAR=0.0
Pod documented
158 1 my ($self, $cards) = @_;
159 1 $self->rounds->current_round->validate_crib_cards($cards);
160 }
161  
162 1 ▶sub crib_player_id {
Subroutine crib_player_id: called CC=1 SCAR=0.0
Pod documented
163 1 my ($self) = @_;
164 1 $self->rounds->current_round->crib_player_id($self);
165 }
166  
167 1 ▶sub crib_player_identifier {
Subroutine crib_player_identifier: called CC=1 SCAR=0.0
Pod documented
168 1 my ($self) = @_;
169 1 $self->rounds->current_round->current_hands->crib_player;
170 }
171  
172 1 ▶sub crib_player_name {
Subroutine crib_player_name: called CC=1 SCAR=0.0
Pod documented
173 1 my ($self) = @_;
174 1 $self->rounds->current_round->crib_player_name($self);
175 }
176  
177 1 ▶sub crib_player_number {
Subroutine crib_player_number: called CC=1 SCAR=0.0
Pod documented
178 1 my ($self) = @_;
179 1 $self->rounds->current_round->crib_player_number($self);
180 }
181  
182 0 ▶sub crib_player_cards {
Subroutine crib_player_cards: not called CC=1 SCAR=6.9
Pod documented
183 0 my ($self, $player, $cards) = @_;
184 0 $self->rounds->current_round->crib_player_cards($player, $cards);
185 }
186  
187 120 ▶sub cribbed_card {
Subroutine cribbed_card: called CC=1 SCAR=0.0
Pod documented
188 120 my ($self, $player, $index) = @_;
189 120 $self->rounds->current_round->crib_player_card($player, $index);
190 }
191  
192 60 ▶sub cribbed_cards {
Subroutine cribbed_cards: called CC=2 SCAR=6.9
Pod documented
193 60 my ($self, $player, @card_indexes) = @_;
194  
195 60 @card_indexes = sort { $b <=> $a } @card_indexes;
196 60 $self->cribbed_card($player, $_) for @card_indexes;
197 60 return 1;
198 }
199  
200 0 ▶sub force_play_card {
Subroutine force_play_card: not called CC=1 SCAR=6.9
Pod documented
201 0 my ($self, $card) = @_;
202 0 $self->rounds->current_round->force_play_card($card);
203 }
204  
205 37 ▶sub play_card {
Subroutine play_card: called CC=1 SCAR=0.0
Pod documented
206 37 my ($self, $player, $index) = @_;
207 37 $self->rounds->current_round->play_player_card($player, $index);
208 }
209  
210 8 ▶sub get_card {
Subroutine get_card: called CC=1 SCAR=0.0
Pod documented
211 8 my ($self, $player, $index) = @_;
212 8 $self->rounds->current_round->get_player_card($player, $index);
213 }
214  
215 78 ▶sub current_play {
Subroutine current_play: called CC=1 SCAR=0.0
Pod documented
216 78 my ($self) = @_;
217 78 return $self->rounds->current_round->current_hands->play;
218 }
219  
220 1 ▶sub current_play_cards {
Subroutine current_play_cards: called CC=1 SCAR=0.2
Pod documented
221 1 my ($self) = @_;
222 0 return [map { $_->card } @{$self->rounds->current_round->current_hands->play->cards}];
223 }
224  
225 52 ▶sub current_play_score {
Subroutine current_play_score: called CC=1 SCAR=0.0
Pod documented
226 52 my ($self) = @_;
227 52 $self->rounds->current_round->current_play_score();
228 }
229  
230 2 ▶sub last_play_score {
Subroutine last_play_score: called CC=1 SCAR=0.0
Pod documented
231 2 my ($self) = @_;
232 2 $self->rounds->current_round->last_play_score();
233 }
234  
235 35 ▶sub score {
Subroutine score: called CC=1 SCAR=0.0
Pod documented
236 35 my ($self) = @_;
237 35 $self->rounds->current_round->score;
238 }
239  
240 11 ▶sub cannot_play {
Subroutine cannot_play: called CC=1 SCAR=0.0
Pod documented
241 11 my ($self, $player) = @_;
242 11 $self->rounds->current_round->cannot_play_a_card($player);
243 }
244  
245 2 ▶sub player_cannot_play {
Subroutine player_cannot_play: called CC=1 SCAR=0.0
Pod documented
246 2 my ($self, $player) = @_;
247 2 return exists $self->rounds->current_round->current_hands->cannot_play->{$player};
248 }
249  
250 1 ▶sub no_player_can_play {
Subroutine no_player_can_play: called CC=1 SCAR=0.0
Pod documented
251 1 my ($self) = @_;
252 1 return scalar(keys(%{$self->rounds->current_round->current_hands->cannot_play})) == scalar(@{$self->players});
253 }
254  
255 7 ▶sub next_play {
Subroutine next_play: called CC=1 SCAR=0.0
Pod documented
256 7 my ($self) = @_;
257 7 $self->rounds->current_round->next_play($self);
258 }
259  
260 2 ▶sub end_play {
Subroutine end_play: called CC=1 SCAR=0.0
Pod documented
261 2 my ($self) = @_;
262 2 $self->rounds->current_round->end_play();
263 }
264  
265 3 ▶sub end_hands {
Subroutine end_hands: called CC=1 SCAR=0.0
Pod documented
266 3 my ($self) = @_;
267 3 $self->rounds->current_round->end_hands($self);
268 }
269  
270 68 ▶sub shuffle {
Subroutine shuffle: called CC=1 SCAR=0.0
Pod documented
271 68 my ($self) = @_;
272 68 $self->deck->shuffle();
273 }
274  
275 1 ▶sub get_round_id {
Subroutine get_round_id: called CC=1 SCAR=0.0
Pod documented
276 1 my ($self) = @_;
277 1 return $self->rounds->current_round->id;
278 }
279  
280 1 ▶sub set_round_id {
Subroutine set_round_id: called CC=1 SCAR=0.0
Pod documented
281 1 my ($self, $id) = @_;
282 1 $self->rounds->current_round->id($id);
283 1 return $id;
284 }
285  
286 1 ▶sub get_hands_id {
Subroutine get_hands_id: called CC=1 SCAR=0.0
Pod documented
287 1 my ($self) = @_;
288 1 return $self->rounds->current_round->current_hands->id;
289 }
290  
291 1 ▶sub set_hands_id {
Subroutine set_hands_id: called CC=1 SCAR=0.0
Pod documented
292 1 my ($self, $id) = @_;
293 1 $self->rounds->current_round->current_hands->id($id);
294 1 return $id;
295 }
296  
297 1 ▶sub get_play_id {
Subroutine get_play_id: called CC=1 SCAR=0.0
Pod documented
298 1 my ($self) = @_;
299 1 return $self->rounds->current_round->current_hands->play->id;
300 }
301  
302 1 ▶sub set_play_id {
Subroutine set_play_id: called CC=1 SCAR=0.0
Pod documented
303 1 my ($self, $id) = @_;
304 1 $self->rounds->current_round->current_hands->play->id($id);
305 1 return $id;
306 }
307  
308 1 ▶sub get_crib_player_hand_id {
Subroutine get_crib_player_hand_id: called CC=1 SCAR=0.0
Pod documented
309 1 my ($self) = @_;
310 1 return $self->rounds->current_round->current_hands->get_crib_player_hand_id();
311 }
312  
313 1 ▶sub set_player_hand_id {
Subroutine set_player_hand_id: called CC=1 SCAR=0.0
Pod documented
314 1 my ($self, $player, $id) = @_;
315 1 return $self->rounds->current_round->current_hands->set_player_hand_id($player, $id);
316 }
317  
318 1 ▶sub get_player_hand_id {
Subroutine get_player_hand_id: called CC=1 SCAR=0.0
Pod documented
319 1 my ($self, $player) = @_;
320 1 return $self->rounds->current_round->current_hands->get_player_hand_id($player);
321 }
322  
323 1 ▶sub set_crib_complete {
Subroutine set_crib_complete: called CC=1 SCAR=0.0
Pod documented
324 1 my ($self, $player, $id) = @_;
325 1 return $self->rounds->current_round->current_hands->set_crib_complete($player, $id);
326 }
327  
328 2 ▶sub crib_complete {
Subroutine crib_complete: called CC=1 SCAR=0.0
Pod documented
329 2 my ($self, $player) = @_;
330 2 return $self->rounds->current_round->current_hands->crib_complete;
331 }
332  
333 1 ▶sub best_run_play {
Subroutine best_run_play: called CC=1 SCAR=0.0
Pod documented
334 1 my ($self, $player) = @_;
335 1 return $self->rounds->current_round->best_run_play($player);
336 }
337  
338 1 ▶sub total_player_score {
Subroutine total_player_score: called CC=2 SCAR=7.1
Pod documented
339 1 my ($self, $player) = @_;
340 1 ▶ $player = ref $player ? $player->player : $player;
Branch: 1 branch
BranchTrueFalseTotal
ref $player ? : 0 1 1
341 1 return $self->rounds->current_round->score->$player;
342 }
343  
344 62 ▶sub set_crib_player {
Subroutine set_crib_player: called CC=3 SCAR=11.3
Pod documented
345 62 my ($self, $player) = @_;
346 62 ▶ $player = ref $player ? $player->player : $player;
Branch: 1 branch
BranchTrueFalseTotal
ref $player ? : 0 62 62
347 62 $self->rounds->current_round->current_hands->crib_player($player);
348 62 ▶ if ($self->rounds->current_round->current_hands->play) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rounds->current_round->current_hands->play) 62 0 62
349 62 $self->rounds->current_round->current_hands->play->next_to_play($player);
350 }
351 }
352  
353 1 ▶sub next_to_play_id {
Subroutine next_to_play_id: called CC=1 SCAR=0.0
Pod documented
354 1 my ($self) = @_;
355 1 $self->rounds->current_round->next_to_play_id($self);
356 }
357  
358 1 ▶sub next_to_play {
Subroutine next_to_play: called CC=1 SCAR=0.0
Pod documented
359 1 my ($self) = @_;
360 1 $self->rounds->current_round->next_to_play($self);
361 }
362  
363 0 ▶sub set_next_to_play {
Subroutine set_next_to_play: not called CC=1 SCAR=6.9
Pod documented
364 0 my ($self, $player) = @_;
365 0 $self->rounds->current_round->current_hands->play->next_to_play($player);
366 }
367  
368 1 ▶sub hand_play_history {
Subroutine hand_play_history: called CC=1 SCAR=0.0
Pod documented
369 1 my ($self) = @_;
370 1 $self->rounds->current_round->hand_play_history();
371 }
372  
373 0 ▶sub reset_hands {
Subroutine reset_hands: not called CC=1 SCAR=6.9
Pod documented
374 0 my ($self) = @_;
375 0 $self->rounds->current_round->reset_hands();
376 }
377  
378 1 ▶sub last_round_hands {
Subroutine last_round_hands: called CC=1 SCAR=0.0
Pod documented
379 1 my ($self) = @_;
380 1 return $self->rounds->current_round->history->[-2];
381 }
382  
383 12 1;
384  
385 __END__
« Cribbage/Round.pm ↑ Summary Cribbage/Deck/Card.pm »