BlackJack/Player.pm

filter: Statementstmt 30.3% 10 / 33 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 23.0% 3 / 13 Podpod 0.0% 0 / 10 totaltotal 19.7% 13 / 66 CC 5 SCAR 15.1
CC
5
Cov
25%
auto_count_cards
12.0
scenario
6.0
hand
6.0
CRAP 4.5
« BlackJack/Shoe.pm ↑ Summary BlackJack/Player/ExamplePlayer1.pm »
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 ▶use Games::Tournament::BlackJack::Utilities;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Games::Tournament::BlackJack::Shoe;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Constructors
10 0 ▶sub scenario {
Subroutine scenario: not called CC=2 SCAR=17.9
Pod undocumented
11 0 my $invocant = shift;
12 0 ▶ my $class = ref($invocant) || $invocant;
Condition0%0/3
ref $invocant || $invocant
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table0%0/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
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 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
35 0 return scenario(@_);
36 }
37  
38  
39  
40  
41 # Main API Calls ----------------
42  
43 # Simple API
44 0 ▶sub decide_simple {
Subroutine decide_simple: not called CC=1 SCAR=6.9
Pod undocumented
45 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 0 ▶sub decide_complex {
Subroutine decide_complex: not called CC=1 SCAR=6.9
Pod undocumented
52 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 ▶sub hand { return $_[0]->{'hand'} || []; }
Subroutine hand: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$_[0]{'hand'} || []
l!l
00
MC/DC0%0/1
$_[0]{'hand'} || []
$_[0]{'hand'}
Truth table0%0/2
A
A= $_[0]{'hand'}
Aresult
11
00
58  
59  
60 # utility functions ----------------
61 0 ▶sub myHandValue { return handValue($_[0]->hand()) }
Subroutine myHandValue: not called CC=1 SCAR=6.9
Pod undocumented
62 0 ▶sub myHandStr { return handStr($_[0]->hand()) }
Subroutine myHandStr: not called CC=1 SCAR=6.9
Pod undocumented
63  
64 0 ▶sub isHandSoft { return $_[0]->doesHandContain("Ace")}
Subroutine isHandSoft: not called CC=1 SCAR=6.9
Pod undocumented
65  
66 0 ▶sub doesHandContain {
Subroutine doesHandContain: not called CC=1 SCAR=6.9
Pod undocumented
67 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 0 ▶sub auto_count_cards {
Subroutine auto_count_cards: not called CC=3 SCAR=24.8
Pod undocumented
75 0 my $self = shift;
76 0 my $hand = shift;
77  
78 0 ▶ if ($self->{'autoCount'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"autoCount"}) 0 0 0
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 1;
87  
88 __END__
« BlackJack/Shoe.pm ↑ Summary BlackJack/Player/ExamplePlayer1.pm »