Durak/Rules.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 98 CC 14 SCAR 28.4
CC
14
Cov
0%
forced
30.0
closes
30.0
cap_for
12.0
CRAP 17.1
1 package Game::Durak::Rules;
2  
3 use strict;
4 use warnings;
5  
6 use Exporter 'import';
7  
8 use Game::Durak::Card qw(rank_of beats);
9 use Game::Durak::Deck qw(HAND_SIZE);
10  
11 our $VERSION = '0.04';
12 our @EXPORT_OK = qw(cap_for legal_attacks legal_beats forced closes);
13  
14 sub cap_for {
15 my ($size) = @_;
16 die "cap_for wants a hand size\n"
17 unless defined $size && $size =~ /\A[0-9]+\z/;
18 return $size < HAND_SIZE ? $size : HAND_SIZE;
19 }
20  
21 sub legal_attacks {
22 my ($hand, $bout) = @_;
23 return [] if $bout->room < 1;
24 return [ @$hand ] unless $bout->size;
25 my $ranks = $bout->ranks;
26 return [ grep { $ranks->{ rank_of($_) } } @$hand ];
27 }
28  
29 sub legal_beats {
30 my ($hand, $bout, $trump) = @_;
31 my $att = $bout->unbeaten;
32 return [] unless defined $att;
33 return [ grep { beats($_, $att, $trump) } @$hand ];
34 }
35  
36 sub forced {
37 my ($hand, $bout, $trump, $phase, $can_swap) = @_;
38 return 0 if $can_swap;
39 return @{ legal_beats($hand, $bout, $trump) } ? 0 : 1 if $phase eq 'defend';
40 return @{ legal_attacks($hand, $bout) } ? 0 : 1;
41 }
42  
43 sub closes {
44 my ($bout, $defender_size) = @_;
45 return undef if $bout->taken;
46 return undef unless $bout->size && $bout->all_beaten;
47 return 'spent' unless $defender_size;
48 return 'capped' if $bout->room < 1;
49 return undef;
50 }
51  
52 1;
53  
54 __END__