| 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.03'; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$have{$suit}{"K"} and $have{$suit}{"Q"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | 38414 | ▶ | return scalar(grep { $_ == $want } @$cards) ? $want : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 20 | 1; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||||||