line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Games::Tournament::BlackJack::Utilities.pm - Utility functions for blackjack |
2
|
|
|
|
|
|
|
# Author: Paul Jacobs, paul@pauljacobs.net |
3
|
|
|
|
|
|
|
package Games::Tournament::BlackJack::Player; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Games::Tournament::BlackJack::Utilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
6
|
1
|
|
|
1
|
|
6
|
use Games::Tournament::BlackJack::Shoe; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
7
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
496
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Constructors |
10
|
|
|
|
|
|
|
sub scenario { |
11
|
0
|
|
|
0
|
0
|
|
my $invocant = shift; |
12
|
0
|
|
0
|
|
|
|
my $class = ref($invocant) || $invocant; |
13
|
0
|
|
|
|
|
|
my $self = { |
14
|
|
|
|
|
|
|
'storage' => {}, # opaque storage for higher level processes. |
15
|
|
|
|
|
|
|
'hand' => [], |
16
|
|
|
|
|
|
|
'memory' => [], # recommended to start with a set of (up to) 13 integer counts of cards seen, degraded |
17
|
|
|
|
|
|
|
# proportionally to memory used. scalars only, no nested arrays or hashes allowed (?) |
18
|
|
|
|
|
|
|
# this count is automatically maintained unless auto_count is set to false |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
'autoCount' => 1, # when true, a card count will be automatically maintained in the first 13 memory spaces. |
21
|
|
|
|
|
|
|
# Aces are put in spot 13. Spot 1 keeps a running total count of all cards auto_counted. |
22
|
|
|
|
|
|
|
# Spot 0 is user defined, as are all entries past 13. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
'dealerUpcard' => '', |
25
|
|
|
|
|
|
|
'otherPlayerUpcards' => '', |
26
|
|
|
|
|
|
|
'numDecks' => $Games::Tournament::BlackJack::Shoe::shoeSize, # ideally this doesn't change after you create a player |
27
|
|
|
|
|
|
|
'options' => ['hit','stand'], # list of acceptable responses to a decide_complex |
28
|
|
|
|
|
|
|
# call, may include split, double.. |
29
|
|
|
|
|
|
|
@_, # Override previous (default) attributes |
30
|
|
|
|
|
|
|
}; |
31
|
0
|
|
|
|
|
|
return bless $self, $class; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
0
|
|
|
0
|
0
|
|
return scenario(@_); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Main API Calls ---------------- |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Simple API |
44
|
|
|
|
|
|
|
sub decide_simple { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
# by default it will always stay when given the chance. Not the best strategy. |
47
|
0
|
|
|
|
|
|
return 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Complex API |
51
|
|
|
|
|
|
|
sub decide_complex { |
52
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
return $self->decide_simple(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# accessors to try to avoid the _need_ for $self examination ---------------- |
57
|
0
|
|
0
|
0
|
0
|
|
sub hand { return $_[0]->{'hand'} || []; } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# utility functions ---------------- |
61
|
0
|
|
|
0
|
0
|
|
sub myHandValue { return handValue($_[0]->hand()) } |
62
|
0
|
|
|
0
|
0
|
|
sub myHandStr { return handStr($_[0]->hand()) } |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
0
|
|
sub isHandSoft { return $_[0]->doesHandContain("Ace")} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub doesHandContain { |
67
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
my $searchKey = firstLetter(shift); |
69
|
0
|
|
|
|
|
|
my $handString = $self->myHandStr(); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return ($handString =~ /$searchKey/); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub auto_count_cards { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my $hand = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ($self->{'autoCount'}) { |
79
|
0
|
|
|
|
|
|
foreach my $card (@$hand) { |
80
|
0
|
|
|
|
|
|
$self->{'memory'}->[Games::Tournament::BlackJack::Utilities::cardValue(uc($card))]++; # update specific-card total |
81
|
0
|
|
|
|
|
|
$self->{'memory'}->[1]++; # update total number of all cards counted |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |