lib/Console/Blackjack.pm

filter: Statementstmt 6.3% 25 / 397 Branchbran 0.0% 0 / 176 Conditioncond 0.0% 0 / 93 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 12.9% 8 / 62 Podpod 0.0% 0 / 54 totaltotal 3.9% 33 / 832 CC 123 SCAR 37.1
CC
123
Cov
4%
hand_value
132.0
draw_player_hand
132.0
player_is_done
90.0
CRAP 40.8
↑ Summary script/console-blackjack.pl »
1 package Console::Blackjack;
2  
3 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use experimental qw(signatures);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use open ':std', ':encoding(UTF-8)';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Console::Blackjack - A console-based implementation of Blackjack
15  
16 =head1 VERSION
17  
18 Version 0.02
19  
20 =cut
21  
22 1 our $VERSION = '0.02';
23  
24 =head1 SYNOPSIS
25  
26 This module lets you play Blackjack in your console.
27  
28 console-blackjack.pl
29  
30 =cut
31  
32 =head1 AUTHOR
33  
34 Greg Donald, C<< <gdonald at gmail.com> >>
35  
36 =head1 BUGS
37  
38 Please report any bugs or feature requests at https://github.com/gdonald/console-blackjack-perl/issues.
39  
40 =head1 SUPPORT
41  
42 You can find documentation for this module with the perldoc command.
43  
44 perldoc Console::Blackjack
45  
46 You can also look for information at:
47  
48 =over 4
49  
50 =item * CPAN Ratings
51  
52 L<https://cpanratings.perl.org/d/Console-Blackjack>
53  
54 =item * Search CPAN
55  
56 L<https://metacpan.org/release/Console-Blackjack>
57  
58 =back
59  
60 =head1 LICENSE AND COPYRIGHT
61  
62 This software is Copyright (c) 2022 by Greg Donald.
63  
64 This is free software, licensed under:
65  
66 The Artistic License 2.0 (GPL Compatible)
67  
68 =cut
69  
70 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 SAVE_FILE => 'bj.txt',
72 CARDS_IN_DECK => 52,
73 MAX_DECKS => 8,
74 MAX_PLAYER_HANDS => 7,
75 MIN_BET => 500,
76 MAX_BET => 10000000,
77 HARD => 0,
78 SOFT => 1,
79 WON => 2,
80 LOST => 3,
81 PUSH => 4,
82 PLAYER => 0,
83 DEALER => 1
84 1 };
85  
86 0 ▶sub is_ace ($card) {
Subroutine is_ace: not called CC=1 SCAR=6.9
Pod undocumented
87 0 !$card->{value};
88 }
89  
90 0 ▶sub is_ten ($card) {
Subroutine is_ten: not called CC=1 SCAR=6.9
Pod undocumented
91 0 $card->{value} > 8;
92 }
93  
94 0 ▶sub hand_value ( $hand, $method, $owner ) {
Subroutine hand_value: not called CC=11 SCAR=48.8
Pod undocumented
95 0 my $total = 0;
96  
97 0 for my $i ( 0 .. scalar( @{ $hand->{cards} } ) - 1 ) {
98 0 ▶ next if $owner == DEALER && $i == 1 && $hand->{hide_down_card};
Branch: 1 branch
BranchTrueFalseTotal
if $owner == 1 and $i == 1 and $hand->{"hide_down_card"} 0 0 0
Condition0%0/6
$owner == 1 and $i == 1 and $hand->{"hide_down_card"}
!ll&&!rl&&r
000
$owner == 1 and $i == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$owner == 1 and $i == 1 and $hand->{"hide_down_card"}
$owner == 1 $i == 1 $hand->{"hide_down_card"}
Truth table0%0/4
A and B and C
A= $owner == 1B= $i == 1C= $hand->{"hide_down_card"}
ABCresult
0XX0
10X0
1100
1111
99  
100 0 my $tmp_v = @{ $hand->{cards} }[$i]->{value} + 1;
101 0 ▶ my $v = $tmp_v > 9 ? 10 : $tmp_v;
Branch: 1 branch
BranchTrueFalseTotal
$tmp_v > 9 ? : 0 0 0
102  
103 0 ▶ $v = 11 if $method eq SOFT && $v == 1 && $total < 11;
Branch: 1 branch
BranchTrueFalseTotal
if $method eq 1 and $v == 1 and $total < 11 0 0 0
Condition0%0/6
$method eq 1 and $v == 1 and $total < 11
!ll&&!rl&&r
000
$method eq 1 and $v == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$method eq 1 and $v == 1 and $total < 11
$method eq 1 $v == 1 $total < 11
Truth table0%0/4
A and B and C
A= $method eq 1B= $v == 1C= $total < 11
ABCresult
0XX0
10X0
1100
1111
104 0 $total += $v;
105 }
106  
107 0 ▶ return hand_value( $hand, HARD, $owner ) if $method eq SOFT && $total > 21;
Branch: 1 branch
BranchTrueFalseTotal
if $method eq 1 and $total > 21 0 0 0
Condition0%0/3
$method eq 1 and $total > 21
!ll&&!rl&&r
000
MC/DC0%0/2
$method eq 1 and $total > 21
$method eq 1 $total > 21
Truth table0%0/3
A and B
A= $method eq 1B= $total > 21
ABresult
0X0
100
111
108  
109 0 $total;
110 }
111  
112 0 ▶sub player_is_busted ($player_hand) {
Subroutine player_is_busted: not called CC=2 SCAR=17.9
Pod undocumented
113 0 ▶ hand_value( $player_hand, SOFT, PLAYER ) > 21 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
hand_value($player_hand, 1, 0) > 21 ? : 0 0 0
114 }
115  
116 0 ▶sub is_blackjack ($cards) {
Subroutine is_blackjack: not called CC=6 SCAR=37.4
Pod undocumented
117 0 ▶ return 0 if scalar( @{$cards} ) != 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$cards;} != 2 0 0 0
118 0 ▶ return 1 if is_ace( @$cards[0] ) && is_ten( @$cards[1] );
Branch: 1 branch
BranchTrueFalseTotal
if is_ace(@$cards[0]) and is_ten(@$cards[1]) 0 0 0
Condition0%0/3
is_ace(@$cards[0]) and is_ten(@$cards[1])
!ll&&!rl&&r
000
MC/DC0%0/2
is_ace(@$cards[0]) and is_ten(@$cards[1])
is_ace(@$cards[0]) is_ten(@$cards[1])
Truth table0%0/3
A and B
A= is_ace(@$cards[0])B= is_ten(@$cards[1])
ABresult
0X0
100
111
119  
120 0 ▶ is_ace( @$cards[1] ) && is_ten( @$cards[0] ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
is_ace(@$cards[1]) && is_ten(@$cards[0]) ? : 0 0 0
Condition0%0/3
is_ace(@$cards[1]) and is_ten(@$cards[0])
!ll&&!rl&&r
000
MC/DC0%0/2
is_ace(@$cards[1]) and is_ten(@$cards[0])
is_ace(@$cards[1]) is_ten(@$cards[0])
Truth table0%0/3
A and B
A= is_ace(@$cards[1])B= is_ten(@$cards[0])
ABresult
0X0
100
111
121 }
122  
123 0 ▶sub player_can_hit ($player_hand) {
Subroutine player_can_hit: not called CC=6 SCAR=37.4
Pod undocumented
124 ( $player_hand->{played}
125 || $player_hand->{stood}
126 || 21 == hand_value( $player_hand, HARD, PLAYER )
127 || is_blackjack( $player_hand->{cards} )
128 0 ▶ || player_is_busted($player_hand) ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$player_hand->{'played'} || $player_hand->{'stood'} || 21 == hand_value($player_hand, 0, 0) || is_blackjack($player_hand->{'cards'}) || player_is_busted($player_hand) ? : 0 0 0
Condition0%0/12
$player_hand->{"played"} or $player_hand->{"stood"} or 21 == hand_value($player_hand, 0, 0) or is_blackjack($player_hand->{"cards"}) or player_is_busted($player_hand)
l!l&&r!l&&!r
000
$player_hand->{"played"} or $player_hand->{"stood"} or 21 == hand_value($player_hand, 0, 0) or is_blackjack($player_hand->{"cards"})
l!l&&r!l&&!r
000
$player_hand->{"played"} or $player_hand->{"stood"} or 21 == hand_value($player_hand, 0, 0)
l!l&&r!l&&!r
000
$player_hand->{"played"} or $player_hand->{"stood"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$player_hand->{"played"} or $player_hand->{"stood"} or 21 == hand_value($player_hand, 0, 0) or is_blackjack($player_hand->{"cards"}) or player_is_busted($player_hand)
$player_hand->{"played"} $player_hand->{"stood"} 21 == hand_value($player_hand, 0, 0) is_blackjack($player_hand->{"cards"}) player_is_busted($player_hand)
Truth table0%0/6
A or B or C or D or E
A= $player_hand->{"played"}B= $player_hand->{"stood"}C= 21 == hand_value($player_hand, 0, 0)D= is_blackjack($player_hand->{"cards"})E= player_is_busted($player_hand)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
129 }
130  
131 0 ▶sub player_can_stand ($player_hand) {
Subroutine player_can_stand: not called CC=4 SCAR=30.0
Pod undocumented
132 ( $player_hand->{stood}
133 || player_is_busted($player_hand)
134 0 ▶ || is_blackjack( $player_hand->{cards} ) ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$player_hand->{'stood'} || player_is_busted($player_hand) || is_blackjack($player_hand->{'cards'}) ? : 0 0 0
Condition0%0/6
$player_hand->{"stood"} or player_is_busted($player_hand) or is_blackjack($player_hand->{"cards"})
l!l&&r!l&&!r
000
$player_hand->{"stood"} or player_is_busted($player_hand)
l!l&&r!l&&!r
000
MC/DC0%0/3
$player_hand->{"stood"} or player_is_busted($player_hand) or is_blackjack($player_hand->{"cards"})
$player_hand->{"stood"} player_is_busted($player_hand) is_blackjack($player_hand->{"cards"})
Truth table0%0/4
A or B or C
A= $player_hand->{"stood"}B= player_is_busted($player_hand)C= is_blackjack($player_hand->{"cards"})
ABCresult
1XX1
01X1
0011
0000
135 }
136  
137 0 ▶sub all_bets ($game) {
Subroutine all_bets: not called CC=2 SCAR=17.9
Pod undocumented
138 0 my $bets = 0;
139  
140 0 for ( @{ $game->{player_hands} } ) {
141 0 $bets += $_->{bet};
142 }
143  
144 0 $bets;
145 }
146  
147 0 ▶sub shuffle ($shoe) {
Subroutine shuffle: not called CC=2 SCAR=17.9
Pod undocumented
148 0 ▶ for ( my $i = @{ ${$shoe} } ; --$i ; ) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$i) 0 0 0
149 0 my $j = int rand( $i + 1 );
150 0 @{ ${$shoe} }[ $i, $j ] = @{ ${$shoe} }[ $j, $i ];
151 }
152 }
153  
154 0 ▶sub new_shoe ( $game, $values ) {
Subroutine new_shoe: not called CC=5 SCAR=34.0
Pod undocumented
155 0 my $total_cards = $game->{num_decks} * CARDS_IN_DECK;
156  
157 0 $game->{shoe} = [];
158  
159 0 ▶ while ( scalar( @{ $game->{shoe} } ) < $total_cards ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$game->{"shoe"};} < $total_cards) 0 0 0
160 0 ▶ for ( my $suit = 0 ; $suit < 4 ; ++$suit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suit < 4) 0 0 0
161 0 ▶ last if scalar( @{ $game->{shoe} } ) >= $total_cards;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$game->{"shoe"};} >= $total_cards 0 0 0
162  
163 0 for ( @{$values} ) {
164 0 my %c = ( suit => $suit, value => $_ );
165 0 push @{ $game->{shoe} }, \%c;
166 }
167 }
168 }
169  
170 0 shuffle( \$game->{shoe} );
171 }
172  
173 0 ▶sub new_regular ($game) {
Subroutine new_regular: not called CC=1 SCAR=6.9
Pod undocumented
174 0 new_shoe( $game, [ 0 .. 12 ] );
175 }
176  
177 0 ▶sub new_aces ($game) {
Subroutine new_aces: not called CC=1 SCAR=6.9
Pod undocumented
178 0 new_shoe( $game, [0] );
179 }
180  
181 0 ▶sub new_jacks ($game) {
Subroutine new_jacks: not called CC=1 SCAR=6.9
Pod undocumented
182 0 new_shoe( $game, [10] );
183 }
184  
185 0 ▶sub new_aces_jacks ($game) {
Subroutine new_aces_jacks: not called CC=1 SCAR=6.9
Pod undocumented
186 0 new_shoe( $game, [ 0, 10 ] );
187 }
188  
189 0 ▶sub new_sevens ($game) {
Subroutine new_sevens: not called CC=1 SCAR=6.9
Pod undocumented
190 0 new_shoe( $game, [6] );
191 }
192  
193 0 ▶sub new_eights ($game) {
Subroutine new_eights: not called CC=1 SCAR=6.9
Pod undocumented
194 0 new_shoe( $game, [7] );
195 }
196  
197 0 ▶sub need_to_shuffle ($game) {
Subroutine need_to_shuffle: not called CC=4 SCAR=30.0
Pod undocumented
198 0 my $num_cards = $game->{num_decks} * CARDS_IN_DECK;
199 0 my $current_card = $num_cards - scalar( @{ $game->{shoe} } );
200 0 my $used = ( $current_card / $num_cards ) * 100.0;
201  
202 0 ▶ for ( my $x = 0 ; $x < MAX_DECKS ; ++$x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < 8) 0 0 0
203 0 my $spec = $game->{shuffle_specs}[$x];
204 0 ▶ return 1 if ( $game->{num_decks} == @$spec[1] && $used > @$spec[0] );
Branch: 1 branch
BranchTrueFalseTotal
if $game->{"num_decks"} == @$spec[1] and $used > @$spec[0] 0 0 0
Condition0%0/3
$game->{"num_decks"} == @$spec[1] and $used > @$spec[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$game->{"num_decks"} == @$spec[1] and $used > @$spec[0]
$game->{"num_decks"} == @$spec[1] $used > @$spec[0]
Truth table0%0/3
A and B
A= $game->{"num_decks"} == @$spec[1]B= $used > @$spec[0]
ABresult
0X0
100
111
205 }
206  
207 0 0;
208 }
209  
210 0 ▶sub deal_card ( $shoe, $cards ) {
Subroutine deal_card: not called CC=1 SCAR=6.9
Pod undocumented
211 0 my $card = pop( @{$shoe} );
212 0 push @{$cards}, $card;
213 }
214  
215 0 ▶sub dealer_upcard_is_ace ($dealer_hand) {
Subroutine dealer_upcard_is_ace: not called CC=1 SCAR=6.9
Pod undocumented
216 0 is_ace( $dealer_hand->{cards}[0] );
217 }
218  
219 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
220 0 system('export TERM=linux; clear');
221 }
222  
223 0 ▶sub card_face ( $game, $value, $suit ) {
Subroutine card_face: not called CC=2 SCAR=17.9
Pod undocumented
224 0 ▶ return $game->{faces2}[$value][$suit] if ( $game->{face_type} == 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $game->{"face_type"} == 2 0 0 0
225  
226 0 $game->{faces}[$value][$suit];
227 }
228  
229 0 ▶sub draw_dealer_hand ($game) {
Subroutine draw_dealer_hand: not called CC=4 SCAR=30.0
Pod undocumented
230 0 my $dealer_hand = $game->{dealer_hand};
231  
232 0 print(' ');
233  
234 0 ▶ for ( my $i = 0 ; $i < scalar( @{ $dealer_hand->{cards} } ) ; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$dealer_hand->{"cards"};}) 0 0 0
235 0 ▶ if ( $i == 1 && $dealer_hand->{hide_down_card} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 1 and $dealer_hand->{'hide_down_card'}) { } 0 0 0
Condition0%0/3
$i == 1 and $dealer_hand->{"hide_down_card"}
!ll&&!rl&&r
000
MC/DC0%0/2
$i == 1 and $dealer_hand->{"hide_down_card"}
$i == 1 $dealer_hand->{"hide_down_card"}
Truth table0%0/3
A and B
A= $i == 1B= $dealer_hand->{"hide_down_card"}
ABresult
0X0
100
111
236 0 printf( '%s ', card_face( $game, 13, 0 ) );
237 }
238 else {
239 0 my $card = $dealer_hand->{cards}[$i];
240 0 printf( '%s ', card_face( $game, $card->{value}, $card->{suit} ) );
241 }
242 }
243  
244 0 printf( ' ⇒ %u', hand_value( $dealer_hand, SOFT, DEALER ) );
245 }
246  
247 0 ▶sub draw_player_hand ( $game, $index ) {
Subroutine draw_player_hand: not called CC=11 SCAR=48.8
Pod undocumented
248 0 my $player_hand = $game->{player_hands}[$index];
249  
250 0 print(' ');
251  
252 0 ▶ for ( my $i = 0 ; $i < scalar( @{ $player_hand->{cards} } ) ; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$player_hand->{"cards"};}) 0 0 0
253 0 my $card = $player_hand->{cards}[$i];
254 0 printf( '%s ', card_face( $game, $card->{value}, $card->{suit} ) );
255 }
256  
257 0 printf( ' ⇒ %u ', hand_value( $player_hand, SOFT, PLAYER ) );
258  
259 0 ▶ if ( $player_hand->{status} == LOST ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($player_hand->{'status'} == 3) { } 0 0 0
elsif ($player_hand->{'status'} == 2) { } 0 0 0
260 0 print('-');
261 }
262 elsif ( $player_hand->{status} == WON ) {
263 0 print('+');
264 }
265  
266 0 printf( '$%.2f', $player_hand->{bet} / 100.0 );
267 print(' ⇐')
268 0 ▶ if ( !$player_hand->{played} && $index == $game->{current_player_hand} );
Branch: 1 branch
BranchTrueFalseTotal
if not $player_hand->{"played"} and $index == $game->{"current_player_hand"} 0 0 0
Condition0%0/3
not $player_hand->{"played"} and $index == $game->{"current_player_hand"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $player_hand->{"played"} and $index == $game->{"current_player_hand"}
not $player_hand->{"played"} $index == $game->{"current_player_hand"}
Truth table0%0/3
not(A) and B
A= not $player_hand->{"played"}B= $index == $game->{"current_player_hand"}
ABresult
0X0
100
111
269 0 print(' ');
270  
271 0 ▶ if ( $player_hand->{status} == LOST ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($player_hand->{'status'} == 3) { } 0 0 0
elsif ($player_hand->{'status'} == 2) { } 0 0 0
elsif ($player_hand->{'status'} == 4) { } 0 0 0
272 0 ▶ print( player_is_busted($player_hand) ? 'Busted!' : 'Lose!' );
Branch: 1 branch
BranchTrueFalseTotal
player_is_busted($player_hand) ? : 0 0 0
273 }
274 elsif ( $player_hand->{status} == WON ) {
275 0 ▶ print( is_blackjack( $player_hand->{cards} ) ? 'Blackjack!' : 'Won!' );
Branch: 1 branch
BranchTrueFalseTotal
is_blackjack($player_hand->{'cards'}) ? : 0 0 0
276 }
277 elsif ( $player_hand->{status} == PUSH ) {
278 0 print('Push');
279 }
280  
281 0 print("\n\n");
282 }
283  
284 0 ▶sub draw_hands ($game) {
Subroutine draw_hands: not called CC=2 SCAR=17.9
Pod undocumented
285 0 clear();
286 0 print("\n Dealer: \n");
287 0 draw_dealer_hand($game);
288 0 printf( "\n\n Player \$%.2f:\n", $game->{money} / 100.0 );
289  
290 0 ▶ for ( my $x = 0 ; $x < scalar( @{ $game->{player_hands} } ) ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < scalar @{$game->{"player_hands"};}) 0 0 0
291 0 draw_player_hand( $game, $x );
292 }
293 }
294  
295 0 ▶sub read_one_char ($matcher) {
Subroutine read_one_char: not called CC=3 SCAR=24.8
Pod undocumented
296 0 ▶ open( TTY, "+</dev/tty" ) or die "no tty: $!";
Branch: 1 branch
BranchTrueFalseTotal
open TTY, "+</dev/tty" or die "no tty: $!" 0 0 0
297 0 system 'stty raw -echo min 1 time 1';
298  
299 0 my $c;
300 0 while (1) {
301 0 $c = getc(TTY);
302 0 ▶ last if $c =~ $matcher;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /$matcher/u 0 0 0
303 }
304  
305 0 system 'stty sane';
306 0 $c;
307 }
308  
309 0 ▶sub need_to_play_dealer_hand ($game) {
Subroutine need_to_play_dealer_hand: not called CC=4 SCAR=30.0
Pod undocumented
310 0 ▶ for ( my $x = 0 ; $x < scalar( @{ $game->{player_hands} } ) ; ++$x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < scalar @{$game->{"player_hands"};}) 0 0 0
311 0 my $player_hand = $game->{player_hands}[$x];
312 return 1
313 if !(player_is_busted($player_hand)
314 0 ▶ || is_blackjack( $player_hand->{cards} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless player_is_busted($player_hand) or is_blackjack($player_hand->{"cards"}) 0 0 0
Condition0%0/3
player_is_busted($player_hand) or is_blackjack($player_hand->{"cards"})
l!l&&r!l&&!r
000
MC/DC0%0/2
player_is_busted($player_hand) or is_blackjack($player_hand->{"cards"})
player_is_busted($player_hand) is_blackjack($player_hand->{"cards"})
Truth table0%0/3
A or B
A= player_is_busted($player_hand)B= is_blackjack($player_hand->{"cards"})
ABresult
1X1
011
000
315 }
316  
317 0 0;
318 }
319  
320 0 ▶sub play_dealer_hand ($game) {
Subroutine play_dealer_hand: not called CC=5 SCAR=34.0
Pod undocumented
321 0 my $dealer_hand = $game->{dealer_hand};
322 $dealer_hand->{hide_down_card} = 0
323 0 ▶ if ( is_blackjack( $dealer_hand->{cards} ) );
Branch: 1 branch
BranchTrueFalseTotal
if is_blackjack($dealer_hand->{"cards"}) 0 0 0
324  
325 0 ▶ if ( !need_to_play_dealer_hand($game) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (need_to_play_dealer_hand($game)) 0 0 0
326 0 pay_hands($game);
327 0 return;
328 }
329  
330 0 $dealer_hand->{hide_down_card} = 0;
331  
332 0 my $soft_count = hand_value( $dealer_hand, SOFT, DEALER );
333 0 my $hard_count = hand_value( $dealer_hand, HARD, DEALER );
334  
335 0 ▶ while ( $soft_count < 18 && $hard_count < 17 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($soft_count < 18 and $hard_count < 17) 0 0 0
Condition0%0/3
$soft_count < 18 and $hard_count < 17
!ll&&!rl&&r
000
MC/DC0%0/2
$soft_count < 18 and $hard_count < 17
$soft_count < 18 $hard_count < 17
Truth table0%0/3
A and B
A= $soft_count < 18B= $hard_count < 17
ABresult
0X0
100
111
336 0 deal_card( $game->{shoe}, $dealer_hand->{cards} );
337 0 $soft_count = hand_value( $dealer_hand, SOFT, DEALER );
338 0 $hard_count = hand_value( $dealer_hand, HARD, DEALER );
339 }
340  
341 0 pay_hands($game);
342 }
343  
344 0 ▶sub no_insurance ($game) {
Subroutine no_insurance: not called CC=3 SCAR=24.8
Pod undocumented
345 0 ▶ if ( is_blackjack( $game->{dealer_hand}->{cards} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_blackjack($game->{"dealer_hand"}{"cards"})) 0 0 0
346 0 $game->{dealer_hand}->{hide_down_card} = 0;
347  
348 0 pay_hands($game);
349 0 draw_hands($game);
350 0 bet_options($game);
351 0 return;
352 }
353  
354 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
355  
356 0 ▶ if ( player_is_done( $game, $player_hand ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (player_is_done($game, $player_hand)) 0 0 0
357 0 play_dealer_hand($game);
358 0 draw_hands($game);
359 0 bet_options($game);
360 0 return;
361 }
362  
363 0 draw_hands($game);
364 0 player_get_action($game);
365 }
366  
367 0 ▶sub insure_hand ($game) {
Subroutine insure_hand: not called CC=1 SCAR=6.9
Pod undocumented
368 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
369  
370 0 $player_hand->{bet} /= 2;
371 0 $player_hand->{played} = 1;
372 0 $player_hand->{payed} = 1;
373 0 $player_hand->{status} = LOST;
374 0 $game->{money} -= $player_hand->{bet};
375  
376 0 draw_hands($game);
377 0 bet_options($game);
378 }
379  
380 0 ▶sub player_is_done ( $game, $player_hand ) {
Subroutine player_is_done: not called CC=9 SCAR=45.0
Pod undocumented
381 0 ▶ if ( $player_hand->{played}
Branch: 1 branch
BranchTrueFalseTotal
if ($player_hand->{"played"} or $player_hand->{"stood"} or is_blackjack($player_hand->{"cards"}) or player_is_busted($player_hand) or 21 == hand_value($player_hand, 1, 0) or 21 == hand_value($player_hand, 0, 0)) 0 0 0
Condition0%0/15
$player_hand->{"played"} or $player_hand->{"stood"} or is_blackjack($player_hand->{"cards"}) or player_is_busted($player_hand) or 21 == hand_value($player_hand, 1, 0) or 21 == hand_value($player_hand, 0, 0)
l!l&&r!l&&!r
000
$player_hand->{"played"} or $player_hand->{"stood"} or is_blackjack($player_hand->{"cards"}) or player_is_busted($player_hand) or 21 == hand_value($player_hand, 1, 0)
l!l&&r!l&&!r
000
$player_hand->{"played"} or $player_hand->{"stood"} or is_blackjack($player_hand->{"cards"}) or player_is_busted($player_hand)
l!l&&r!l&&!r
000
$player_hand->{"played"} or $player_hand->{"stood"} or is_blackjack($player_hand->{"cards"})
l!l&&r!l&&!r
000
$player_hand->{"played"} or $player_hand->{"stood"}
l!l&&r!l&&!r
000
MC/DC0%0/6
$player_hand->{"played"} or $player_hand->{"stood"} or is_blackjack($player_hand->{"cards"}) or player_is_busted($player_hand) or 21 == hand_value($player_hand, 1, 0) or 21 == hand_value($player_hand, 0, 0)
$player_hand->{"played"} $player_hand->{"stood"} is_blackjack($player_hand->{"cards"}) player_is_busted($player_hand) 21 == hand_value($player_hand, 1, 0) 21 == hand_value($player_hand, 0, 0)
Truth table0%0/7
A or B or C or D or E or F
A= $player_hand->{"played"}B= $player_hand->{"stood"}C= is_blackjack($player_hand->{"cards"})D= player_is_busted($player_hand)E= 21 == hand_value($player_hand, 1, 0)F= 21 == hand_value($player_hand, 0, 0)
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
382 || $player_hand->{stood}
383 || is_blackjack( $player_hand->{cards} )
384 || player_is_busted($player_hand)
385 || 21 == hand_value( $player_hand, SOFT, PLAYER )
386 || 21 == hand_value( $player_hand, HARD, PLAYER ) )
387 {
388  
389 0 $player_hand->{played} = 1;
390  
391 0 ▶ if ( !$player_hand->{payed} && player_is_busted($player_hand) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $player_hand->{"payed"} and player_is_busted($player_hand)) 0 0 0
Condition0%0/3
not $player_hand->{"payed"} and player_is_busted($player_hand)
!ll&&!rl&&r
000
MC/DC0%0/2
not $player_hand->{"payed"} and player_is_busted($player_hand)
not $player_hand->{"payed"} player_is_busted($player_hand)
Truth table0%0/3
not(A) and B
A= not $player_hand->{"payed"}B= player_is_busted($player_hand)
ABresult
0X0
100
111
392 0 $player_hand->{payed} = 1;
393 0 $player_hand->{status} = LOST;
394 0 $game->{money} -= $player_hand->{bet};
395 }
396  
397 0 return 1;
398 }
399  
400 0 0;
401 }
402  
403 0 ▶sub normalize_bet ($game) {
Subroutine normalize_bet: not called CC=4 SCAR=30.0
Pod undocumented
404 0 ▶ $game->{current_bet} = MIN_BET if $game->{current_bet} < MIN_BET;
Branch: 1 branch
BranchTrueFalseTotal
if $game->{"current_bet"} < 500 0 0 0
405 0 ▶ $game->{current_bet} = MAX_BET if $game->{current_bet} > MAX_BET;
Branch: 1 branch
BranchTrueFalseTotal
if $game->{"current_bet"} > 10000000 0 0 0
406  
407 $game->{current_bet} = $game->{money}
408 0 ▶ if $game->{current_bet} > $game->{money};
Branch: 1 branch
BranchTrueFalseTotal
if $game->{"current_bet"} > $game->{"money"} 0 0 0
409 }
410  
411 0 ▶sub dealer_is_busted ($dealer_hand) {
Subroutine dealer_is_busted: not called CC=2 SCAR=17.9
Pod undocumented
412 0 ▶ hand_value( $dealer_hand, SOFT, DEALER ) > 21 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
hand_value($dealer_hand, 1, 1) > 21 ? : 0 0 0
413 }
414  
415 0 ▶sub pay_hands ($game) {
Subroutine pay_hands: not called CC=7 SCAR=40.3
Pod undocumented
416 0 my $dealer_hand = $game->{dealer_hand};
417 0 my $dhv = hand_value( $dealer_hand, SOFT, DEALER );
418 0 my $dhb = dealer_is_busted($dealer_hand);
419  
420 0 ▶ for ( my $x = 0 ; $x < scalar( @{ $game->{player_hands} } ) ; ++$x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < scalar @{$game->{"player_hands"};}) 0 0 0
421 0 my $player_hand = $game->{player_hands}[$x];
422  
423 0 ▶ next if ( $player_hand->{payed} );
Branch: 1 branch
BranchTrueFalseTotal
if $player_hand->{"payed"} 0 0 0
424 0 $player_hand->{payed} = 1;
425  
426 0 my $phv = hand_value( $player_hand, SOFT, PLAYER );
427  
428 0 ▶ if ( $dhb || $phv > $dhv ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dhb or $phv > $dhv) { } 0 0 0
elsif ($phv < $dhv) { } 0 0 0
Condition0%0/3
$dhb or $phv > $dhv
l!l&&r!l&&!r
000
MC/DC0%0/2
$dhb or $phv > $dhv
$dhb $phv > $dhv
Truth table0%0/3
A or B
A= $dhbB= $phv > $dhv
ABresult
1X1
011
000
429 $player_hand->{bet} *= 1.5
430 0 ▶ if ( is_blackjack( $player_hand->{cards} ) );
Branch: 1 branch
BranchTrueFalseTotal
if is_blackjack($player_hand->{"cards"}) 0 0 0
431 0 $game->{money} += $player_hand->{bet};
432 0 $player_hand->{status} = WON;
433 }
434 elsif ( $phv < $dhv ) {
435 0 $game->{money} -= $player_hand->{bet};
436 0 $player_hand->{status} = LOST;
437 }
438 else {
439 0 $player_hand->{status} = PUSH;
440 }
441 }
442  
443 0 normalize_bet($game);
444 0 save_game($game);
445 }
446  
447 0 ▶sub get_new_bet ($game) {
Subroutine get_new_bet: not called CC=1 SCAR=6.9
Pod undocumented
448 0 clear();
449 0 draw_hands($game);
450  
451 printf( ' Current Bet: $%u Enter New Bet: $',
452 0 ( $game->{current_bet} / 100 ) );
453  
454 0 my $tmp = <STDIN>;
455 0 chomp $tmp;
456  
457 0 $game->{current_bet} = $tmp * 100;
458 0 normalize_bet($game);
459 0 deal_new_hand($game);
460 }
461  
462 0 ▶sub get_new_num_decks ($game) {
Subroutine get_new_num_decks: not called CC=3 SCAR=24.8
Pod undocumented
463 0 clear();
464 0 draw_hands($game);
465  
466 printf( ' Number Of Decks: %u Enter New Number Of Decks (1-8): ',
467 0 ( $game->{num_decks} ) );
468  
469 0 my $tmp = <STDIN>;
470  
471 0 ▶ $tmp = 1 if ( $tmp < 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp < 1 0 0 0
472 0 ▶ $tmp = 8 if ( $tmp > 8 );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp > 8 0 0 0
473 0 $game->{num_decks} = $tmp;
474  
475 0 game_options($game);
476 }
477  
478 0 ▶sub get_new_deck_type ($game) {
Subroutine get_new_deck_type: not called CC=1 SCAR=6.9
Pod undocumented
479 0 clear();
480 0 draw_hands($game);
481 0 print(
482 " (1) Regular (2) Aces (3) Jacks (4) Aces & Jacks (5) Sevens (6) Eights\n"
483 );
484  
485 0 my $c = read_one_char(qr/[1-6]/);
486 0 $game->{deck_type} = $c;
487 0 $game->{deck_types}->{ $game->{deck_type} }->($game);
488  
489 0 save_game($game);
490 0 draw_hands($game);
491 0 bet_options($game);
492 }
493  
494 0 ▶sub get_new_face_type ($game) {
Subroutine get_new_face_type: not called CC=1 SCAR=6.9
Pod undocumented
495 0 clear();
496 0 draw_hands($game);
497 0 print(" (1) A♠ (2) 🂡\n");
498  
499 0 my $c = read_one_char(qr/[1-2]/);
500 0 $game->{face_type} = $c;
501  
502 0 save_game($game);
503 0 draw_hands($game);
504 0 bet_options($game);
505 }
506  
507 0 ▶sub game_options ($game) {
Subroutine game_options: not called CC=5 SCAR=34.0
Pod undocumented
508 0 clear();
509 0 draw_hands($game);
510 0 print(" (N) Number of Decks (T) Deck Type (F) Face Type (B) Back\n");
511  
512 0 my $c = read_one_char(qr/[ntfb]/);
513  
514 0 ▶ if ( $c eq 'n' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($c eq 'n') { } 0 0 0
elsif ($c eq 't') { } 0 0 0
elsif ($c eq 'f') { } 0 0 0
elsif ($c eq 'b') { } 0 0 0
515 0 get_new_num_decks($game);
516 }
517 elsif ( $c eq 't' ) {
518 0 get_new_deck_type($game);
519 }
520 elsif ( $c eq 'f' ) {
521 0 get_new_face_type($game);
522 }
523 elsif ( $c eq 'b' ) {
524 0 clear();
525 0 draw_hands($game);
526 0 bet_options($game);
527 }
528 }
529  
530 0 ▶sub bet_options ($game) {
Subroutine bet_options: not called CC=5 SCAR=34.0
Pod undocumented
531 0 print(" (D) Deal Hand (B) Change Bet (O) Options (Q) Quit\n");
532  
533 0 my $c = read_one_char(qr/[dboq]/);
534  
535 0 ▶ return if $c eq 'd';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "d" 0 0 0
536  
537 0 ▶ if ( $c eq 'b' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c eq 'b') { } 0 0 0
elsif ($c eq 'o') { } 0 0 0
elsif ($c eq 'q') { } 0 0 0
538 0 get_new_bet($game);
539 }
540 elsif ( $c eq 'o' ) {
541 0 game_options($game);
542 }
543 elsif ( $c eq 'q' ) {
544 0 $game->{quitting} = 1;
545 0 clear();
546 }
547 }
548  
549 0 ▶sub player_can_split ($game) {
Subroutine player_can_split: not called CC=6 SCAR=37.4
Pod undocumented
550 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
551  
552 return 0
553 if ( $player_hand->{stood}
554 0 ▶ || scalar( @{ $game->{player_hands} } ) >= MAX_PLAYER_HANDS );
Branch: 1 branch
BranchTrueFalseTotal
if $player_hand->{"stood"} or scalar @{$game->{"player_hands"};} >= 7 0 0 0
Condition0%0/3
$player_hand->{"stood"} or scalar @{$game->{"player_hands"};} >= 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$player_hand->{"stood"} or scalar @{$game->{"player_hands"};} >= 7
$player_hand->{"stood"} scalar @{$game->{"player_hands"};} >= 7
Truth table0%0/3
A or B
A= $player_hand->{"stood"}B= scalar @{$game->{"player_hands"};} >= 7
ABresult
1X1
011
000
555 0 ▶ return 0 if ( $game->{money} < all_bets($game) + $player_hand->{bet} );
Branch: 1 branch
BranchTrueFalseTotal
if $game->{"money"} < all_bets($game) + $player_hand->{"bet"} 0 0 0
556  
557 0 my $cards = $player_hand->{cards};
558 0 ▶ @$cards == 2 && @$cards[0]->{value} == @$cards[1]->{value} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$cards == 2 && @$cards[0]->{'value'} == @$cards[1]->{'value'} ? : 0 0 0
Condition0%0/3
@$cards == 2 and @$cards[0]->{"value"} == @$cards[1]->{"value"}
!ll&&!rl&&r
000
MC/DC0%0/2
@$cards == 2 and @$cards[0]->{"value"} == @$cards[1]->{"value"}
@$cards == 2 @$cards[0]->{"value"} == @$cards[1]->{"value"}
Truth table0%0/3
A and B
A= @$cards == 2B= @$cards[0]->{"value"} == @$cards[1]->{"value"}
ABresult
0X0
100
111
559 }
560  
561 0 ▶sub player_can_dbl ($game) {
Subroutine player_can_dbl: not called CC=6 SCAR=37.4
Pod undocumented
562 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
563  
564 0 ▶ return 0 if ( $game->{money} < all_bets($game) + $player_hand->{bet} );
Branch: 1 branch
BranchTrueFalseTotal
if $game->{"money"} < all_bets($game) + $player_hand->{"bet"} 0 0 0
565  
566 $player_hand->{stood}
567 0 || scalar( @{ $player_hand->{cards} } ) != 2
568 || player_is_busted($player_hand)
569 0 ▶ || is_blackjack( $player_hand->{cards} ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$player_hand->{'stood'} || scalar @{$player_hand->{'cards'};} != 2 || player_is_busted($player_hand) || is_blackjack($player_hand->{'cards'}) ? : 0 0 0
Condition0%0/9
$player_hand->{"stood"} or scalar @{$player_hand->{"cards"};} != 2 or player_is_busted($player_hand) or is_blackjack($player_hand->{"cards"})
l!l&&r!l&&!r
000
$player_hand->{"stood"} or scalar @{$player_hand->{"cards"};} != 2 or player_is_busted($player_hand)
l!l&&r!l&&!r
000
$player_hand->{"stood"} or scalar @{$player_hand->{"cards"};} != 2
l!l&&r!l&&!r
000
MC/DC0%0/4
$player_hand->{"stood"} or scalar @{$player_hand->{"cards"};} != 2 or player_is_busted($player_hand) or is_blackjack($player_hand->{"cards"})
$player_hand->{"stood"} scalar @{$player_hand->{"cards"};} != 2 player_is_busted($player_hand) is_blackjack($player_hand->{"cards"})
Truth table0%0/5
A or B or C or D
A= $player_hand->{"stood"}B= scalar @{$player_hand->{"cards"};} != 2C= player_is_busted($player_hand)D= is_blackjack($player_hand->{"cards"})
ABCDresult
1XXX1
01XX1
001X1
00011
00000
570 }
571  
572 0 ▶sub process ($game) {
Subroutine process: not called CC=2 SCAR=17.9
Pod undocumented
573 0 ▶ if ( more_hands_to_play($game) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (more_hands_to_play($game)) 0 0 0
574 0 play_more_hands($game);
575 0 return;
576 }
577  
578 0 play_dealer_hand($game);
579 0 draw_hands($game);
580 0 bet_options($game);
581 }
582  
583 0 ▶sub more_hands_to_play ($game) {
Subroutine more_hands_to_play: not called CC=1 SCAR=6.9
Pod undocumented
584 0 $game->{current_player_hand} < scalar( @{ $game->{player_hands} } ) - 1;
585 }
586  
587 0 ▶sub play_more_hands ($game) {
Subroutine play_more_hands: not called CC=2 SCAR=17.9
Pod undocumented
588 my $player_hand =
589 0 $game->{player_hands}[ ++( $game->{current_player_hand} ) ];
590 0 deal_card( $game->{shoe}, $player_hand->{cards} );
591  
592 0 ▶ if ( player_is_done( $game, $player_hand ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (player_is_done($game, $player_hand)) 0 0 0
593 0 process($game);
594 0 return;
595 }
596  
597 0 draw_hands($game);
598 0 player_get_action($game);
599 }
600  
601 0 ▶sub player_hit ($game) {
Subroutine player_hit: not called CC=2 SCAR=17.9
Pod undocumented
602 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
603 0 deal_card( $game->{shoe}, $player_hand->{cards} );
604  
605 0 ▶ if ( player_is_done( $game, $player_hand ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (player_is_done($game, $player_hand)) 0 0 0
606 0 process($game);
607 0 return;
608 }
609  
610 0 draw_hands($game);
611 0 player_get_action($game);
612 }
613  
614 0 ▶sub player_stand ($game) {
Subroutine player_stand: not called CC=2 SCAR=17.9
Pod undocumented
615 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
616  
617 0 $player_hand->{stood} = 1;
618 0 $player_hand->{played} = 1;
619  
620 0 ▶ if ( more_hands_to_play($game) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (more_hands_to_play($game)) 0 0 0
621 0 play_more_hands($game);
622 0 return;
623 }
624  
625 0 play_dealer_hand($game);
626 0 draw_hands($game);
627 0 bet_options($game);
628 }
629  
630 0 ▶sub player_split ($game) {
Subroutine player_split: not called CC=4 SCAR=30.0
Pod undocumented
631 0 ▶ if ( !player_can_split($game) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (player_can_split($game)) 0 0 0
632 0 draw_hands($game);
633 0 player_get_action($game);
634 0 return;
635 }
636  
637 my %new_hand = (
638 cards => [],
639 bet => $game->{current_bet},
640 0 stood => 0,
641 played => 0,
642 payed => 0,
643 status => 0
644 );
645 0 my $hand_count = scalar( @{ $game->{player_hands} } );
646  
647 0 $game->{player_hands}[$hand_count] = \%new_hand;
648  
649 0 ▶ while ( $hand_count > $game->{current_player_hand} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hand_count > $game->{"current_player_hand"}) 0 0 0
650 0 my $ph = dclone( $game->{player_hands}[ $hand_count - 1 ] );
651 0 $game->{player_hands}[$hand_count] = $ph;
652 0 --$hand_count;
653 }
654  
655 0 my $this_hand = $game->{player_hands}[ $game->{current_player_hand} ];
656 0 my $split_hand = $game->{player_hands}[ $game->{current_player_hand} + 1 ];
657  
658 0 $split_hand->{cards} = [ dclone( $this_hand->{cards}[1] ) ];
659 0 $this_hand->{cards} = [ dclone( $this_hand->{cards}[0] ) ];
660  
661 0 deal_card( $game->{shoe}, $this_hand->{cards} );
662  
663 0 ▶ if ( player_is_done( $game, $this_hand ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (player_is_done($game, $this_hand)) 0 0 0
664 0 process($game);
665 0 return;
666 }
667  
668 0 draw_hands($game);
669 0 player_get_action($game);
670 }
671  
672 0 ▶sub player_dbl ($game) {
Subroutine player_dbl: not called CC=2 SCAR=17.9
Pod undocumented
673 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
674  
675 0 deal_card( $game->{shoe}, $player_hand->{cards} );
676 0 $player_hand->{played} = 1;
677 0 $player_hand->{bet} *= 2;
678  
679 0 ▶ process($game) if ( player_is_done( $game, $player_hand ) );
Branch: 1 branch
BranchTrueFalseTotal
if player_is_done($game, $player_hand) 0 0 0
680 }
681  
682 0 ▶sub player_get_action ($game) {
Subroutine player_get_action: not called CC=9 SCAR=45.0
Pod undocumented
683 0 my $player_hand = $game->{player_hands}[ $game->{current_player_hand} ];
684 0 print(' ');
685  
686 0 ▶ if ( player_can_hit($player_hand) ) { print('(H) Hit '); }
Branch: 1 branch
BranchTrueFalseTotal
if (player_can_hit($player_hand)) 0 0 0
687 0 ▶ if ( player_can_stand($player_hand) ) { print('(S) Stand '); }
Branch: 1 branch
BranchTrueFalseTotal
if (player_can_stand($player_hand)) 0 0 0
688 0 ▶ if ( player_can_split($game) ) { print('(P) Split '); }
Branch: 1 branch
BranchTrueFalseTotal
if (player_can_split($game)) 0 0 0
689 0 ▶ if ( player_can_dbl($game) ) { print('(D) Double '); }
Branch: 1 branch
BranchTrueFalseTotal
if (player_can_dbl($game)) 0 0 0
690  
691 0 print("\n");
692  
693 0 my $c = read_one_char(qr/[hspd]/);
694  
695 0 ▶ if ( $c eq 'h' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($c eq 'h') { } 0 0 0
elsif ($c eq 's') { } 0 0 0
elsif ($c eq 'p') { } 0 0 0
elsif ($c eq 'd') { } 0 0 0
696 0 player_hit($game);
697 }
698 elsif ( $c eq 's' ) {
699 0 player_stand($game);
700 }
701 elsif ( $c eq 'p' ) {
702 0 player_split($game);
703 }
704 elsif ( $c eq 'd' ) {
705 0 player_dbl($game);
706 }
707 }
708  
709 0 ▶sub ask_insurance ($game) {
Subroutine ask_insurance: not called CC=3 SCAR=24.8
Pod undocumented
710 0 print(" Insurance? (Y) Yes (N) No\n");
711  
712 0 my $c = read_one_char(qr/[yn]/);
713  
714 0 ▶ if ( $c eq 'y' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq 'y') { } 0 0 0
elsif ($c eq 'n') { } 0 0 0
715 0 insure_hand($game);
716 }
717 elsif ( $c eq 'n' ) {
718 0 no_insurance($game);
719 }
720 }
721  
722 0 ▶sub deal_new_hand ($game) {
Subroutine deal_new_hand: not called CC=5 SCAR=34.0
Pod undocumented
723 0 ▶ $game->{deck_types}->{ $game->{deck_type} }->($game)
Branch: 1 branch
BranchTrueFalseTotal
if need_to_shuffle($game) 0 0 0
724 if ( need_to_shuffle($game) );
725  
726 my %player_hand = (
727 cards => [],
728 bet => $game->{current_bet},
729 0 stood => 0,
730 played => 0,
731 payed => 0,
732 status => 0
733 );
734 0 my %dealer_hand = ( cards => [], hide_down_card => 1 );
735  
736 0 deal_card( $game->{shoe}, ( \%player_hand )->{cards} );
737 0 deal_card( $game->{shoe}, ( \%dealer_hand )->{cards} );
738 0 deal_card( $game->{shoe}, ( \%player_hand )->{cards} );
739 0 deal_card( $game->{shoe}, ( \%dealer_hand )->{cards} );
740  
741 0 $game->{player_hands} = [ \%player_hand ];
742 0 $game->{current_player_hand} = 0;
743 0 $game->{dealer_hand} = \%dealer_hand;
744  
745 0 draw_hands($game);
746  
747 0 ▶ if ( dealer_upcard_is_ace( \%dealer_hand )
Branch: 1 branch
BranchTrueFalseTotal
if (dealer_upcard_is_ace(\%dealer_hand) and not is_blackjack(+(\%player_hand)->{"cards"})) 0 0 0
Condition0%0/3
dealer_upcard_is_ace(\%dealer_hand) and not is_blackjack(+(\%player_hand)->{"cards"})
!ll&&!rl&&r
000
MC/DC0%0/2
dealer_upcard_is_ace(\%dealer_hand) and not is_blackjack(+(\%player_hand)->{"cards"})
dealer_upcard_is_ace(\%dealer_hand) not is_blackjack(+(\%player_hand)->{"cards"})
Truth table0%0/3
A and not(B)
A= dealer_upcard_is_ace(\%dealer_hand)B= not is_blackjack(+(\%player_hand)->{"cards"})
ABresult
0X0
100
111
748 && !is_blackjack( ( \%player_hand )->{cards} ) )
749 {
750 0 draw_hands($game);
751 0 ask_insurance($game);
752 0 return;
753 }
754  
755 0 ▶ if ( player_is_done( $game, \%player_hand ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (player_is_done($game, \%player_hand)) 0 0 0
756 0 $dealer_hand{hide_down_card} = 0;
757 0 pay_hands($game);
758 0 draw_hands($game);
759 0 bet_options($game);
760 0 return;
761 }
762  
763 0 draw_hands($game);
764 0 player_get_action($game);
765 0 save_game($game);
766 }
767  
768 0 ▶sub save_game ($game) {
Subroutine save_game: not called CC=2 SCAR=17.9
Pod undocumented
769 0 ▶ open( my $fh, '>:encoding(UTF-8)', SAVE_FILE ) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:encoding(UTF-8)", "bj.txt" or die $! 0 0 0
770 printf( $fh "%u\n%u\n%u\n%u\n%u\n",
771 $game->{num_decks}, $game->{money}, $game->{current_bet},
772 $game->{deck_type}, $game->{face_type}
773 0 );
774 0 close($fh);
775 }
776  
777 0 ▶sub load_game ($game) {
Subroutine load_game: not called CC=2 SCAR=17.9
Pod undocumented
778 0 ▶ if ( open( my $fh, '<:encoding(UTF-8)', SAVE_FILE ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<:encoding(UTF-8)", "bj.txt") 0 0 0
779 0 my $line = <$fh>;
780 0 chomp $line;
781 0 $game->{num_decks} = int($line);
782  
783 0 $line = <$fh>;
784 0 chomp $line;
785 0 $game->{money} = int($line);
786  
787 0 $line = <$fh>;
788 0 chomp $line;
789 0 $game->{current_bet} = int($line);
790  
791 0 $line = <$fh>;
792 0 chomp $line;
793 0 $game->{deck_type} = int($line);
794  
795 0 $line = <$fh>;
796 0 chomp $line;
797 0 $game->{face_type} = int($line);
798  
799 0 close($fh);
800 }
801 }
802  
803 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
804 0 my %game = (
805 quitting => 0,
806 shoe => [],
807 dealer_hand => {},
808 player_hands => [],
809 num_decks => 8,
810 deck_type => 1,
811 face_type => 1,
812 money => 10000,
813 current_bet => 500,
814 current_player_hand => 0,
815 shuffle_specs => [
816 [ 95, 8 ], [ 92, 7 ], [ 89, 6 ], [ 86, 5 ],
817 [ 84, 4 ], [ 82, 3 ], [ 81, 2 ], [ 80, 1 ]
818 ],
819 faces => [
820 [ 'A♠', 'A♥', 'A♣', 'A♦' ],
821 [ '2♠', '2♥', '2♣', '2♦' ],
822 [ '3♠', '3♥', '3♣', '3♦' ],
823 [ '4♠', '4♥', '4♣', '4♦' ],
824 [ '5♠', '5♥', '5♣', '5♦' ],
825 [ '6♠', '6♥', '6♣', '6♦' ],
826 [ '7♠', '7♥', '7♣', '7♦' ],
827 [ '8♠', '8♥', '8♣', '8♦' ],
828 [ '9♠', '9♥', '9♣', '9♦' ],
829 [ 'T♠', 'T♥', 'T♣', 'T♦' ],
830 [ 'J♠', 'J♥', 'J♣', 'J♦' ],
831 [ 'Q♠', 'Q♥', 'Q♣', 'Q♦' ],
832 [ 'K♠', 'K♥', 'K♣', 'K♦' ],
833 ['??']
834 ],
835 faces2 => [
836 [ '🂡', '🂱', '🃁', '🃑' ],
837 [ '🂢', '🂲', '🃂', '🃒' ],
838 [ '🂣', '🂳', '🃃', '🃓' ],
839 [ '🂤', '🂴', '🃄', '🃔' ],
840 [ '🂥', '🂵', '🃅', '🃕' ],
841 [ '🂦', '🂶', '🃆', '🃖' ],
842 [ '🂧', '🂷', '🃇', '🃗' ],
843 [ '🂨', '🂸', '🃈', '🃘' ],
844 [ '🂩', '🂹', '🃉', '🃙' ],
845 [ '🂪', '🂺', '🃊', '🃚' ],
846 [ '🂫', '🂻', '🃋', '🃛' ],
847 [ '🂭', '🂽', '🃍', '🃝' ],
848 [ '🂮', '🂾', '🃎', '🃞' ],
849 ['🂠']
850 ],
851 deck_types => {
852 1 => \&new_regular,
853 2 => \&new_aces,
854 3 => \&new_jacks,
855 4 => \&new_aces_jacks,
856 5 => \&new_sevens,
857 6 => \&new_eights
858 }
859 );
860  
861 0 load_game( \%game );
862  
863 0 while (1) {
864 0 deal_new_hand( \%game );
865 0 ▶ last if $game{quitting};
Branch: 1 branch
BranchTrueFalseTotal
if $game{"quitting"} 0 0 0
866 }
867 }
868  
869 1 1; # End of Console::Blackjack
↑ Summary script/console-blackjack.pl »