blib/lib/Games/Cards/ShuffleTrack.pm

filter: Statementstmt 98.1% 312 / 318 Branchbran 97.3% 109 / 112 Conditioncond 96.3% 26 / 27 MC/DCmcdc 80.0% 12 / 15 Subroutinesub 100% 53 / 53 Podpod 100% 33 / 33 totaltotal 97.6% 545 / 558 CC 71 SCAR 12.1
CC
71
Cov
98%
run
7.0
deal
6.1
_count_all
5.0
CRAP 3.4
↑ Summary
1 package Games::Cards::ShuffleTrack;
2  
3 16 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 ▶use List::Util qw/any min/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use List::MoreUtils qw/zip first_index/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Games::Cards::ShuffleTrack - Track cards through shuffles and cuts
14  
15 =head1 VERSION
16  
17 Version 0.03_4
18  
19 =cut
20  
21 16 our $VERSION = '0.03_4';
22  
23 16 my $cut_limits = {
24 normal => [0.19, 0.82], # on a 52 cards deck, cut between 10 and 43 cards
25 short => [0.09, 0.28], # on a 52 cards deck, cut between 5 and 15 cards
26 center => [0.36, 0.59], # on a 52 cards deck, cut between 19 and 31 cards
27 deep => [0.67, 0.86], # on a 52 cards deck, cut between 35 and 45 cards
28 };
29  
30 16 my $decks = {
31 empty => [],
32 new_deck_order => [qw/AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH
33 AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC
34 KD QD JD 10D 9D 8D 7D 6D 5D 4D 3D 2D AD
35 KS QS JS 10S 9S 8S 7S 6S 5S 4S 3S 2S AS/],
36 fournier => [qw/AS 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS
37 AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH
38 KD QD JD 10D 9D 8D 7D 6D 5D 4D 3D 2D AD
39 KC QC JC 10C 9C 8C 7C 6C 5C 4C 3C 2C AC/],
40 };
41  
42 16 my $shortcuts = {
43 'top' => 1,
44 'second' => 2,
45 'greek' => -2,
46 'bottom' => -1,
47 };
48  
49 16 my $expressions = {
50 A => qr/A[CHSD]/,
51 2 => qr/2[CHSD]/,
52 3 => qr/3[CHSD]/,
53 4 => qr/4[CHSD]/,
54 5 => qr/5[CHSD]/,
55 6 => qr/6[CHSD]/,
56 7 => qr/7[CHSD]/,
57 8 => qr/8[CHSD]/,
58 9 => qr/9[CHSD]/,
59 10 => qr/10[CHSD]/,
60 J => qr/J[CHSD]/,
61 Q => qr/Q[CHSD]/,
62 K => qr/K[CHSD]/,
63  
64 C => qr/(?:[A23456789JQK]|10)C/,
65 H => qr/(?:[A23456789JQK]|10)H/,
66 S => qr/(?:[A23456789JQK]|10)S/,
67 D => qr/(?:[A23456789JQK]|10)D/,
68 };
69  
70  
71 =head1 SYNOPSIS
72  
73 This module allows you to simulate shuffles and cuts.
74  
75 use Games::Cards::ShuffleTrack;
76  
77 my $deck = Games::Cards::ShuffleTrack->new();
78  
79 $deck->overhand_shuffle( 2 );
80 $deck->riffle_shuffle();
81 $deck->cut( 'short' );
82 $deck->riffle_shuffle();
83 print "@{$deck->get_deck()}";
84  
85 Or perhaps with more precision:
86  
87 my $deck = Games::Cards::ShuffleTrack->new();
88  
89 $deck->faro_in();
90 $deck->cut( 26 );
91 print $deck->get_deck();
92  
93 See the rest of the documentation for more advanced features. See the examples folder for more detailed usage.
94  
95  
96 =head1 INSTALLATION
97  
98 To install this module, run the following commands:
99  
100 perl Makefile.PL
101 make
102 make test
103 make install
104  
105  
106 =head1 DECK REPRESENTATION
107  
108 At the moment a deck is represented as a list of strings; each string represents a card where the first letter or digit (or digits, in the case of a 10) is the value of the card and the following letter is the suit:
109  
110 C - Clubs
111 H - Hearts
112 S - Spades
113 D - Diamonds
114  
115 As an example, some card representations:
116  
117 AC - Ace of Clubs
118 10S - Ten of Spades
119 4D - 4 of Diamonds
120 KH - King of Hearts
121  
122 Still, you can add whichever cards you want to the deck:
123  
124 $deck->put( 'Joker' ); # place a Joker on top of the deck
125  
126  
127 =head1 SUBROUTINES/METHODS
128  
129 =head2 Standard methods
130  
131 =head3 new
132  
133 Create a new deck.
134  
135 my $deck = Games::Cards::ShuffleTrack->new();
136  
137 The order of the deck is from top to bottom, which means it is the reverse of what you see when you spread a deck in your hands with the cards facing you.
138  
139 When you open most professional decks of cards you'll see the Ace of Spades (AS) in the front; this means it will actually be the 52nd card in the deck, since when you place the cards on the table facing down it will be the bottom card.
140  
141 Currently this module doesn't support specific orders or different orders other than the new deck.
142  
143 The order of the cards is as follows:
144  
145 Ace of Hearths through King of Hearts
146 Ace of Clubs through King of Clubs
147 King of Diamonds through Ace of Diamonds
148 King of Spades through Ace of Spades
149  
150 You can also specify the starting order of the deck among the following:
151  
152 =over 4
153  
154 =item * new_deck_order (the default order)
155  
156 =item * fournier
157  
158 =back
159  
160 my $deck = Games::Cards::ShuffleTrack->new( 'fournier' );
161  
162 You can also set your own order:
163  
164 my $pile = Games::Cards::ShufleTrack->new( [qw/10S JS QS KS AS/] );
165  
166 =cut
167  
168 # TODO: What happens if the user has a typo in the order?
169 sub new {
170 35 ▶ my ($self, $order) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
171 35 ▶ $order ||= 'new_deck_order';
Condition100%2/2
$order ||= "new_deck_order"
l!l
1916
MC/DC100%1/1
$order ||= "new_deck_order"
$order
Truth table100%2/2
A
A= $order
Aresult
11
00
172  
173 35 my $cards;
174 35 ▶ if ( ref $order eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $order eq 'ARRAY') { } 1 34 35
175 1 $cards = $order;
176 }
177 else {
178 34 $cards = $decks->{ $order };
179 }
180  
181 35 return bless {
182 'deck' => $cards,
183 'original' => $cards,
184 'orientation' => 'down',
185 }, $self;
186 }
187  
188 =head3 restart
189  
190 Reset the deck to its original status. The original is whatever you selected when you created the deck.
191  
192 $deck->restart;
193  
194 Do bear in mind that by doing so you are replenishing the deck of whatever cards you took out of it.
195  
196 =cut
197  
198 sub restart {
199 112 ▶ my $self = shift;
Subroutine restart: called CC=1 SCAR=0.0
Pod documented
200 112 return $self->_set_deck( @{$self->{'original'}} );
201 }
202  
203  
204 =head3 size, deck_size
205  
206 Returns the size of the deck.
207  
208 my $size = $deck->deck_size;
209  
210 =cut
211  
212 sub size {
213 49 ▶ my $self = shift;
Subroutine size: called CC=1 SCAR=0.0
Pod documented
214 49 return $self->deck_size;
215 }
216  
217 sub deck_size {
218 601 ▶ my $self = shift;
Subroutine deck_size: called CC=1 SCAR=0.0
Pod documented
219 601 return scalar @{$self->{'deck'}};
220 }
221  
222  
223 =head3 original_size
224  
225 Returns the original size of the deck.
226  
227 if ($size < 0.5 * $deck->original_size) {
228 # if the deck has been exausted by over 50%
229 }
230  
231 =cut
232  
233 sub original_size {
234 4 ▶ my $self = shift;
Subroutine original_size: called CC=1 SCAR=0.0
Pod documented
235 4 return scalar @{$self->{'original'}};
236 }
237  
238  
239 =head3 get_deck
240  
241 Returns the deck (a reference to a list of strings).
242  
243 my $cards = $deck->get_deck();
244  
245 =cut
246  
247 # TODO: should we return a copy of the list instead of the list itself?
248 # TODO: use wantarray to allow for an array to be returned?
249 sub get_deck {
250 1177 ▶ my $self = shift;
Subroutine get_deck: called CC=1 SCAR=0.0
Pod documented
251 1177 return $self->{'deck'};
252 }
253  
254  
255 =head3 orientation
256  
257 Return whether the deck is face up or face down:
258  
259 if ( $deck->orientation eq 'down' ) {
260 ...
261 }
262  
263 The deck's orientation is either 'up' or 'down'.
264  
265 =cut
266  
267 sub orientation {
268 17 ▶ my $self = shift;
Subroutine orientation: called CC=1 SCAR=0.0
Pod documented
269  
270 17 return $self->{'orientation'};
271 }
272  
273  
274 =head3 turn
275  
276 If the deck was face up, it is turned face down; if the deck was face down, it is turned face up.
277  
278 Turning the deck reverses its order.
279  
280 $deck->turn;
281  
282 =cut
283  
284 sub turn {
285 14 ▶ my $self = shift;
Subroutine turn: called CC=2 SCAR=6.9
Pod documented
286  
287 14 ▶ $self->{'orientation'} = $self->orientation eq 'down' ? 'up' : 'down';
Branch: 1 branch
BranchTrueFalseTotal
$self->orientation eq 'down' ? : 10 4 14
288  
289 14 return $self->_set_deck( reverse @{$self->get_deck} );
290 }
291  
292 =head3 count
293  
294 Counts how many cards with specific characteristics are in the deck.
295  
296 # how many tens
297 $deck->count( '10' );
298  
299 # how many Clubs
300 $deck->count( 'C' );
301  
302 # how many Clubs and Hearts
303 my ($clubs, $hearts) = $deck->count( 'C', 'H' );
304 my $clubs_and_hearts = $deck->count( 'C', 'H' );
305  
306 # how many Jokers
307 $deck->count( 'Joker' );
308  
309 Since you can add whichever card you want to the deck, it should be noted how searching for values and suits works:
310  
311 =over 4
312  
313 =item * If looking for a value from 2 to A, you'll get the amount of cards with that value and one of the four suits
314  
315 =item * If looking for a suit (C, H, S, D), you'll get the amount of cards with a value from 2 through Ace and that suit
316  
317 =item * If looking for anything else, that something is compared to the whole card
318  
319 =back
320  
321 It is important to note:
322  
323 my $total = $deck->count( 'JC' ); # holds 4
324 my $total = $deck->count( 'C', J ); # holds 16, because the JC is only counted once
325 my @total = $deck->count( 'C', J ); # holds (13, 4)
326  
327 Also:
328  
329 $deck->put( 'Joker' );
330 $deck->put( 'Signed Joker' );
331 $deck->count( 'Joker' ); # returns 2
332  
333 $deck->put( 'Signed 4C' );
334 $deck->count( '4C' ); # returns 2, because you didn't removed the previous one
335  
336 =cut
337  
338 sub count {
339 33 ▶ my $self = shift;
Subroutine count: called CC=3 SCAR=11.0
Pod documented
340 33 my @results;
341  
342 33 ▶ if ( wantarray and @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray and @_ > 1) { } 3 30 33
Condition100%3/3
wantarray and @_ > 1
!ll&&!rl&&r
2913
MC/DC100%2/2
wantarray and @_ > 1
wantarray @_ > 1
Truth table100%3/3
A and B
A= wantarrayB= @_ > 1
ABresult
0X0
100
111
343 3 return $self->_count_each( @_ );
344 }
345 else {
346 30 return $self->_count_all( @_ );
347 }
348 }
349  
350 sub _count_each {
351 3 ▶ my $self = shift;
Subroutine _count_each: called CC=3 SCAR=11.0
352 3 my @results;
353 3 ▶ while (my $param = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $param = shift()) 6 3 9
354 6 ▶ if ( exists $expressions->{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $expressions->{$param}) { } 5 1 6
355 5 push @results, scalar grep { /$expressions->{$param}/ } @{$self->get_deck};
356 }
357 else {
358 1 push @results, scalar grep { /$param/ } @{$self->get_deck};
359 }
360 }
361 3 return @results;
362 }
363  
364 sub _count_all {
365 30 ▶ my $self = shift;
Subroutine _count_all: called CC=5 SCAR=16.1
366  
367 30 my @expressions;
368 30 for my $param (@_) {
369 push @expressions, exists $expressions->{$param} ?
370 35 ▶ $expressions->{$param} :
Branch: 1 branch
BranchTrueFalseTotal
exists $expressions->{$param} ? : 29 6 35
371 qr/$param/x,
372 }
373  
374 30 my @results;
375 30 for my $card (@{$self->get_deck}) {
376  
377 1586 ▶ if (any { $card =~ $_ } @expressions) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $card =~ /$_/; } , @expressions)) 211 1375 1586
378 211 push @results, $card;
379 }
380  
381 }
382 30 return scalar @results;
383 }
384  
385  
386 =head2 Shuffling
387  
388 =head3 Overhand Shuffle
389  
390 =head4 overhand_shuffle
391  
392 In an overhand shuffle the cards are moved from hand to the other in packets, the result being similar to that of running cuts (the difference being that the packets in an overhand shuffle may be smaller than the ones in a running cut sequence).
393  
394 $deck->overhand_shuffle;
395  
396 You can specify how many times you want to go through the deck (which is basically the same thing as calling the method that many times):
397  
398 $deck->overhand_shuffle( 2 );
399  
400 =cut
401  
402 sub overhand_shuffle {
403 6 ▶ my $self = shift;
Subroutine overhand_shuffle: called CC=4 SCAR=13.9
Pod documented
404 6 my $times = shift;
405  
406 6 ▶ if (not defined $times) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $times) 1 5 6
407 1 $times = 1;
408 }
409  
410 6 ▶ return $self if $times < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $times < 1 2 4 6
411  
412 4 $self->_packet_transfer( 1, 10 );
413  
414 4 ▶ return $times > 1 ?
Branch: 1 branch
BranchTrueFalseTotal
$times > 1 ? : 1 3 4
415 $self->overhand_shuffle( $times - 1 ) :
416 $self
417 }
418  
419  
420 =head4 run
421  
422 The act of running cards is similar to the overhand shuffle, but instead of in packets the cards are run singly.
423  
424 $deck->run( 10 );
425  
426 When running cards you can choose whether to drop those cards on the top or on the bottom of the deck. By default, the cards are moved to the bottom of the deck.
427  
428 $deck->run( 10, 'drop-top' );
429 $deck->run( 10, 'drop-bottom' );
430  
431 Running cards basically reverses their order.
432  
433 If no number is given then no cards are run.
434  
435 If we're doing multiple runs we can set everything at the same time:
436  
437 $deck->run( 4, 6, 2 );
438  
439 =cut
440  
441 # TODO: review this code
442 sub run {
443 15 ▶ my $self = shift;
Subroutine run: called CC=7 SCAR=19.5
Pod documented
444  
445 15 my @number_of_cards;
446 my $where_to_drop;
447  
448 15 ▶ while ( my $param = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $param = shift()) 18 15 33
449 18 ▶ if ( looks_like_number( $param ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($param)) { } 9 9 18
450 9 push @number_of_cards, $param;
451 }
452 else {
453 9 $where_to_drop = $param;
454 }
455 }
456  
457 15 ▶ @number_of_cards || return $self;
Branch: 1 branch
BranchTrueFalseTotal
@number_of_cards or return $self 7 8 15
458 8 ▶ $where_to_drop ||= 'drop-bottom';
Condition100%2/2
$where_to_drop ||= "drop-bottom"
l!l
35
MC/DC100%1/1
$where_to_drop ||= "drop-bottom"
$where_to_drop
Truth table100%2/2
A
A= $where_to_drop
Aresult
11
00
459  
460 8 my $number_of_cards = shift @number_of_cards;
461 8 ▶ $number_of_cards > 0 or return $self;
Branch: 1 branch
BranchTrueFalseTotal
$number_of_cards > 0 or return $self 1 7 8
462  
463 # take cards from top and reverse their order
464 7 my @deck = @{$self->get_deck};
465 7 my @run = reverse splice @deck, 0, $number_of_cards;
466  
467 7 ▶ if ( $where_to_drop eq 'drop-top' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($where_to_drop eq 'drop-top') { } 2 5 7
468 2 $self->_set_deck( @run, @deck );
469 }
470 else { # drop-bottom is the default
471 5 $self->_set_deck( @deck, @run );
472 }
473  
474 7 return $self->run( @number_of_cards, $where_to_drop );
475 }
476  
477  
478 =head3 Hindu Shuffle
479  
480 =head4 hindu_shuffle
481  
482 In a Hindu shuffle the cards are moved from hand to the other in packets, the result being similar to that of running cuts (the difference being that the packets in an overhand shuffle may be smaller than the ones in a running cut sequence).
483  
484 $deck->hindu_shuffle;
485  
486 You can specify how many times you want to go through the deck (which is basically the same thing as calling the method that many times):
487  
488 $deck->hindu_shuffle( 2 );
489  
490 The Hindu shuffle differs in result from the Overhand shuffle in that the packets are usually thicker; the reason for this is that while in the Overhand shuffle it's the thumb that grabs the cards (and the thumb can easily carry just one or two cards) in the Hindu shuffle it's more than one finger accomplishing this task, grabbing the deck by the sides, which makes it more difficult (hence, rare) to cut just one or two cards.
491  
492 =cut
493  
494 sub hindu_shuffle {
495 3 ▶ my $self = shift;
Subroutine hindu_shuffle: called CC=3 SCAR=11.0
Pod documented
496 3 ▶ my $times = shift || 1;
Condition100%2/2
shift() || 1
l!l
21
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
497  
498 3 $self->_packet_transfer( 4, 10 );
499  
500 3 ▶ return $times > 1 ?
Branch: 1 branch
BranchTrueFalseTotal
$times > 1 ? : 1 2 3
501 $self->hindu_shuffle( $times - 1 ) :
502 $self
503 }
504  
505 sub _packet_transfer {
506 9 ▶ my $self = shift;
Subroutine _packet_transfer: called CC=4 SCAR=13.9
507 9 my $min = shift;
508 9 my $max = shift;
509  
510 9 my @deck = @{$self->get_deck};
511  
512 9 my @new_deck;
513  
514 9 ▶ while ( @deck ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@deck) 92 9 101
515 92 ▶ if (@deck < $max) { $max = scalar @deck }
Branch: 1 branch
BranchTrueFalseTotal
if (@deck < $max) 22 70 92
516 92 ▶ if (@deck < $min) { $min = scalar @deck }
Branch: 1 branch
BranchTrueFalseTotal
if (@deck < $min) 5 87 92
517 92 unshift @new_deck, splice @deck, 0, _rand( $min, $max );
518 }
519  
520 9 return $self->_set_deck( @new_deck );
521 }
522  
523  
524 =head3 Riffle Shuffle
525  
526 =head4 riffle_shuffle
527  
528 Riffle shuffle the deck.
529  
530 $deck->riffle_shuffle();
531  
532 In the act of riffle shuffling a deck the deck is cut into two halves of approximately the same size; each half is riffled so that the cards of both halves interlace; these cards usually drop in groups of 1 to 5 cards.
533  
534 You can also decide where to cut the deck for the shuffle:
535  
536 $deck->riffle_shuffle( 'short' ); # closer to the top
537 $deck->riffle_shuffle( 'center' ); # near the center
538 $deck->riffle_shuffle( 'deep' ); # closer to the bottom
539 $deck->riffle_shuffle( 26 ); # precisely under the 26th card
540  
541 =cut
542  
543 # TODO: add an option for an out-shuffle
544 # TODO: add an option to control top or bottom stock
545 # TODO: when dropping cards, should we favor numbers 2 and 3?
546 # TODO: with a lot of cards, the riffle should be done breaking the deck in piles
547 sub riffle_shuffle {
548 5 ▶ my $self = shift;
Subroutine riffle_shuffle: called CC=3 SCAR=11.0
Pod documented
549 5 my $depth = shift;
550  
551 # cut the deck (left pile is the original top half)
552 5 my $cut_depth = _cut_depth( $self->deck_size, $depth );
553  
554 5 my @left_pile = @{$self->get_deck};
555 5 my @right_pile = splice @left_pile, $cut_depth;
556  
557 5 my @halves = ( \@left_pile, \@right_pile );
558  
559 # drop cards from the bottom of each half to the pile (1-5 at a time)
560 5 my @new_pile = ();
561 5 ▶ while ( @left_pile and @right_pile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@left_pile and @right_pile) 66 5 71
Condition100%3/3
@left_pile and @right_pile
!ll&&!rl&&r
4166
MC/DC100%2/2
@left_pile and @right_pile
@left_pile @right_pile
Truth table100%3/3
A and B
A= @left_pileB= @right_pile
ABresult
0X0
100
111
562 66 my $current_half = $halves[0];
563 66 my $number_of_cards = int(rand( min(5, scalar @$current_half) ))+1;
564  
565 66 unshift @new_pile, splice @$current_half, -$number_of_cards;
566  
567 66 @halves = reverse @halves;
568 }
569  
570 # drop the balance on top and set the deck to be the result
571 5 $self->_set_deck( @left_pile, @right_pile, @new_pile );
572  
573 5 return $self;
574 }
575  
576  
577 =head3 Faro shuffle
578  
579 In a faro shuffle the deck is split in half and the two halves are interlaced perfectly so that each card from one half is inserted in between two cards from the opposite half.
580  
581 =head4 faro out
582  
583 Faro out the deck.
584  
585 $deck->faro( 'out' );
586  
587 In a "faro out" the top and bottom cards remain in their original positions.
588  
589 Considering the positions on the cards from 1 to 52 the result of the faro would be as follows:
590  
591 1, 27, 2, 28, 3, 29, 4, 30, 5, 31, 6, 32, 7, 33, ...
592  
593 =head4 faro in
594  
595 Faro in the deck.
596  
597 $deck->faro( 'in' );
598  
599 In a "faro in" the top and bottom cards do not remain in their original positions (top card becomes second from the top, bottom card becomes second from the bottom).
600  
601 Considering the positions on the cards from 1 to 52 the result of the faro would be as follows:
602  
603 27, 1, 28, 2, 29, 3, 30, 4, 31, 5, 32, 6, 33, 7, ...
604  
605 =cut
606  
607 sub faro {
608 60 ▶ my $self = shift;
Subroutine faro: called CC=2 SCAR=6.9
Pod documented
609 60 my $faro = shift; # by default we're doing a faro out
610  
611 # TODO: what happens when the deck is odd-sized?
612 60 my @first_half = @{$self->get_deck};
613 60 my @second_half = splice @first_half, $self->deck_size / 2;
614  
615 60 ▶ $self->_set_deck(
Branch: 1 branch
BranchTrueFalseTotal
$faro eq 'in' ? : 52 8 60
616 $faro eq 'in' ?
617 zip @second_half, @first_half :
618 zip @first_half, @second_half
619 );
620  
621 60 return $self;
622 }
623  
624  
625 =head2 Cutting
626  
627 =head3 cut
628  
629 Cut the deck.
630  
631 $deck->cut();
632  
633 In a 52 cards deck, this would cut somewhere between 10 and 43 cards.
634  
635 Cut at a precise position (moving X cards from top to bottom):
636  
637 $deck->cut(26);
638  
639 If you try to cut to a position that doesn't exist nothing will happen (apart from a warning that you tried to cut to a non-existing position, of course).
640  
641 You can also cut at negative positions, meaning that you're counting from the bottom of the deck and cutting above that card. For instance, to cut the bottom two cards to the top:
642  
643 $deck->cut(-2);
644  
645 Additional ways of cutting:
646  
647 $deck->cut( 'short' ); # on a 52 cards deck, somewhere between 5 and 15 cards
648 $deck->cut( 'center' ); # on a 52 cards deck, somewhere between 19 and 31 cards
649 $deck->cut( 'deep' ); # on a 52 cards deck, somewhere between 35 and 45 cards
650  
651 =head3 cut_below
652  
653 You can cut below a specific card.
654  
655 $deck->cut_below( '9D' );
656  
657 If the desired card is already on the bottom of the deck nothing will happen.
658  
659 For more information on how to cut to a specific card please refer to the L<SEE ALSO> section of this documentation.
660  
661 =head3 cut_above
662  
663 You can cut above a specific card.
664  
665 $deck->cut_above( 'JS' );
666  
667 If the desired card is already on top of the deck nothing will happen.
668  
669 For more information on how to cut to a specific card please refer to the L<SEE ALSO> section of this documentation.
670  
671 =cut
672  
673 # TODO: delimit randomness of the cut between two numbers: $deck->cut( 1, 25 );
674 sub cut {
675 26 ▶ my $self = shift;
Subroutine cut: called CC=4 SCAR=14.3
Pod documented
676 26 my $position = shift;
677  
678 26 ▶ if ( defined $position
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position and &looks_like_number($position) and abs $position > $self->deck_size) 0 26 26
Condition83%5/6
defined $position and &looks_like_number($position) and abs $position > $self->deck_size
!ll&&!rl&&r
4220
defined $position and &looks_like_number($position)
!ll&&!rl&&r
1322
MC/DC0%0/3
defined $position and &looks_like_number($position) and abs $position > $self->deck_size
defined $position &looks_like_number($position) abs $position > $self->deck_size
Truth table75%3/4
A and B and C
A= defined $positionB= &looks_like_number($position)C= abs $position > $self->deck_size
ABCresult
0XX0
10X0
1100
1111
679 and looks_like_number( $position )
680 and abs($position) > $self->deck_size ) {
681 0 warn "Tried to cut the deck at a non-existing position ($position).\n";
682 0 return $self;
683 }
684  
685 26 my $cut_depth = _cut_depth( $self->deck_size, $position );
686  
687 26 my @deck = @{$self->get_deck};
688 26 unshift @deck, splice @deck, $cut_depth;
689  
690 26 return $self->_set_deck( @deck );
691 }
692  
693 sub cut_below {
694 5 ▶ my $self = shift;
Subroutine cut_below: called CC=1 SCAR=0.0
Pod documented
695 5 my $card = shift;
696  
697 5 return $self->cut( $self->find( $card ) );
698 }
699  
700 sub cut_above {
701 6 ▶ my $self = shift;
Subroutine cut_above: called CC=1 SCAR=0.0
Pod documented
702 6 my $card = shift;
703  
704 6 return $self->cut( $self->find( $card ) - 1 );
705 }
706  
707 =head3 cut_to
708  
709 Cuts a portion of the deck to another position
710  
711 $deck->cut_to( $pile );
712  
713 You can specify exactly how many cards to cut or delimit the randomness of the cut:
714  
715 # cut exactly 15 cards to $pile
716 $deck->cut_to( $pile, 15 );
717  
718 # cut between 10 and 26 cards to $pile
719 $deck->cut_to( $pile, 10, 26 );
720  
721 If the position doesn't exist yet you can also automatically create it:
722  
723 my $pile = $deck->cut_to();
724  
725 This method returns the new pile.
726  
727 =cut
728  
729 sub cut_to {
730 19 ▶ my $self = shift;
Subroutine cut_to: called CC=5 SCAR=16.1
Pod documented
731  
732 # create the new pile if required
733 19 my $new_pile;
734 19 ▶ if ( defined($_[0]) and ref( $_[0] ) eq 'Games::Cards::ShuffleTrack' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and ref $_[0] eq 'Games::Cards::ShuffleTrack') { } 11 8 19
Condition100%3/3
defined $_[0] and ref $_[0] eq "Games::Cards::ShuffleTrack"
!ll&&!rl&&r
1711
MC/DC100%2/2
defined $_[0] and ref $_[0] eq "Games::Cards::ShuffleTrack"
defined $_[0] ref $_[0] eq "Games::Cards::ShuffleTrack"
Truth table100%3/3
A and B
A= defined $_[0]B= ref $_[0] eq "Games::Cards::ShuffleTrack"
ABresult
0X0
100
111
735 11 $new_pile = shift;
736 }
737 else {
738 8 $new_pile = Games::Cards::ShuffleTrack->new( 'empty' );
739 }
740  
741 # TODO: could this be done with _cut_depth? (perhaps changing it a bit)
742 # set the position
743 19 my $lower_limit = shift;
744 19 my $upper_limit = shift;
745  
746 19 my $position;
747  
748 19 ▶ if ( not defined $lower_limit ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $lower_limit) { } 2 17 19
elsif (not defined $upper_limit) { } 10 7 17
749 2 $position = _rand( 1, $self->deck_size );
750 }
751 elsif ( not defined $upper_limit ) {
752 10 $position = $lower_limit;
753 }
754 else {
755 7 $position = _rand( $lower_limit, $upper_limit );
756 }
757  
758 # cut the deck
759 19 $new_pile->place_on_top( splice @{$self->get_deck}, 0, $position );
760  
761 19 return $new_pile;
762 }
763  
764  
765 =head3 place_on_top
766  
767 Places a pile of cards on top of the deck.
768  
769 $deck->place_on_top( qw/AS KS QS JS 10S/ );
770  
771 =cut
772  
773 # TODO place_on_top and put share similar code; review
774 sub place_on_top {
775 20 ▶ my $self = shift;
Subroutine place_on_top: called CC=1 SCAR=0.0
Pod documented
776 20 my @pile = @_;
777  
778 20 $self->_set_deck( @pile, @{$self->get_deck} );
779  
780 20 return $self;
781 }
782  
783 =head3 complete_cut, move_to
784  
785 Complete the cut by moving all cards from one deck onto another:
786  
787 $deck->complete_cut( $new_pile );
788
789 # or
790  
791 $deck->move_to( $table );
792  
793 =cut
794  
795 sub complete_cut {
796 7 ▶ my $self = shift;
Subroutine complete_cut: called CC=1 SCAR=0.0
Pod documented
797 7 my $destination = shift;
798  
799 7 $self->cut_to( $destination, $self->deck_size );
800  
801 7 return $self;
802 }
803  
804 sub move_to {
805 7 ▶ my $self = shift;
Subroutine move_to: called CC=1 SCAR=0.0
Pod documented
806  
807 7 return $self->complete_cut( @_ );
808 }
809  
810  
811 =head3 running_cuts
812  
813 Cut packets:
814  
815 $deck->running_cuts();
816  
817 To do the procedure twice:
818  
819 $deck->running_cuts( 2 );
820  
821 =cut
822  
823 sub running_cuts {
824 2 ▶ my $self = shift;
Subroutine running_cuts: called CC=3 SCAR=11.0
Pod documented
825 2 ▶ my $times = shift || 1;
Condition100%2/2
shift() || 1
l!l
11
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
826  
827 2 $self->_packet_transfer( 5, 15 );
828  
829 2 ▶ return $times > 1 ?
Branch: 1 branch
BranchTrueFalseTotal
$times > 1 ? : 1 1 2
830 $self->overhand_shuffle( $times - 1 ) :
831 $self
832 }
833  
834  
835 =head2 Handling cards
836  
837 There are a few different methods to track down cards.
838  
839 =head3 find
840  
841 Get the position of specific cards:
842  
843 my $position = $deck->find( 'AS' ); # find the position of the Ace of Spades
844  
845 my @positions = $deck->find( 'AS', 'KH' ); # find the position of two cards
846  
847 If a card is not present on the deck the position returned will be a 0.
848  
849 This method can also return the card at a specific position:
850  
851 my $card = $deck->find( 3 );
852  
853 You can also request a card in a negative position (i.e., from the bottom of the deck). To get the second to last card in the deck:
854  
855 $deck->find( -2 );
856  
857 If you're dealing five hands of poker from the top of the deck, for instance, you can easily find which cards will fall on the dealer's hand:
858  
859 $deck->find( 5, 10, 15, 20, 25 );
860  
861 =cut
862  
863 sub find {
864 419 ▶ my $self = shift;
Subroutine find: called CC=4 SCAR=13.9
Pod documented
865 419 my @cards = @_;
866  
867 419 my @results;
868  
869 419 my $deck = $self->get_deck();
870  
871 419 for my $card ( @cards ) {
872  
873 433 ▶ push @results, looks_like_number( $card )
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($card) ? : 369 64 433
874 ? $self->_find_card_by_position( $card )
875 : $self->_find_card_by_name( $card );
876  
877 }
878  
879 419 ▶ return wantarray ? @results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 33 386 419
880 }
881  
882 sub _find_card_by_position {
883 369 ▶ my $self = shift;
Subroutine _find_card_by_position: called CC=4 SCAR=13.9
884 369 my $card = shift;
885  
886 369 ▶ if ($card) {
Branch: 1 branch
BranchTrueFalseTotal
if ($card) { } 367 2 369
887 367 ▶ if ($card > 0) { $card--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($card > 0) 339 28 367
888 367 ▶ return $card > $self->deck_size - 1 ?
Branch: 1 branch
BranchTrueFalseTotal
$card > $self->deck_size - 1 ? : 3 364 367
889 q{} :
890 $self->get_deck->[ $card ];
891 }
892 else {
893 2 return q{};
894 }
895 }
896  
897 sub _find_card_by_name {
898 64 ▶ my $self = shift;
Subroutine _find_card_by_name: called CC=2 SCAR=6.9
899 64 my $card = shift;
900  
901 64 ▶ my $position = 1 + first_index { $_ eq $card } @{$self->get_deck};
Subroutine __ANON__: called CC=1 SCAR=0.0
902  
903 64 ▶ return $position ? $position : 0;
Branch: 1 branch
BranchTrueFalseTotal
$position ? : 59 5 64
904 }
905  
906  
907 =head3 find_card_before
908  
909 Finds the card immediately before another card:
910  
911 # return the card immediately before the Ace of Spades
912 $deck->find_card_before( 'AS' );
913  
914 If the specified card is on top of the deck you will get the card on the bottom of the deck.
915  
916 =cut
917  
918 sub find_card_before {
919 2 ▶ my $self = shift;
Subroutine find_card_before: called CC=2 SCAR=6.9
Pod documented
920 2 my $card = shift;
921  
922 2 my $position = $self->find( $card );
923  
924 2 ▶ if ($position == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position == 1) { } 1 1 2
925 1 return 0;
926 }
927 else {
928 1 return $self->find( $position - 1 );
929 }
930 }
931  
932  
933 =head3 find_card_after
934  
935 Finds the card immediately after another card:
936  
937 # return the card immediately after the King of Hearts
938 $deck->find_card_before( 'KH' );
939  
940 If the specified card is on the bottom of the deck you will get the card on the top of the deck.
941  
942 =cut
943  
944 sub find_card_after {
945 2 ▶ my $self = shift;
Subroutine find_card_after: called CC=2 SCAR=6.9
Pod documented
946 2 my $card = shift;
947  
948 2 my $position = 1 + $self->find( $card );
949
950 2 ▶ if ( $position > $self->deck_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position > $self->deck_size) 1 1 2
951 1 return 0;
952 }
953  
954 1 return $self->find( $self->find( $card ) + 1 );
955 }
956  
957  
958 =head3 distance
959  
960 Find the distance between two cards.
961  
962 To find the distance between the Ace of Spades and the King of Hearts:
963  
964 $deck->distance( 'AS', 'KH' );
965  
966 If the King of Hearts is just after the Ace of Spades, then the result is 1. If it's immediately before, the result is -1.
967  
968 =cut
969  
970 sub distance {
971 7 ▶ my $self = shift;
Subroutine distance: called CC=1 SCAR=0.0
Pod documented
972 7 my $first_card = shift;
973 7 my $second_card = shift;
974  
975 7 return $self->find( $second_card) - $self->find( $first_card );
976 }
977  
978  
979 =head3 put
980  
981 Put a card on top of the deck. This is a new card, and not a card already on the deck.
982  
983 $deck->put( $card );
984  
985 If the card was already on the deck, you now have a duplicate card.
986  
987 =cut
988  
989 sub put {
990 17 ▶ my $self = shift;
Subroutine put: called CC=1 SCAR=0.0
Pod documented
991 17 my $card = shift;
992  
993 17 $self->_set_deck( $card, @{$self->get_deck} );
994  
995 17 return $self;
996 }
997  
998  
999 =head3 insert
1000  
1001 Inserts a card in a specified position in the deck. If the position isn't specified than the card is inserted somewhere at random.
1002  
1003 # insert a Joker at position 20
1004 $deck->insert( 'Joker', 20 );
1005  
1006 # replace a card somewhere in the deck at random
1007 $deck->insert( $card );
1008  
1009 If the position doesn't exist the card will be replaced at the bottom of the deck.
1010  
1011 You can also add cards to negative positions, meaning that the resulting position will be that negative position:
1012  
1013 # insert card so that it ends up being the last one in the deck
1014 $deck->insert( $card, -1 );
1015  
1016 # insert card so that it ends up being the 10th from the bottom
1017 $deck->insert( $card, -10 );
1018  
1019 =cut
1020  
1021 # TODO: what if the user inserts at position 0?
1022 sub insert {
1023 7 ▶ my $self = shift;
Subroutine insert: called CC=4 SCAR=13.9
Pod documented
1024 7 my $card = shift;
1025 7 my $position = shift;
1026  
1027 7 ▶ if ( not defined $position ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $position) { } 1 6 7
elsif ($position > $self->deck_size) { } 1 5 6
elsif ($position < 0) { } 2 3 5
1028 1 $position = _rand( 1, $self->deck_size );
1029 }
1030 elsif ( $position > $self->deck_size ) {
1031 1 $position = $self->deck_size + 1;
1032 }
1033 elsif ( $position < 0 ) {
1034 2 $position = $self->deck_size + $position + 2;
1035 }
1036  
1037 7 splice @{$self->get_deck}, $position - 1, 0, $card;
1038  
1039 7 return $self;
1040 }
1041  
1042  
1043 =head3 deal
1044  
1045 Deals a card, removing it from the deck.
1046  
1047 my $removed_card = $deck->deal();
1048  
1049 Just as in regular gambling, you can deal cards from other positions:
1050  
1051 # deal the second card from the top
1052 my $card = $deck->deal( 'second' );
1053  
1054 # deal the second card from the bottom
1055 my $card = $deck->deal( 'greek' );
1056  
1057 # deal the card from the bottom of the deck
1058 my $card = $deck->deal( 'bottom' );
1059  
1060 For more information on false dealing see the L<SEE ALSO> section.
1061  
1062 If you're dealing cards to a pile you can actually state where you're dealing:
1063  
1064 $deck->deal( $pile );
1065  
1066 You can still do a false deal to a pile:
1067  
1068 $deck->deal( 'second', $pile );
1069  
1070 # or
1071  
1072 $deck->deal( $pile, 'second' );
1073  
1074 =cut
1075  
1076 # TODO: deal from an empty deck?
1077 sub deal {
1078 17 ▶ my $self = shift;
Subroutine deal: called CC=6 SCAR=18.0
Pod documented
1079  
1080 17 ▶ if (not $self->size) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->size) 0 17 17
1081 0 warn "Tried to deal without cards.\n";
1082 0 return $self;
1083 }
1084  
1085 17 my $deal = 'top';
1086 17 my $destination = undef;
1087 17 ▶ while (my $param = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $param = shift()) 25 17 42
1088 25 ▶ if ( ref( $param ) eq 'Games::Cards::ShuffleTrack' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $param eq 'Games::Cards::ShuffleTrack') { } 11 14 25
elsif (exists $shortcuts->{$param}) { } 13 1 14
1089 11 $destination = $param;
1090 }
1091 elsif ( exists $shortcuts->{$param} ) {
1092 13 $deal = $param;
1093 }
1094 }
1095  
1096 17 my $position = $shortcuts->{$deal};
1097  
1098 17 my $card = $self->remove( $position );
1099  
1100 17 ▶ if ( defined $destination ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $destination) { } 11 6 17
1101 11 return $destination->put( $card );
1102 }
1103 else {
1104 6 return $card;
1105 }
1106 }
1107  
1108 =head3 remove
1109  
1110 Removes a card from the deck.
1111  
1112 # remove the 4th card from the top
1113 my $card = $deck->remove( 4 );
1114  
1115 =cut
1116  
1117 # TODO: allow removal of several cards (do note that positions change as cards are removed)
1118 sub remove {
1119 74 ▶ my $self = shift;
Subroutine remove: called CC=2 SCAR=6.9
Pod documented
1120 74 my $position = shift;
1121  
1122 74 my @deck = @{$self->get_deck};
1123  
1124 74 ▶ if ($position > 0) { $position--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($position > 0) 67 7 74
1125  
1126 74 my $card = splice @deck, $position, 1;
1127  
1128 74 $self->_set_deck( @deck );
1129 74 return $card;
1130 }
1131  
1132  
1133 =head3 peek
1134  
1135 Peek at a position in the deck (this is essentially the same thing as &find()).
1136  
1137 # peek the top card
1138 my $card = $deck->peek( 1 );
1139  
1140 You can also peek the top and bottom card by using an alias:
1141  
1142 # peek the top card
1143 my $card = $deck->peek( 'top' );
1144  
1145 # peek the bottom card
1146 my $card = $deck->peek( 'bottom' );
1147  
1148 Negative indexes are also supported:
1149  
1150 # peek the second from bottom card
1151 my $card = $deck->peek( -2 );
1152  
1153 =cut
1154  
1155 sub peek {
1156 72 ▶ my $self = shift;
Subroutine peek: called CC=3 SCAR=11.0
Pod documented
1157 72 ▶ my $position = shift || 1;
Condition100%2/2
shift() || 1
l!l
711
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1158  
1159 72 ▶ if (_is_shortcut( $position )) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_shortcut($position)) 4 68 72
1160 4 $position = $shortcuts->{$position};
1161 }
1162  
1163 72 return $self->find( $position );
1164 }
1165  
1166  
1167 =head3 take_random
1168  
1169 Remove a random card from the deck.
1170  
1171 my $random_card = $deck->take_random();
1172  
1173 You can also specify limits (if you're somehow directing the person taking the card to a particular section of the deck):
1174  
1175 my $random_card = $deck->take_random( 13, 39 );
1176  
1177 =cut
1178  
1179 sub take_random {
1180 56 ▶ my $self = shift;
Subroutine take_random: called CC=3 SCAR=11.0
Pod documented
1181  
1182 56 ▶ my $lower_limit = shift || 1;
Condition100%2/2
shift() || 1
l!l
542
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1183 56 my $upper_limit = shift;
1184  
1185 56 ▶ $upper_limit = defined $upper_limit ?
Branch: 1 branch
BranchTrueFalseTotal
defined $upper_limit ? : 52 4 56
1186 $upper_limit :
1187 $self->deck_size;
1188  
1189 56 return $self->remove( _rand( $lower_limit, $upper_limit ) );
1190 }
1191  
1192 =head3 dribble
1193  
1194 Dribble the cards (usually to select one, which could either be the last one to fall or the one that would be next).
1195  
1196 # dribble cards onto $pile
1197 $deck->dribble( $pile );
1198  
1199 # same thing, but declaring $pile
1200 $pile = $deck->dribble;
1201  
1202 # dribble to position 10 (in a 52 card deck, 42 cards would fall)
1203 $deck->dribble( 10 );
1204  
1205 # dribble 10 cards
1206 $deck->dribble( -10 );
1207  
1208 # dribble to position between 10 and 20
1209 $deck->dribble( 10, 20 );
1210  
1211 # dribble to position between 10th from the top and 10th from the bottom
1212 $deck->dribble( 10, -10 );
1213  
1214 =cut
1215  
1216 # TODO: what happens if you're dribbling and have no cards?
1217 sub dribble {
1218 6 ▶ my $self = shift;
Subroutine dribble: called CC=5 SCAR=16.1
Pod documented
1219 6 my $params = _parse_params( @_ );
1220  
1221 6 my $has_destination = @{$params->{'places'}};
1222 my $destination = $has_destination ?
1223 6 ▶ $params->{'places'}[0] :
Branch: 1 branch
BranchTrueFalseTotal
$has_destination ? : 1 5 6
1224 Games::Cards::ShuffleTrack->new( 'empty' );
1225  
1226 6 my ($lower_limit, $upper_limit) = $self->_fix_limits( @{$params->{'numbers'}} );
1227  
1228 6 ▶ if ( defined $lower_limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lower_limit) { } 4 2 6
1229 4 $lower_limit = $self->size - $lower_limit;
1230 4 ▶ $upper_limit = defined $upper_limit ?
Branch: 1 branch
BranchTrueFalseTotal
defined $upper_limit ? : 2 2 4
1231 $self->size - $upper_limit :
1232 $lower_limit;
1233 }
1234 else {
1235 # FIXME: this means we can't dribble if we have just 5 cards
1236 2 $lower_limit = 5; # minimum amount of cards to hold back
1237 2 $upper_limit = $self->size - 5; # minimum amount of cards to dribble
1238 }
1239  
1240 6 $self->turn;
1241 6 my $transfer = $self->cut_to( $lower_limit, $upper_limit );
1242 6 $transfer->turn;
1243 6 $transfer->move_to( $destination );
1244  
1245 6 ▶ return $has_destination ? $self : $destination;
Branch: 1 branch
BranchTrueFalseTotal
$has_destination ? : 1 5 6
1246 }
1247  
1248 # subroutines
1249  
1250 # TODO: fix limits in other methods (just being used in dribble)
1251 sub _fix_limits {
1252 6 ▶ my $self = shift;
Subroutine _fix_limits: called CC=3 SCAR=11.0
1253 6 my @limits;
1254  
1255 6 ▶ while ( my $limit = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $limit = shift()) 6 6 12
1256 6 ▶ push @limits, $limit < 0 ? $self->size + $limit : $limit;
Branch: 1 branch
BranchTrueFalseTotal
$limit < 0 ? : 2 4 6
1257 }
1258  
1259 6 return @limits;
1260 }
1261  
1262 # TODO: use this for every method (just being used in dribble)
1263 sub _parse_params {
1264 6 ▶ my $params = {
Subroutine _parse_params: called CC=4 SCAR=14.1
1265 numbers => [],
1266 places => [],
1267 options => [],
1268 };
1269 6 ▶ while (my $param = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $param = shift()) 7 6 13
1270 7 ▶ if (looks_like_number($param)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_number($param)) { } 6 1 7
elsif (ref $param eq 'Games::Cards::ShuffleTrack') { } 1 0 1
1271 6 push @{$params->{'numbers'}}, $param;
1272 }
1273 elsif (ref $param eq 'Games::Cards::ShuffleTrack') {
1274 1 push @{$params->{'places'}}, $param;
1275 }
1276 else {
1277 0 push @{$params->{'options'}}, $param;
1278 }
1279 }
1280 6 return $params;
1281 }
1282  
1283 sub _set_deck {
1284 344 ▶ my $self = shift;
Subroutine _set_deck: called CC=1 SCAR=0.0
1285 344 return $self->{'deck'} = [@_];
1286 }
1287  
1288 sub _rand {
1289 166 ▶ my ($lower_limit, $upper_limit) = @_;
Subroutine _rand: called CC=1 SCAR=0.0
1290  
1291 166 return int($lower_limit + int(rand( $upper_limit - $lower_limit )));
1292 }
1293  
1294 sub _cut_depth {
1295 31 ▶ my $deck_size = shift;
Subroutine _cut_depth: called CC=3 SCAR=11.0
1296 31 my $position = shift;
1297  
1298 31 ▶ if (not defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $position) 5 26 31
1299 5 $position = 'normal';
1300 }
1301  
1302 31 ▶ if ( any { $_ eq $position } keys %$cut_limits ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq $position; } , keys %$cut_limits)) 8 23 31
1303 8 my ($lower, $upper) = @{$cut_limits->{ $position }};
1304 8 $position = _rand( $deck_size * $lower, $deck_size * $upper );
1305 }
1306  
1307 31 return $position;
1308 }
1309  
1310 sub _is_shortcut {
1311 72 ▶ my $shortcut = shift;
Subroutine _is_shortcut: called CC=1 SCAR=0.0
1312  
1313 72 return exists $shortcuts->{$shortcut};
1314 }
1315  
1316  
1317 =head1 GLOSSARY
1318  
1319 The following is not a comprehensive list of gambling terms; it is simply a list of some terms used somewhere in this module that may be useful.
1320  
1321 The text has been taken verbatim from The Expert at the Card Table.
1322  
1323 =over 4
1324  
1325 =item * Stock
1326  
1327 That portion of the deck that contains certain cards, placed in some particular order for dealing; or certain
1328 desirable cards placed at top or bottom of the deck.
1329  
1330 =item * Run
1331  
1332 To draw off one card at a time during the process of the hand shuffle. There is little or no difficulty in acquiring
1333 perfect ability to run the whole deck through in this manner with the utmost rapidity. The left thumb presses
1334 lightly on the top card, the right hand alone making the movement necessary to shuffle.
1335  
1336 =item * Break
1337  
1338 A space or division held in the deck. While shuffling it is held at the end by the right thumb. It is formed under
1339 the in-jog when about to under cut for the shuffle, by pushing the in-jog card slightly upwards with the right
1340 thumb, making a space of from an eighth to a quarter of an inch wide, and holding the space, by squeezing the
1341 ends of the packet to be drawn out, between the thumb and second and third fingers. The use of the break
1342 during a shuffle makes it possible to throw any number of cards that are immediately above it, in one packet
1343 into the left hand, without disarranging their order. The break is used when not shuffling, to locate any particular
1344 card or position, and is infinitely superior to the common method of inserting the little finger. A break can be
1345 held firmly by a finger or thumb of either hand, and entirely concealed by the other fingers of the same hand. It
1346 is also the principal aid in the blind riffles and cuts.
1347  
1348 =item * Throw
1349  
1350 To pass from the right hand to the left, during a shuffle, a certain number of cards in one packet, thereby
1351 retaining their order. A throw may be required at the beginning, during the process, or at the end of a shuffle;
1352 and the packet to be thrown may be located by the jog, or break, or by both.
1353  
1354 =item * Top Card
1355  
1356 The card on top of packet held in the left hand, or the original top card of the full deck, which about to be
1357 shuffled.
1358  
1359 =item * Riffle
1360  
1361 The modern method of shuffling on the table by springing, the ends of two packets into each other.
1362  
1363 =item * Crimp
1364  
1365 To bend one or a number of cards, so that they may be distinguished or located.
1366  
1367 =back
1368  
1369  
1370 =head1 AUTHOR
1371  
1372 Jose Castro, C<< <cog at cpan.org> >>
1373  
1374 =head1 BUGS
1375  
1376 Please report any bugs or feature requests to C<bug-games-cards-shuffletrack at rt.cpan.org>, or through
1377 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Cards-ShuffleTrack>. I will be notified, and then you'll
1378 automatically be notified of progress on your bug as I make changes.
1379  
1380  
1381 =head1 SUPPORT
1382  
1383 You can find documentation for this module with the perldoc command.
1384  
1385 perldoc Games::Cards::ShuffleTrack
1386  
1387  
1388 You can also look for information at:
1389  
1390 =over 4
1391  
1392 =item * Github
1393  
1394 L<https://github.com/cog/Games-Cards-ShuffleTrack>
1395  
1396 =item * Search CPAN
1397  
1398 L<http://search.cpan.org/dist/Games-Cards-ShuffleTrack/>
1399  
1400 =back
1401  
1402  
1403 =head1 SEE ALSO
1404  
1405 The following is an extremely small list of recommended books:
1406  
1407 =over 4
1408  
1409 =item * The Expert at the Card Table, by S. W. Erdnase
1410  
1411 =item * Card College, by Roberto Giobbi
1412  
1413 =back
1414  
1415  
1416 =head1 LICENSE AND COPYRIGHT
1417  
1418 Copyright 2016 Jose Castro.
1419  
1420 This program is free software; you can redistribute it and/or modify it
1421 under the terms of the the Artistic License (2.0). You may obtain a
1422 copy of the full license at:
1423  
1424 L<http://www.perlfoundation.org/artistic_license_2_0>
1425  
1426 Any use, modification, and distribution of the Standard or Modified
1427 Versions is governed by this Artistic License. By using, modifying or
1428 distributing the Package, you accept this license. Do not use, modify,
1429 or distribute the Package, if you do not accept this license.
1430  
1431 If your Modified Version has been derived from a Modified Version made
1432 by someone other than you, you are nevertheless required to ensure that
1433 your Modified Version complies with the requirements of this license.
1434  
1435 This license does not grant you the right to use any trademark, service
1436 mark, tradename, or logo of the Copyright Holder.
1437  
1438 This license includes the non-exclusive, worldwide, free-of-charge
1439 patent license to make, have made, use, offer to sell, sell, import and
1440 otherwise transfer the Package with respect to any patent claims
1441 licensable by the Copyright Holder that are necessarily infringed by the
1442 Package. If you institute patent litigation (including a cross-claim or
1443 counterclaim) against any party alleging that the Package constitutes
1444 direct or contributory patent infringement, then this Artistic License
1445 to you shall terminate on the date that such litigation is filed.
1446  
1447 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
1448 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
1449 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
1450 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
1451 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
1452 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
1453 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
1454 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1455  
1456  
1457 =cut
1458  
1459 16 1; # End of Games::Cards::ShuffleTrack
↑ Summary