blib/lib/Game/Schnapsen/Trick.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 20 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 100% 80 / 80 CC 12 SCAR 13.2
CC
12
Cov
100%
follow_band
5.0
legal_follows
5.0
winner_of
4.0
CRAP 3.7
« blib/lib/Game/Schnapsen/Deck.pm ↑ Summary blib/lib/Game/Schnapsen.pm »
1 package Game::Schnapsen::Trick;
2  
3 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 22 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 ▶use Game::Schnapsen::Card qw(suit_of power_of points_of);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 22 our $VERSION = '0.02';
11 22 our @EXPORT_OK = qw(winner_of value_of legal_follows follow_band);
12  
13 215385 ▶sub winner_of {
Subroutine winner_of: called CC=4 SCAR=13.9
Pod documented
14 215385 my ($lead, $follow, $trump) = @_;
15 215385 my $ls = suit_of($lead);
16 215385 my $fs = suit_of($follow);
17  
18 215385 ▶ return power_of($follow) > power_of($lead) ? $follow : $lead if $fs eq $ls;
Branch: 2 branches
BranchTrueFalseTotal
if $fs eq $ls 61514 153871 215385
power_of($follow) > power_of($lead) ? : 44162 17352 61514
19 153871 ▶ return $follow if $fs eq $trump;
Branch: 1 branch
BranchTrueFalseTotal
if $fs eq $trump 52460 101411 153871
20 101411 return $lead;
21 }
22  
23 37245 ▶sub value_of {
Subroutine value_of: called CC=1 SCAR=0.0
Pod documented
24 37245 my ($lead, $follow) = @_;
25 37245 return points_of($lead) + points_of($follow);
26 }
27  
28 91704 ▶sub follow_band {
Subroutine follow_band: called CC=5 SCAR=16.1
Pod documented
29 91704 my ($hand, $lead, $trump, $phase) = @_;
30 91704 ▶ return 'free' if $phase == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $phase == 1 51301 40403 91704
31  
32 40403 my $ls = suit_of($lead);
33 40403 my @suited = grep { suit_of($_) eq $ls } @$hand;
34 40403 ▶ if (@suited) {
Branch: 1 branch
BranchTrueFalseTotal
if (@suited) 21625 18778 40403
35 21625 ▶ return scalar(grep { power_of($_) > power_of($lead) } @suited) ? 'beat' : 'follow';
Branch: 1 branch
BranchTrueFalseTotal
scalar grep({power_of($_) > power_of($lead);} @suited) ? : 7631 13994 21625
36 }
37 18778 ▶ return scalar(grep { suit_of($_) eq $trump } @$hand) ? 'trump' : 'free';
Branch: 1 branch
BranchTrueFalseTotal
scalar grep({suit_of($_) eq $trump;} @$hand) ? : 10276 8502 18778
38 }
39  
40 91694 ▶sub legal_follows {
Subroutine legal_follows: called CC=5 SCAR=16.1
Pod documented
41 91694 my ($hand, $lead, $trump, $phase) = @_;
42 91694 my $band = follow_band($hand, $lead, $trump, $phase);
43  
44 91694 ▶ return [ @$hand ] if $band eq 'free';
Branch: 1 branch
BranchTrueFalseTotal
if $band eq "free" 59801 31893 91694
45  
46 31893 my $ls = suit_of($lead);
47 31893 ▶ return [ grep { suit_of($_) eq $ls && power_of($_) > power_of($lead) } @$hand ]
Branch: 1 branch
BranchTrueFalseTotal
if $band eq "beat" 7628 24265 31893
Condition100%3/3
suit_of($_) eq $ls && power_of($_) > power_of($lead)
!ll&&!rl&&r
2073916189121
MC/DC100%2/2
suit_of($_) eq $ls && power_of($_) > power_of($lead)
suit_of($_) eq $ls power_of($_) > power_of($lead)
Truth table100%3/3
A && B
A= suit_of($_) eq $lsB= power_of($_) > power_of($lead)
ABresult
0X0
100
111
48 if $band eq 'beat';
49 24265 ▶ return [ grep { suit_of($_) eq $ls } @$hand ] if $band eq 'follow';
Branch: 1 branch
BranchTrueFalseTotal
if $band eq "follow" 13991 10274 24265
50 10274 return [ grep { suit_of($_) eq $trump } @$hand ];
51 }
52  
53 22 1;
54  
55 __END__
« blib/lib/Game/Schnapsen/Deck.pm ↑ Summary blib/lib/Game/Schnapsen.pm »