| 1 | package Game::Schnapsen::Trick; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 23 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 23 | ▶ | use Game::Schnapsen::Card qw(suit_of power_of points_of); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 23 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 11 | 23 | 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
| |||||||||||||||||||||||||||||
| 19 | 153871 | ▶ | return $follow if $fs eq $trump; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | 21625 | ▶ | return scalar(grep { power_of($_) > power_of($lead) } @suited) ? 'beat' : 'follow'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 18778 | ▶ | return scalar(grep { suit_of($_) eq $trump } @$hand) ? 'trump' : 'free'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
suit_of($_) eq $ls && power_of($_) > power_of($lead)
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)
| |||||||||||||||||||||||||||||
| 48 | if $band eq 'beat'; | ||||||||||||||||||||||||||||
| 49 | 24265 | ▶ | return [ grep { suit_of($_) eq $ls } @$hand ] if $band eq 'follow'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 10274 | return [ grep { suit_of($_) eq $trump } @$hand ]; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 23 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||