File Coverage

blib/lib/Games/Tournament/BlackJack.pm
Criterion Covered Total %
statement 24 43 55.8
branch 0 2 0.0
condition 0 3 0.0
subroutine 8 9 88.8
pod 0 1 0.0
total 32 58 55.1


line stmt bran cond sub pod time code
1             package Games::Tournament::BlackJack;
2             # This package is NOT meant to be used with OO syntax.
3              
4 1     1   24466 use 5.006; # a guess, earlier perls may work.
  1         4  
  1         44  
5 1     1   6 use strict;
  1         2  
  1         51  
6 1     1   7 use warnings;
  1         3  
  1         42  
7 1     1   6 use Exporter;
  1         2  
  1         142  
8              
9             our @ISA = qw(Exporter);
10              
11             our @EXPORT = qw(
12             run_example_bj_game
13             );
14              
15              
16              
17             our $VERSION = '0.01';
18             $VERSION = eval $VERSION;
19              
20             # You will probably want to include the following modules
21             # when writing a game script, at least until there are
22             # better facilities to help you in here.
23 1     1   1210 use Games::Tournament::BlackJack::Shoe;
  1         3  
  1         100  
24 1     1   667 use Games::Tournament::BlackJack::Game;
  1         3  
  1         38  
25              
26             # You may also want some player modules
27             # ExamplePlayer2 is hardcoded to hit on 16 or less, but adjustable.
28 1     1   735 use Games::Tournament::BlackJack::Player::ExamplePlayer2;
  1         3  
  1         31  
29              
30             # DealerPlayer plays by dealer rules (hit on soft 17)
31 1     1   595 use Games::Tournament::BlackJack::Player::DealerPlayer;
  1         2  
  1         421  
32              
33             our $defaultNumRounds = 100;
34             our $numRounds = $defaultNumRounds;
35              
36             # example game configuration, determines the best hard-threshold to use (ExamplePlayer2's strategy)
37             # Use this code as a template to create other simulations.
38              
39             sub run_example_bj_game {
40              
41             # set number of rounds to play (recommend 100 (very fast) to 100000 (very slow))
42 0   0 0 0   $numRounds = shift || $numRounds || $defaultNumRounds;
43            
44 0           my @players = (
45             # investigate best hit threshold for ExamplePlayer2.
46             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>10),
47             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>11),
48             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>12),
49             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>13),
50             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>14),
51             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>15),
52             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>16),
53             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>17),
54             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>18),
55             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>19),
56             new Games::Tournament::BlackJack::Player::ExamplePlayer2('hit_threshold'=>20),
57             );
58            
59            
60 0           my $game = new Games::Tournament::BlackJack::Game();
61 0           my $dealer = new Games::Tournament::BlackJack::Player::DealerPlayer();
62 0           $game->addPlayers(@players);
63            
64 0           $game->setDealer($dealer); # this is the actual dealer player.
65              
66             # tell game that config is done and it can prepare to run game
67 0           $game->start();
68              
69             # run the game
70 0           my $num = 1;
71 0           while ($game->running()) {
72 0           print "\n---playing round $num..---\n";
73 0           $game->playRound();
74 0 0         if ($num > ($numRounds-1)) {$game->quit();}
  0            
75 0           $num++;
76             }
77 0           print "\n\n\n";
78            
79              
80             # print scores
81 0           my @scores = @{$game->playersScores()};
  0            
82 0           foreach (0..$#scores) {
83 0           print "player $_ score: $scores[$_]\n"
84             }
85              
86             }
87              
88              
89              
90              
91             # more game config and execution functionality to come in future releases
92              
93             1;
94             __END__