| 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
Condition33%1/3
defined $seed and length $seed == 32
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
| |||||||||||||||||||||||||||||
| 26 | unless defined $seed && length $seed == 32; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 221 | ▶ | my $dealer = $o{dealer} || 'p1'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$o{'dealer'} || 'p1'
MC/DC0%0/1
$o{'dealer'} || 'p1'
$o{'dealer'}
Truth table50%1/2
A
A= $o{'dealer'}
| |||||||||||||||||||||||||||||
| 29 | my $self = $class->new( | ||||||||||||||||||||||||||||
| 30 | seed => $seed, | ||||||||||||||||||||||||||||
| 31 | 221 | ▶ | target => $o{target} || TARGET, | ||||||||||||||||||||||||||
|
Condition50%1/2
$o{'target'} || 100
MC/DC0%0/1
$o{'target'} || 100
$o{'target'}
Truth table50%1/2
A
A= $o{'target'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
@out == 1 and ref $out[0] eq "Game::Gin::Error"
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"
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 59967 | ▶ | return @out unless $self->deal->over; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$scores->{"p1"} >= $self->target or $scores->{"p2"} >= $self->target
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||