blib/lib/Game/Schnapsen/Scoring.pm

filter: Statementstmt 100% 72 / 72 Branchbran 94.7% 36 / 38 Conditioncond 76.4% 13 / 17 MC/DCmcdc 63.6% 7 / 11 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 93.4% 143 / 153 CC 26 SCAR 25.2
CC
26
Cov
95%
deal_result
21.1
_state
3.0
scale
3.0
CRAP 12.5
« blib/lib/Game/Schnapsen/Terminal.pm ↑ Summary blib/lib/Game/Schnapsen/Bot.pm »
1 package Game::Schnapsen::Scoring;
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::Variant ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 22 our $VERSION = '0.03';
11 22 our @EXPORT_OK = qw(scale deal_result
12 TARGET_POINTS SCHNEIDER_AT LAST_TRICK_BONUS
13 PENALTY PENALTY_SCHWARZ);
14  
15 22 ▶use constant TARGET_POINTS => 66;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 22 ▶use constant SCHNEIDER_AT => 33;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 22 ▶use constant LAST_TRICK_BONUS => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 22 ▶use constant PENALTY => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 22 ▶use constant PENALTY_SCHWARZ => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4230 ▶sub _other { return $_[0] eq 'p1' ? 'p2' : 'p1' }
Subroutine _other: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq 'p1' ? : 2150 2080 4230
22  
23 3122 ▶sub scale {
Subroutine scale: called CC=3 SCAR=11.0
Pod documented
24 3122 my ($points, $tricks) = @_;
25 3122 ▶ return 3 unless $tricks;
Branch: 1 branch
BranchTrueFalseTotal
unless $tricks 136 2986 3122
26 2986 ▶ return 2 if $points < SCHNEIDER_AT;
Branch: 1 branch
BranchTrueFalseTotal
if $points < 33 1111 1875 2986
27 1875 return 1;
28 }
29  
30 2442 ▶sub _state {
Subroutine _state: called CC=3 SCAR=11.0
31 2442 my ($o, $seat, $at) = @_;
32 return { points => $o->{points}{$seat}, tricks => $o->{tricks}{$seat} }
33 2442 ▶ unless $at eq 'close' && $o->{close_state};
Branch: 1 branch
BranchTrueFalseTotal
unless $at eq "close" and $o->{"close_state"} 2158 284 2442
Condition66%2/3
$at eq "close" and $o->{"close_state"}
!ll&&!rl&&r
21580284
MC/DC50%1/2
$at eq "close" and $o->{"close_state"}
$at eq "close" $o->{"close_state"}
Truth table66%2/3
A and B
A= $at eq "close"B= $o->{"close_state"}
ABresult
0X0
100
111
34 284 return $o->{close_state}{$seat};
35 }
36  
37 4249 ▶sub deal_result {
Subroutine deal_result: called CC=21 SCAR=30.5
Pod documented
38 4249 my (%o) = @_;
39 4249 my $v = $o{variant};
40  
41 my %r = (
42 drawn => 0,
43 4249 points => { %{ $o{points} } },
44 4249 tricks => { %{ $o{tricks} } },
45 closed_by => $o{closed_by},
46 last_trick => $o{last_trick},
47 4249 );
48  
49 4249 ▶ if (($o{how} // '') eq 'claim') {
Branch: 1 branch
BranchTrueFalseTotal
if (($o{"how"} // "") eq "claim") 2495 1754 4249
Condition50%1/2
$o{"how"} // ""
l!l
42490
MC/DC0%0/1
$o{"how"} // ""
$o{"how"}
Truth table50%1/2
A
A= $o{"how"}
Aresult
11
00
50 2495 my $me = $o{by};
51 2495 my $them = _other($me);
52  
53 2495 ▶ unless ($o{points}{$me} >= TARGET_POINTS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o{"points"}{$me} >= 66) 8 2487 2495
54 my $schwarz = Game::Schnapsen::Variant::false_claim_schwarz($v)
55 8 ▶ && !$o{tricks}{$them};
Condition100%3/3
Game::Schnapsen::Variant::false_claim_schwarz($v) && !$o{'tricks'}{$them}
!ll&&!rl&&r
422
MC/DC100%2/2
Game::Schnapsen::Variant::false_claim_schwarz($v) && !$o{'tricks'}{$them}
Game::Schnapsen::Variant::false_claim_schwarz($v) !$o{'tricks'}{$them}
Truth table100%3/3
A && not(B)
A= Game::Schnapsen::Variant::false_claim_schwarz($v)B= !$o{'tricks'}{$them}
ABresult
0X0
100
111
56 8 ▶ return { %r, how => 'false_claim', winner => $them, loser => $me,
Branch: 1 branch
BranchTrueFalseTotal
$schwarz ? : 2 6 8
57 game_points => $schwarz ? PENALTY_SCHWARZ : PENALTY };
58 }
59  
60 2487 ▶ if (defined $o{closed_by} && $o{closed_by} ne $me) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{"closed_by"} and $o{"closed_by"} ne $me) 45 2442 2487
Condition100%3/3
defined $o{"closed_by"} and $o{"closed_by"} ne $me
!ll&&!rl&&r
159384945
MC/DC100%2/2
defined $o{"closed_by"} and $o{"closed_by"} ne $me
defined $o{"closed_by"} $o{"closed_by"} ne $me
Truth table100%3/3
A and B
A= defined $o{"closed_by"}B= $o{"closed_by"} ne $me
ABresult
0X0
100
111
61 45 my $flat = Game::Schnapsen::Variant::beaten_closer_flat($v);
62 45 ▶ my $at_close = $o{close_state} ? $o{close_state}{$me} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o{'close_state'} ? : 45 0 45
63 my $gp = $flat ? PENALTY
64 45 ▶ : (($at_close && $at_close->{tricks}) ? PENALTY : PENALTY_SCHWARZ);
Branch: 2 branches
BranchTrueFalseTotal
$flat ? : 32 13 45
$at_close && $at_close->{'tricks'} ? : 10 3 13
Condition66%2/3
$at_close and $at_close->{"tricks"}
!ll&&!rl&&r
0310
MC/DC50%1/2
$at_close and $at_close->{"tricks"}
$at_close $at_close->{"tricks"}
Truth table66%2/3
A and B
A= $at_closeB= $at_close->{"tricks"}
ABresult
0X0
100
111
65 45 return { %r, how => 'beat_closer', winner => $me, loser => $them,
66 game_points => $gp };
67 }
68  
69 my $at = defined $o{closed_by}
70 2442 ▶ ? Game::Schnapsen::Variant::close_counts_tricks_at($v)
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'closed_by'} ? : 849 1593 2442
71 : 'end';
72 2442 my $s = _state(\%o, $them, $at);
73 return { %r, how => defined $o{closed_by} ? 'closed_out' : 'claim',
74 winner => $me, loser => $them,
75 2442 ▶ game_points => scale($s->{points}, $s->{tricks}) };
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'closed_by'} ? : 849 1593 2442
76 }
77  
78 1754 ▶ if (defined $o{closed_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{"closed_by"}) 113 1641 1754
79 113 my $winner = _other($o{closed_by});
80 113 ▶ my $at_close = $o{close_state} ? $o{close_state}{$winner} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o{'close_state'} ? : 113 0 113
81 return { %r, how => 'failed_close', winner => $winner, loser => $o{closed_by},
82 game_points => ($at_close && $at_close->{tricks})
83 113 ▶ ? PENALTY : PENALTY_SCHWARZ };
Branch: 1 branch
BranchTrueFalseTotal
$at_close && $at_close->{'tricks'} ? : 79 34 113
Condition66%2/3
$at_close and $at_close->{"tricks"}
!ll&&!rl&&r
03479
MC/DC50%1/2
$at_close and $at_close->{"tricks"}
$at_close $at_close->{"tricks"}
Truth table66%2/3
A and B
A= $at_closeB= $at_close->{"tricks"}
ABresult
0X0
100
111
84 }
85  
86 1641 ▶ if (Game::Schnapsen::Variant::last_trick_rule($v) eq 'one_point') {
Branch: 1 branch
BranchTrueFalseTotal
if (Game::Schnapsen::Variant::last_trick_rule($v) eq "one_point") 954 687 1641
87 return { %r, how => 'last_trick', winner => $o{last_trick},
88 954 loser => _other($o{last_trick}), game_points => 1 };
89 }
90  
91 687 my %final = %{ $o{points} };
92 687 $final{ $o{last_trick} } += LAST_TRICK_BONUS;
93 687 $r{points} = \%final;
94  
95 687 ▶ if ($final{p1} == $final{p2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final{"p1"} == $final{"p2"}) 19 668 687
96 19 return { %r, how => 'drawn', winner => undef, loser => undef,
97 game_points => 0, drawn => 1 };
98 }
99  
100 668 ▶ my $winner = $final{p1} > $final{p2} ? 'p1' : 'p2';
Branch: 1 branch
BranchTrueFalseTotal
$final{'p1'} > $final{'p2'} ? : 324 344 668
101 668 my $loser = _other($winner);
102 return { %r, how => 'last_trick', winner => $winner, loser => $loser,
103 668 game_points => scale($final{$loser}, $o{tricks}{$loser}) };
104 }
105  
106 22 1;
107  
108 __END__
« blib/lib/Game/Schnapsen/Terminal.pm ↑ Summary blib/lib/Game/Schnapsen/Bot.pm »