| 1 | package Games::Tournament::BlackJack; | ||||||||||||||||||||||||||||||||||
| 2 | # This package is NOT meant to be used with OO syntax. | ||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.006; # a guess, earlier perls may work. | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||
| 12 | run_example_bj_game | ||||||||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||
| 18 | 1 | $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 | ▶ | use Games::Tournament::BlackJack::Shoe; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Games::Tournament::BlackJack::Game; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | # You may also want some player modules | ||||||||||||||||||||||||||||||||||
| 27 | # ExamplePlayer2 is hardcoded to hit on 16 or less, but adjustable. | ||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Games::Tournament::BlackJack::Player::ExamplePlayer2; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | # DealerPlayer plays by dealer rules (hit on soft 17) | ||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use Games::Tournament::BlackJack::Player::DealerPlayer; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 1 | our $defaultNumRounds = 100; | |||||||||||||||||||||||||||||||||
| 34 | 1 | 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 | 0 | ▶ | sub run_example_bj_game { | ||||||||||||||||||||||||||||||||
|
Subroutine
run_example_bj_game: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | # set number of rounds to play (recommend 100 (very fast) to 100000 (very slow)) | ||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $numRounds = shift || $numRounds || $defaultNumRounds; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
shift() || $Games::Tournament::BlackJack::numRounds || $Games::Tournament::BlackJack::defaultNumRounds
shift() or $Games::Tournament::BlackJack::numRounds
MC/DC0%0/3
shift() || $Games::Tournament::BlackJack::numRounds || $Games::Tournament::BlackJack::defaultNumRounds
shift()
$Games::Tournament::BlackJack::numRounds
$Games::Tournament::BlackJack::defaultNumRounds
Truth table0%0/4
A or B || C
A= shift()B= $Games::Tournament::BlackJack::numRoundsC= $Games::Tournament::BlackJack::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()) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | 0 | print "\n---playing round $num..---\n"; | |||||||||||||||||||||||||||||||||
| 73 | 0 | $game->playRound(); | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($num > ($numRounds-1)) {$game->quit();} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | 0 | $num++; | |||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||
| 77 | 0 | print "\n\n\n"; | |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | # print scores | ||||||||||||||||||||||||||||||||||
| 81 | 0 | my @scores = @{$game->playersScores()}; | |||||||||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||||||||