| 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.02'; | |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 26 | 2986 | ▶ | return 2 if $points < SCHNEIDER_AT; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$at eq "close" and $o->{"close_state"}
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"}
| |||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$o{"how"} // ""
MC/DC0%0/1
$o{"how"} // ""
$o{"how"}
Truth table50%1/2
A
A= $o{"how"}
| |||||||||||||||||||||||||||||||||
| 50 | 2495 | my $me = $o{by}; | |||||||||||||||||||||||||||||||
| 51 | 2495 | my $them = _other($me); | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 2495 | ▶ | unless ($o{points}{$me} >= TARGET_POINTS) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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}
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}
| |||||||||||||||||||||||||||||||||
| 56 | 8 | ▶ | return { %r, how => 'false_claim', winner => $them, loser => $me, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 57 | game_points => $schwarz ? PENALTY_SCHWARZ : PENALTY }; | ||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 2487 | ▶ | if (defined $o{closed_by} && $o{closed_by} ne $me) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $o{"closed_by"} and $o{"closed_by"} ne $me
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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 63 | my $gp = $flat ? PENALTY | ||||||||||||||||||||||||||||||||
| 64 | 45 | ▶ | : (($at_close && $at_close->{tricks}) ? PENALTY : PENALTY_SCHWARZ); | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$at_close and $at_close->{"tricks"}
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"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 1754 | ▶ | if (defined $o{closed_by}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 113 | my $winner = _other($o{closed_by}); | |||||||||||||||||||||||||||||||
| 80 | 113 | ▶ | my $at_close = $o{close_state} ? $o{close_state}{$winner} : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$at_close and $at_close->{"tricks"}
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"}
| |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 1641 | ▶ | if (Game::Schnapsen::Variant::last_trick_rule($v) eq 'one_point') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||