blib/lib/Game/Schnapsen/Declare.pm

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 98.3% 60 / 61 CC 8 SCAR 10.1
CC
8
Cov
98%
marriages_in
5.0
exchange_card
3.0
marriage_value
2.0
CRAP 2.8
« blib/lib/Game/Schnapsen.pm ↑ Summary blib/lib/Game/Schnapsen/Card.pm »
1 package Game::Schnapsen::Declare;
2  
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 20 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶use Game::Schnapsen::Card qw(suit_of rank_of id_of);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 20 our $VERSION = '0.02';
11 20 our @EXPORT_OK = qw(marriages_in marriage_value exchange_card
12 MARRIAGE MARRIAGE_TRUMP);
13  
14 20 ▶use constant MARRIAGE => 20;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 20 ▶use constant MARRIAGE_TRUMP => 40;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 10202 ▶sub marriage_value {
Subroutine marriage_value: called CC=2 SCAR=6.9
Pod documented
18 10202 my ($suit, $trump) = @_;
19 10202 ▶ return $suit eq $trump ? MARRIAGE_TRUMP : MARRIAGE;
Branch: 1 branch
BranchTrueFalseTotal
$suit eq $trump ? : 2435 7767 10202
20 }
21  
22 50228 ▶sub marriages_in {
Subroutine marriages_in: called CC=5 SCAR=16.1
Pod documented
23 50228 my ($cards, $trump) = @_;
24 50228 my %have;
25 50228 $have{ suit_of($_) }{ rank_of($_) } = $_ for @$cards;
26  
27 50228 my @out;
28 50228 for my $suit (sort keys %have) {
29 150455 ▶ next unless $have{$suit}{K} && $have{$suit}{Q};
Branch: 1 branch
BranchTrueFalseTotal
unless $have{$suit}{"K"} and $have{$suit}{"Q"} 140255 10200 150455
Condition100%3/3
$have{$suit}{"K"} and $have{$suit}{"Q"}
!ll&&!rl&&r
1015713868410200
MC/DC100%2/2
$have{$suit}{"K"} and $have{$suit}{"Q"}
$have{$suit}{"K"} $have{$suit}{"Q"}
Truth table100%3/3
A and B
A= $have{$suit}{"K"}B= $have{$suit}{"Q"}
ABresult
0X0
100
111
30 push @out, {
31 suit => $suit,
32 value => marriage_value($suit, $trump),
33 king => $have{$suit}{K},
34 queen => $have{$suit}{Q},
35 10200 };
36 }
37 50228 return \@out;
38 }
39  
40 38414 ▶sub exchange_card {
Subroutine exchange_card: called CC=3 SCAR=11.0
Pod documented
41 38414 my ($cards, $trump, $rank) = @_;
42 38414 my $want = id_of("$rank$trump");
43 38414 ▶ return undef unless defined $want;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $want 0 38414 38414
44 38414 ▶ return scalar(grep { $_ == $want } @$cards) ? $want : undef;
Branch: 1 branch
BranchTrueFalseTotal
scalar grep({$_ == $want;} @$cards) ? : 5990 32424 38414
45 }
46  
47 20 1;
48  
49 __END__
« blib/lib/Game/Schnapsen.pm ↑ Summary blib/lib/Game/Schnapsen/Card.pm »