| 1 | package Game::Oware::Move; | ||||||||||||||||||||||||||||||||||||||||||
| 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 Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 23 | ▶ | use Game::Oware::Board; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 23 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | has seat => ( | ||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | has house => ( | ||||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | isa => Int | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | has sown => ( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | isa => Int | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | has last => ( | ||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | isa => Int | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | has captured => ( | ||||||||||||||||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | default => [] | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | has taken => ( | ||||||||||||||||||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | has slammed => ( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | has forfeited => ( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | default => [] | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 525395 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 525395 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 525395 | ▶ | my $seat = $self->seat // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->seat // ""
MC/DC0%0/1
$self->seat // ""
$self->seat
Truth table50%1/2
A
A= $self->seat
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 525395 | ▶ | die "Game::Oware::Move: seat must be p1 or p2, not '$seat'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$seat eq "p1" or $seat eq "p2"
MC/DC100%2/2
$seat eq "p1" or $seat eq "p2"
$seat eq "p1"
$seat eq "p2"
Truth table100%3/3
A or B
A= $seat eq "p1"B= $seat eq "p2"
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | unless $seat eq 'p1' || $seat eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 525394 | Game::Oware::Board->assert_house($self->house); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 525393 | Game::Oware::Board->assert_house($self->last); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 525393 | ▶ | die 'Game::Oware::Move: a seat may only sow from its own house' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | unless Game::Oware::Board->owner_of($self->house) eq $seat; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 525392 | my $sown = $self->sown; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 525392 | ▶ | die 'Game::Oware::Move: a move sows at least one seed' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $sown and $sown =~ /\A\d+\z/ and $sown > 0
defined $sown and $sown =~ /\A\d+\z/
MC/DC33%1/3
defined $sown and $sown =~ /\A\d+\z/ and $sown > 0
defined $sown
$sown =~ /\A\d+\z/
$sown > 0
Truth table50%2/4
A and B and C
A= defined $sownB= $sown =~ /\A\d+\z/C= $sown > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | unless defined $sown && $sown =~ /\A\d+\z/ && $sown > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 525391 | my $captured = $self->captured; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 525391 | ▶ | die 'Game::Oware::Move: a move never captures more houses than it sowed' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | if @$captured > $sown; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | die 'Game::Oware::Move: a seat never captures its own house' | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 525390 | ▶ | if grep { Game::Oware::Board->owner_of($_) eq $seat } @$captured; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 525389 | ▶ | die 'Game::Oware::Move: taken disagrees with captured' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @$captured and $self->taken
MC/DC100%2/2
not @$captured and $self->taken
not @$captured
$self->taken
Truth table100%3/3
not(A) and B
A= not @$capturedB= $self->taken
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | if !@$captured && $self->taken; | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 525388 | my $forfeited = $self->forfeited; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 525388 | ▶ | die 'Game::Oware::Move: a move either captured its chain or forfeited it' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$forfeited and @$captured
MC/DC100%2/2
@$forfeited and @$captured
@$forfeited
@$captured
Truth table100%3/3
A and B
A= @$forfeitedB= @$captured
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | if @$forfeited && @$captured; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 525387 | ▶ | die 'Game::Oware::Move: only a grand slam forfeits a chain' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$forfeited and not $self->slammed
MC/DC100%2/2
@$forfeited and not $self->slammed
@$forfeited
not $self->slammed
Truth table100%3/3
A and not(B)
A= @$forfeitedB= not $self->slammed
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | if @$forfeited && !$self->slammed; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 525386 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | require Game::Oware::Notation; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | return Game::Oware::Notation->letter_of($self->house); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | my $name = $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | ▶ | return $name . ' (slam forfeited)' if @{ $self->forfeited }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | return $name unless @{ $self->captured }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | return $name . ' takes ' . $self->taken . ($self->slammed ? ' (slam)' : ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||||||||||||||||