line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
2
|
|
24702
|
use Exporter; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
2457
|
|
6
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
7
|
|
|
|
|
|
|
our @EXPORT = qw( |
8
|
|
|
|
|
|
|
printCards |
9
|
|
|
|
|
|
|
printCardsNumbered |
10
|
|
|
|
|
|
|
deal |
11
|
|
|
|
|
|
|
openNewDeck |
12
|
|
|
|
|
|
|
openNewShoe |
13
|
|
|
|
|
|
|
setShoeSize |
14
|
|
|
|
|
|
|
noticeCards |
15
|
|
|
|
|
|
|
maybeNoticeCards |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $shoeSize = 2; # default number of decks in a shoe. |
19
|
|
|
|
|
|
|
@suits = qw(Spades Clubs Diamonds Hearts); |
20
|
|
|
|
|
|
|
@faceValues = qw(Ace 2 3 4 5 6 7 8 9 10 Jack Queen King); |
21
|
|
|
|
|
|
|
%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
|
|
|
|
|
|
|
sub setShoeSize { |
38
|
1
|
|
|
1
|
0
|
7
|
my $newSize = shift; |
39
|
1
|
|
|
|
|
3
|
my $possibleSize = shift; |
40
|
1
|
50
|
|
|
|
5
|
if (ref $newSize) { |
41
|
|
|
|
|
|
|
# if the first arg turned out to be an object ref, use the second |
42
|
0
|
|
|
|
|
0
|
$newSize = $possibleSize; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
33
|
|
|
16
|
die "invalid shoe size (number of decks in shoe) [$newSize] must be an integer 1-10" |
|
|
|
33
|
|
|
|
|
46
|
|
|
|
|
|
|
unless ($newSize >= 1 and $newSize <= 10 and (int $newSize == $newSize)); |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
4
|
$shoeSize = $newSize; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
0
|
10
|
sub shoeSize { return $shoeSize; } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub openNewShoe { |
54
|
3
|
|
|
3
|
0
|
8
|
my @newShoe = (); |
55
|
3
|
|
|
|
|
12
|
foreach (0..$shoeSize) { |
56
|
11
|
|
|
|
|
15
|
push @newShoe, @{openNewDeck()}; |
|
11
|
|
|
|
|
29
|
|
57
|
|
|
|
|
|
|
} |
58
|
3
|
|
|
|
|
122
|
return bless [@newShoe]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub openNewDeck { |
62
|
12
|
|
|
12
|
0
|
20
|
my @newDeck = (); |
63
|
12
|
|
|
|
|
22
|
foreach $suit (@suits) { |
64
|
48
|
|
|
|
|
78
|
foreach $value (@faceValues) { |
65
|
624
|
|
|
|
|
1160
|
push @newDeck, ($value . "_of_" . $suit); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
12
|
|
|
|
|
302
|
return bless [@newDeck]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
@dek = @{openNewShoe()}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub noticeCards { |
74
|
0
|
|
|
0
|
0
|
0
|
my $cards = $_[0]; |
75
|
0
|
|
|
|
|
0
|
my %noticed = %${$_[1]}; |
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
foreach my $card (@$cards) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
0
|
$noticed{$card}++; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub maybeNoticeCards { |
84
|
0
|
|
|
0
|
0
|
0
|
my $cards = $_[0]; |
85
|
0
|
|
|
|
|
0
|
my $noticed = %${$_[1]}; |
|
0
|
|
|
|
|
0
|
|
86
|
0
|
|
|
|
|
0
|
my $noticeLikelyhood = $_[2]; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
0
|
if ($noticeLikelyhood >= 1) |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
|
|
0
|
$noticeLikelyhood = 0; |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
0
|
foreach my $card (@$cards) |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
0
|
|
|
|
0
|
if ( (rand 1) > $noticeLikelyhood) |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
|
|
0
|
$noticed{$card}++; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub deal { |
102
|
0
|
|
|
0
|
0
|
0
|
my $numToDeal = $_[0]; |
103
|
0
|
|
|
|
|
0
|
my $from = $_[1]; |
104
|
0
|
|
|
|
|
0
|
my $to = $_[2]; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
foreach (1..$numToDeal) |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
0
|
|
|
0
|
my $card = pop @{$from} || die "card not dealt from empty deck $from [@$from] to $to [@$to]"; |
109
|
0
|
|
|
|
|
0
|
push @{$to}, $card; |
|
0
|
|
|
|
|
0
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub shuffle { |
114
|
1
|
|
|
1
|
0
|
620
|
my $self = shift; |
115
|
1
|
|
|
|
|
2
|
my $shuffleThoroughness = 8; # min for good shuffle |
116
|
1
|
|
|
|
|
3
|
my $i; |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
5
|
foreach (1..($shuffleThoroughness)) { |
119
|
8
|
|
|
|
|
27
|
for ($i = scalar (@$self); --$i; ) { |
120
|
408
|
|
|
|
|
649
|
my $j = int rand ($i + 1); |
121
|
408
|
100
|
|
|
|
850
|
next if $i == $j; |
122
|
378
|
|
|
|
|
10655
|
($$self[$i], $$self[$j]) = ($$self[$j], $$self[$i]); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
|
|
12
|
return $self; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub sprintCards { |
130
|
4
|
|
|
4
|
0
|
2875
|
my $self = $_[0]; |
131
|
4
|
|
|
|
|
11
|
my $hand; |
132
|
4
|
100
|
|
|
|
16
|
if (ref $self eq 'Games::Tournament::BlackJack::Shoe') { |
133
|
3
|
|
|
|
|
6
|
$hand = $self; |
134
|
|
|
|
|
|
|
} else { |
135
|
1
|
50
|
|
|
|
5
|
if (@_) { |
136
|
1
|
|
|
|
|
4
|
$hand = bless [@_]; |
137
|
|
|
|
|
|
|
} else { |
138
|
0
|
|
|
|
|
0
|
$hand = bless []; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
4
|
|
|
|
|
8
|
my $output = ""; |
143
|
|
|
|
|
|
|
|
144
|
4
|
|
|
|
|
9
|
foreach my $card (@$hand) { |
145
|
158
|
|
|
|
|
270
|
$card =~ s/_/ /g; |
146
|
158
|
|
|
|
|
1594
|
$output .= "\t\t$card\n"; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
4
|
|
|
|
|
33
|
return $output; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub printCards { |
153
|
0
|
|
|
0
|
0
|
|
print sprintCards(@_); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub sprintCardsNumbered { |
158
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub printCardsNumbered { |
172
|
0
|
|
|
0
|
0
|
|
print sprintCardsNumbered(@_); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |