BlackJack/Shoe.pm

filter: Statementstmt 58.5% 48 / 82 Branchbran 56.2% 9 / 16 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 53.8% 7 / 13 Podpod 0.0% 0 / 12 totaltotal 48.8% 66 / 135 CC 21 SCAR 19.3
CC
21
Cov
56%
maybeNoticeCards
20.0
deal
12.0
setShoeSize
7.1
CRAP 6.9
« BlackJack/Player/DealerPlayer.pm ↑ Summary BlackJack/Player.pm »
1 # Shoe.pm - perl module for manipulating shoes (one or more decks combined) of cards
2 # Author: Paul Jacobs, paul@pauljacobs.net
3 package Games::Tournament::BlackJack::Shoe;
4  
5 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our @ISA = qw(Exporter);
7 2 our @EXPORT = qw(
8 printCards
9 printCardsNumbered
10 deal
11 openNewDeck
12 openNewShoe
13 setShoeSize
14 noticeCards
15 maybeNoticeCards
16 );
17
18 2 our $shoeSize = 2; # default number of decks in a shoe.
19 2 @suits = qw(Spades Clubs Diamonds Hearts);
20 2 @faceValues = qw(Ace 2 3 4 5 6 7 8 9 10 Jack Queen King);
21 2 %facePoints = (
22 "Ace" => 1,
23 2 => 2,
24 3 => 3,
25 4 => 4,
26 5 => 5,
27 6 => 6,
28 7 => 7,
29 8 => 8,
30 9 => 9,
31 10 => 10,
32 "Jack" => 11,
33 "Queen" => 12,
34 "King" => 13,
35 );
36  
37 1 ▶sub setShoeSize {
Subroutine setShoeSize: called CC=5 SCAR=19.6
Pod undocumented
38 1 my $newSize = shift;
39 1 my $possibleSize = shift;
40 1 ▶ if (ref $newSize) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $newSize) 0 1 1
41 # if the first arg turned out to be an object ref, use the second
42 0 $newSize = $possibleSize;
43 }
44  
45 1 ▶ die "invalid shoe size (number of decks in shoe) [$newSize] must be an integer 1-10"
Branch: 1 branch
BranchTrueFalseTotal
unless $newSize >= 1 and $newSize <= 10 and int $newSize == $newSize 0 1 1
Condition33%2/6
$newSize >= 1 and $newSize <= 10 and int $newSize == $newSize
!ll&&!rl&&r
001
$newSize >= 1 and $newSize <= 10
!ll&&!rl&&r
001
MC/DC0%0/3
$newSize >= 1 and $newSize <= 10 and int $newSize == $newSize
$newSize >= 1 $newSize <= 10 int $newSize == $newSize
Truth table25%1/4
A and B and C
A= $newSize >= 1B= $newSize <= 10C= int $newSize == $newSize
ABCresult
0XX0
10X0
1100
1111
46 unless ($newSize >= 1 and $newSize <= 10 and (int $newSize == $newSize));
47
48 1 $shoeSize = $newSize;
49 }
50  
51 1 ▶sub shoeSize { return $shoeSize; }
Subroutine shoeSize: called CC=1 SCAR=0.0
Pod undocumented
52  
53 3 ▶sub openNewShoe {
Subroutine openNewShoe: called CC=2 SCAR=6.9
Pod undocumented
54 3 my @newShoe = ();
55 3 foreach (0..$shoeSize) {
56 11 push @newShoe, @{openNewDeck()};
57 }
58 3 return bless [@newShoe];
59 }
60  
61 12 ▶sub openNewDeck {
Subroutine openNewDeck: called CC=3 SCAR=11.0
Pod undocumented
62 12 my @newDeck = ();
63 12 foreach $suit (@suits) {
64 48 foreach $value (@faceValues) {
65 624 push @newDeck, ($value . "_of_" . $suit);
66 }
67 }
68 12 return bless [@newDeck];
69 }
70  
71 2 @dek = @{openNewShoe()};
72  
73 0 ▶sub noticeCards {
Subroutine noticeCards: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my $cards = $_[0];
75 0 my %noticed = %${$_[1]};
76
77 0 foreach my $card (@$cards)
78 {
79 0 $noticed{$card}++;
80 }
81 }
82  
83 0 ▶sub maybeNoticeCards {
Subroutine maybeNoticeCards: not called CC=4 SCAR=30.0
Pod undocumented
84 0 my $cards = $_[0];
85 0 my $noticed = %${$_[1]};
86 0 my $noticeLikelyhood = $_[2];
87
88 0 ▶ if ($noticeLikelyhood >= 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($noticeLikelyhood >= 1) 0 0 0
89 {
90 0 $noticeLikelyhood = 0;
91 }
92 0 foreach my $card (@$cards)
93 {
94 0 ▶ if ( (rand 1) > $noticeLikelyhood)
Branch: 1 branch
BranchTrueFalseTotal
if (rand 1 > $noticeLikelyhood) 0 0 0
95 {
96 0 $noticed{$card}++;
97 }
98 }
99 }
100  
101 0 ▶sub deal {
Subroutine deal: not called CC=3 SCAR=24.8
Pod undocumented
102 0 my $numToDeal = $_[0];
103 0 my $from = $_[1];
104 0 my $to = $_[2];
105
106 0 foreach (1..$numToDeal)
107 {
108 0 ▶ my $card = pop @{$from} || die "card not dealt from empty deck $from [@$from] to $to [@$to]";
Condition0%0/2
pop @{$from;} || die("card not dealt from empty deck $from [@$from] to $to [@$to]")
l!l
00
MC/DC0%0/1
pop @{$from;} || die("card not dealt from empty deck $from [@$from] to $to [@$to]")
pop @{$from;}
Truth table0%0/2
A
A= pop @{$from;}
Aresult
11
00
109 0 push @{$to}, $card;
110 }
111 }
112  
113 1 ▶sub shuffle {
Subroutine shuffle: called CC=4 SCAR=13.9
Pod undocumented
114 1 my $self = shift;
115 1 my $shuffleThoroughness = 8; # min for good shuffle
116 1 my $i;
117
118 1 foreach (1..($shuffleThoroughness)) {
119 8 ▶ for ($i = scalar (@$self); --$i; ) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$i) 408 8 416
120 408 my $j = int rand ($i + 1);
121 408 ▶ next if $i == $j;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $j 27 381 408
122 381 ($$self[$i], $$self[$j]) = ($$self[$j], $$self[$i]);
123 }
124 }
125  
126 1 return $self;
127 }
128  
129 4 ▶sub sprintCards {
Subroutine sprintCards: called CC=4 SCAR=13.9
Pod undocumented
130 4 my $self = $_[0];
131 4 my $hand;
132 4 ▶ if (ref $self eq 'Games::Tournament::BlackJack::Shoe') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq 'Games::Tournament::BlackJack::Shoe') { } 3 1 4
133 3 $hand = $self;
134 } else {
135 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 0 1
136 1 $hand = bless [@_];
137 } else {
138 0 $hand = bless [];
139 }
140 }
141
142 4 my $output = "";
143  
144 4 foreach my $card (@$hand) {
145 158 $card =~ s/_/ /g;
146 158 $output .= "\t\t$card\n";
147 }
148
149 4 return $output;
150 }
151  
152 0 ▶sub printCards {
Subroutine printCards: not called CC=1 SCAR=6.9
Pod undocumented
153 0 print sprintCards(@_);
154 }
155  
156  
157 0 ▶sub sprintCardsNumbered {
Subroutine sprintCardsNumbered: not called CC=2 SCAR=17.9
Pod undocumented
158 0 my $self = shift;
159 0 my @hand = @_;
160 0 my $output = "";
161  
162 0 my $index = 0;
163 0 foreach my $card (@hand) {
164 0 $output .= "$index: $card\n";
165 0 $index++;
166 }
167 0 return $output;
168 }
169  
170  
171 0 ▶sub printCardsNumbered {
Subroutine printCardsNumbered: not called CC=1 SCAR=6.9
Pod undocumented
172 0 print sprintCardsNumbered(@_);
173 }
174  
175 2 1;
« BlackJack/Player/DealerPlayer.pm ↑ Summary BlackJack/Player.pm »