| 1 | package Games::Tournament::BlackJack::Player::HumanPlayer; | ||
| 2 | # example interactive human player module for blackjack | ||
| 3 | |||
| 4 | use Games::Tournament::BlackJack::Player; | ||
| 5 | use Games::Tournament::BlackJack::Utilities; | ||
| 6 | @ISA = qw(Games::Tournament::BlackJack::Player); | ||
| 7 | |||
| 8 | # decide_simple returns true for hit, false for stand. | ||
| 9 | sub decide_simple { | ||
| 10 | my $self = shift; | ||
| 11 | my @hand = @{$self->{'hand'}}; | ||
| 12 | my $hval = handValue(\@hand); | ||
| 13 | my $hand_str = handStr(\@hand); | ||
| 14 | $output = "dealer shows $self->{'dealerUpcard'}, you have [ $hand_str ] for a total of $hval.\n"; | ||
| 15 | |||
| 16 | print $output; | ||
| 17 | print "[h]it or stay>"; | ||
| 18 | |||
| 19 | my $input = <>; | ||
| 20 | if ($input =~ m/h/i) | ||
| 21 | { return 1; } # hit if the user says to. | ||
| 22 | else | ||
| 23 | { return 0; } | ||
| 24 | } | ||
| 25 | |||
| 26 | |||
| 27 | 1; | ||
| 28 |