File Coverage

blib/lib/Games/Euchre/AI/Simple.pm
Criterion Covered Total %
statement 9 33 27.2
branch 0 10 0.0
condition n/a
subroutine 3 6 50.0
pod 3 3 100.0
total 15 52 28.8


line stmt bran cond sub pod time code
1             # _DUMB_ computer player. This is pretty much just a clone of the
2             # built-in computer player in Euchre.pm, but it would also make a good
3             # starting place for other computer players to start from.
4              
5             # This module is licensed under the same terms as the other modules in
6             # this package: GPLv2
7              
8             package Games::Euchre::AI::Simple;
9              
10 1     1   908 use strict;
  1         2  
  1         32  
11 1     1   4 use warnings;
  1         2  
  1         21  
12 1     1   4 use Games::Euchre::AI;
  1         1  
  1         284  
13              
14             our @ISA = qw(Games::Euchre::AI);
15              
16             sub bid {
17 0     0 1   my $self = shift;
18 0           my $state = shift;
19              
20             # DUMB computer player!!! pass unless last bid, then pick any one
21 0 0         if ($state->{passes} == 7) {
22             # pick any card in hand
23 0           foreach my $card (@{$state->{hand}}) {
  0            
24 0           my $suit = $self->getCardSuit($state, $card);
25 0 0         if ($self->isLegalBid($state, $suit)) {
26 0           return $suit;
27             }
28             }
29             # pick any suit
30 0           foreach my $suit ("H", "S", "D", "C") {
31 0 0         if ($self->isLegalBid($state, $suit)) {
32 0           return $suit;
33             }
34             }
35             } else {
36 0           return undef;
37             }
38             }
39              
40             sub pickItUp {
41 0     0 1   my $self = shift;
42 0           my $state = shift;
43              
44             # DUMB computer player!!! pick the first card
45 0           return 0;
46             }
47              
48             sub playCard {
49 0     0 1   my $self = shift;
50 0           my $state = shift;
51              
52             # DUMB computer player!!! pick the first legal card
53 0           for (my $i=0; $i < @{$state->{hand}}; $i++) {
  0            
54 0 0         if ($self->isLegalPlay($state, $i)) {
55 0           print($state->{name} . " plays " . $state->{hand}->[$i] .
56 0 0         " on " . join(" ", @{$state->{hand}}) . "\n")
57             if ($state->{debug});
58 0           return $i;
59             }
60             }
61              
62 0           die "No legal play???? Impossible!";
63             }
64              
65             1;