| 1 | package Game::Durak::Card; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | our @EXPORT_OK = qw(rank_of suit_of power_of name_of long_name_of face_of | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | id_of ids_of_suit six_of beats ranks suits CARDS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use constant CARDS => 36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | my @RANKS = qw(A K Q J T 9 8 7 6); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | my @SUITS = qw(S H D C); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | my %RANK_NAME = (A => 'ace', K => 'king', Q => 'queen', J => 'jack', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | T => 'ten', 9 => 'nine', 8 => 'eight', 7 => 'seven', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 => 'six'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | my %SUIT_NAME = (S => 'spades', H => 'hearts', D => 'diamonds', C => 'clubs'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | my %RANK_AT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | @RANK_AT{@RANKS} = 0 .. $#RANKS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | my %SUIT_AT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | @SUIT_AT{@SUITS} = 0 .. $#SUITS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub ranks { return @RANKS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ranks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 220 | ▶ | sub suits { return @SUITS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
suits: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7417 | ▶ | sub _card { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_card: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7417 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 7417 | ▶ | die 'Game::Durak::Card: no card has id ' . (defined $id ? "'$id'" : 'undef') . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition88%8/9
defined $id and $id =~ /\A[1-9][0-9]*\z/ and $id >= 1 and $id <= 36
defined $id and $id =~ /\A[1-9][0-9]*\z/ and $id >= 1
defined $id and $id =~ /\A[1-9][0-9]*\z/
MC/DC75%3/4
defined $id and $id =~ /\A[1-9][0-9]*\z/ and $id >= 1 and $id <= 36
defined $id
$id =~ /\A[1-9][0-9]*\z/
$id >= 1
$id <= 36
Truth table80%4/5
A and B and C and D
A= defined $idB= $id =~ /\A[1-9][0-9]*\z/C= $id >= 1D= $id <= 36
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | unless defined $id && $id =~ /\A[1-9][0-9]*\z/ && $id >= 1 && $id <= CARDS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 7411 | return $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 32 | ▶ | sub _suit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_suit: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 32 | my ($suit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | die 'Game::Durak::Card: no suit is ' . (defined $suit ? "'$suit'" : 'undef') . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 32 | ▶ | unless defined $suit && exists $SUIT_AT{$suit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $suit and exists $SUIT_AT{$suit}
MC/DC50%1/2
defined $suit and exists $SUIT_AT{$suit}
defined $suit
exists $SUIT_AT{$suit}
Truth table66%2/3
A and B
A= defined $suitB= exists $SUIT_AT{$suit}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 30 | return $suit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1668 | ▶ | sub rank_of { my $id = _card($_[0]); return $RANKS[ ($id - 1) % @RANKS ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rank_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 5695 | ▶ | sub suit_of { my $id = _card($_[0]); return $SUITS[ int(($id - 1) / @RANKS) ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
suit_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1479 | ▶ | sub power_of { return $#RANKS - $RANK_AT{ rank_of($_[0]) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
power_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 144 | ▶ | sub name_of { my ($id) = @_; return rank_of($id) . suit_of($id) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | my %FACE = (T => '10'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub face_of { my ($id) = @_; my $rank = rank_of($id); return $FACE{$rank} // $rank } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
face_of: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
$FACE{$rank} // $rank
MC/DC0%0/2
$FACE{$rank} // $rank
$FACE{$rank}
$rank
Truth table0%0/3
A // B
A= $FACE{$rank}B= $rank
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | sub long_name_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
long_name_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | return $RANK_NAME{ rank_of($id) } . ' of ' . $SUIT_NAME{ suit_of($id) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | my %ID; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | for my $id (1 .. CARDS) { $ID{ name_of($id) } = $id } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 267 | ▶ | sub id_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id_of: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 267 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 267 | ▶ | return undef unless defined $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 266 | return $ID{ uc $name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | sub ids_of_suit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ids_of_suit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | my ($suit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $at = $SUIT_AT{ _suit($suit) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | return [ map { $at * @RANKS + $_ } 1 .. scalar @RANKS ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub six_of { my ($suit) = @_; return $ID{ '6' . _suit($suit) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
six_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 27 | ▶ | sub beats { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
beats: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 27 | my ($def, $att, $trump) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 27 | _card($def); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 27 | _card($att); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 27 | _suit($trump); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 26 | ▶ | return 0 if $def == $att; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 25 | my $ds = suit_of($def); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 25 | my $as = suit_of($att); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 25 | ▶ | return ($ds eq $trump && power_of($def) > power_of($att)) ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$ds eq $trump and power_of($def) > power_of($att)
MC/DC100%2/2
$ds eq $trump and power_of($def) > power_of($att)
$ds eq $trump
power_of($def) > power_of($att)
Truth table100%3/3
A and B
A= $ds eq $trumpB= power_of($def) > power_of($att)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | if $as eq $trump; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 15 | ▶ | return 1 if $ds eq $trump; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 10 | ▶ | return ($ds eq $as && power_of($def) > power_of($att)) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ds eq $as and power_of($def) > power_of($att)
MC/DC100%2/2
$ds eq $as and power_of($def) > power_of($att)
$ds eq $as
power_of($def) > power_of($att)
Truth table100%3/3
A and B
A= $ds eq $asB= power_of($def) > power_of($att)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||