Gin.pm

filter: Statementstmt 100% 66 / 66 Branchbran 80.0% 16 / 20 Conditioncond 69.2% 9 / 13 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 12 / 12 Podpod 100% 6 / 6 totaltotal 90.4% 113 / 125 CC 17 SCAR 14.6
CC
17
Cov
92%
apply
8.0
build
5.9
scores
3.0
CRAP 4.3
« Gin/Deadwood.pm ↑ Summary Gin/Deck.pm »
1 package Game::Gin;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use Game::Gin::Deal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Game::Gin::Error ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Game::Gin::Scoring qw(match_result TARGET);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 our $VERSION = '0.03';
13  
14 7 has seed => (is => 'ro', isa => Str);
15 7 has target => (is => 'ro', isa => Int);
16 7 has dealer => (is => 'rw', isa => Str);
17 7 has deal => (is => 'rw', isa => Object);
18 7 has number => (is => 'rw', isa => Int);
19 7 has hands => (is => 'rw', isa => ArrayRef);
20 7 has result => (is => 'rw', isa => HashRef);
21  
22 221 ▶sub build {
Subroutine build: called CC=5 SCAR=17.8
Pod documented
23 221 my ($class, %o) = @_;
24 221 my $seed = $o{seed};
25 221 ▶ return Game::Gin::Error->new_code('no_seed')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seed and length $seed == 32 0 221 221
Condition33%1/3
defined $seed and length $seed == 32
!ll&&!rl&&r
00221
MC/DC0%0/2
defined $seed and length $seed == 32
defined $seed length $seed == 32
Truth table33%1/3
A and B
A= defined $seedB= length $seed == 32
ABresult
0X0
100
111
26 unless defined $seed && length $seed == 32;
27  
28 221 ▶ my $dealer = $o{dealer} || 'p1';
Condition50%1/2
$o{'dealer'} || 'p1'
l!l
2210
MC/DC0%0/1
$o{'dealer'} || 'p1'
$o{'dealer'}
Truth table50%1/2
A
A= $o{'dealer'}
Aresult
11
00
29 my $self = $class->new(
30 seed => $seed,
31 221 ▶ target => $o{target} || TARGET,
Condition50%1/2
$o{'target'} || 100
l!l
0221
MC/DC0%0/1
$o{'target'} || 100
$o{'target'}
Truth table50%1/2
A
A= $o{'target'}
Aresult
11
00
32 dealer => $dealer,
33 number => 1,
34 hands => [],
35 deal => Game::Gin::Deal->build(seed => $seed, number => 1, dealer => $dealer),
36 result => undef,
37 );
38 221 return $self;
39 }
40  
41 205301 ▶sub over { return $_[0]->result ? 1 : 0 }
Subroutine over: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->result ? : 297 205004 205301
42 55902 ▶sub turn { my $s = $_[0]; return undef if $s->over; return $s->deal->turn }
Subroutine turn: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $s->over 0 55902 55902
43 14518 ▶sub legal { my ($s, $seat) = @_; return [] if $s->over; return $s->deal->legal($seat) }
Subroutine legal: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $s->over 0 14518 14518
44  
45 2106 ▶sub scores {
Subroutine scores: called CC=3 SCAR=11.0
Pod documented
46 2106 my ($self) = @_;
47 2106 my %p = (p1 => 0, p2 => 0);
48 2106 for my $h (@{ $self->hands }) {
49 12623 ▶ next unless $h->{winner};
Branch: 1 branch
BranchTrueFalseTotal
unless $h->{"winner"} 144 12479 12623
50 12479 $p{ $h->{winner} } += $h->{points};
51 }
52 2106 return \%p;
53 }
54  
55 59969 ▶sub apply {
Subroutine apply: called CC=8 SCAR=20.8
Pod documented
56 59969 my ($self, $seat, $move) = @_;
57 59969 ▶ return Game::Gin::Error->new_code('hand_over') if $self->over;
Branch: 1 branch
BranchTrueFalseTotal
if $self->over 0 59969 59969
58  
59 59969 my @out = $self->deal->apply($seat, $move);
60 59969 ▶ return $out[0] if @out == 1 && ref $out[0] eq 'Game::Gin::Error';
Branch: 1 branch
BranchTrueFalseTotal
if @out == 1 and ref $out[0] eq "Game::Gin::Error" 2 59967 59969
Condition100%3/3
@out == 1 and ref $out[0] eq "Game::Gin::Error"
!ll&&!rl&&r
2036579312
MC/DC100%2/2
@out == 1 and ref $out[0] eq "Game::Gin::Error"
@out == 1 ref $out[0] eq "Game::Gin::Error"
Truth table100%3/3
A and B
A= @out == 1B= ref $out[0] eq "Game::Gin::Error"
ABresult
0X0
100
111
61  
62 59967 ▶ return @out unless $self->deal->over;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->deal->over 57931 2036 59967
63  
64 2036 my $r = $self->deal->result;
65 2036 push @{ $self->hands }, { %$r, number => $self->number };
66  
67 2036 my $scores = $self->scores;
68 2036 ▶ if (($scores->{p1} >= $self->target) || ($scores->{p2} >= $self->target)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scores->{"p1"} >= $self->target or $scores->{"p2"} >= $self->target) 197 1839 2036
Condition100%3/3
$scores->{"p1"} >= $self->target or $scores->{"p2"} >= $self->target
l!l&&r!l&&!r
116811839
MC/DC100%2/2
$scores->{"p1"} >= $self->target or $scores->{"p2"} >= $self->target
$scores->{"p1"} >= $self->target $scores->{"p2"} >= $self->target
Truth table100%3/3
A or B
A= $scores->{"p1"} >= $self->targetB= $scores->{"p2"} >= $self->target
ABresult
1X1
011
000
69 197 my $m = match_result(hands => $self->hands, target => $self->target);
70 197 $self->result($m);
71 197 push @out, { kind => 'game_end', %$m };
72 197 return @out;
73 }
74  
75 1839 ▶ $self->dealer($r->{winner}) if $r->{winner};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"winner"} 1821 18 1839
76 1839 $self->number($self->number + 1);
77 1839 $self->deal(Game::Gin::Deal->build(
78 seed => $self->seed, number => $self->number, dealer => $self->dealer));
79 1839 push @out, { kind => 'deal', number => $self->number, dealer => $self->dealer };
80 1839 return @out;
81 }
82  
83 7 1;
84  
85 __END__
« Gin/Deadwood.pm ↑ Summary Gin/Deck.pm »