| 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
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant
$invocant
Truth table0%0/3
A || B
A= ref $invocantB= $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 | 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'} || []
MC/DC0%0/1
$_[0]{'hand'} || []
$_[0]{'hand'}
Truth table0%0/2
A
A= $_[0]{'hand'}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||