| 1 | package Game::Reversi::Move; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Game::Reversi::Board; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | has phase => ( | ||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | has square => ( | ||||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | isa => Int | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | has colour => ( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | has flips => ( | ||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | isa => ArrayRef | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 201199 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=15 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 201199 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 201199 | ▶ | my $phase = $self->phase // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->phase // ""
MC/DC0%0/1
$self->phase // ""
$self->phase
Truth table50%1/2
A
A= $self->phase
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 201199 | ▶ | die "Game::Reversi::Move: phase must be place or play, not '$phase'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$phase eq "place" or $phase eq "play"
MC/DC0%0/2
$phase eq "place" or $phase eq "play"
$phase eq "place"
$phase eq "play"
Truth table66%2/3
A or B
A= $phase eq "place"B= $phase eq "play"
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | unless $phase eq 'place' || $phase eq 'play'; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 201199 | ▶ | my $colour = $self->colour // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->colour // ""
MC/DC0%0/1
$self->colour // ""
$self->colour
Truth table50%1/2
A
A= $self->colour
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 201199 | ▶ | die "Game::Reversi::Move: colour must be b or w, not '$colour'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$colour eq "b" or $colour eq "w"
MC/DC100%2/2
$colour eq "b" or $colour eq "w"
$colour eq "b"
$colour eq "w"
Truth table100%3/3
A or B
A= $colour eq "b"B= $colour eq "w"
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | unless $colour eq 'b' || $colour eq 'w'; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 201198 | my $square = $self->square; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 201198 | ▶ | die 'Game::Reversi::Move: square must be 0 to 63' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $square and $square =~ /\A\d+\z/ and $square < 64
defined $square and $square =~ /\A\d+\z/
MC/DC33%1/3
defined $square and $square =~ /\A\d+\z/ and $square < 64
defined $square
$square =~ /\A\d+\z/
$square < 64
Truth table50%2/4
A and B and C
A= defined $squareB= $square =~ /\A\d+\z/C= $square < 64
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | unless defined $square && $square =~ /\A\d+\z/ && $square < 64; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 201197 | ▶ | my $flips = $self->flips || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->flips || []
MC/DC0%0/1
$self->flips || []
$self->flips
Truth table50%1/2
A
A= $self->flips
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 201197 | ▶ | die 'Game::Reversi::Move: a placement flips nothing' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$phase eq "place" and @$flips
MC/DC100%2/2
$phase eq "place" and @$flips
$phase eq "place"
@$flips
Truth table100%3/3
A and B
A= $phase eq "place"B= @$flips
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | if $phase eq 'place' && @$flips; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 201196 | ▶ | die 'Game::Reversi::Move: a play flips at least one disc' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$phase eq "play" and not @$flips
MC/DC100%2/2
$phase eq "play" and not @$flips
$phase eq "play"
not @$flips
Truth table100%3/3
A and not(B)
A= $phase eq "play"B= not @$flips
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | if $phase eq 'play' && !@$flips; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 201195 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1221 | ▶ | sub place { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1221 | my ($class, $square, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1221 | return $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 58 | phase => 'place', square => $square, colour => $colour, flips => []); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 199977 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 199977 | my ($class, $square, $colour, @flips) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 199977 | return $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 64 | phase => 'play', square => $square, colour => $colour, flips => [ @flips ]); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 318 | ▶ | sub name { my ($self) = @_; return Game::Reversi::Board->name_of($self->square) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 633 | ▶ | sub turned { my ($self) = @_; return scalar @{ $self->flips || [] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turned: called CC=2 SCAR=7.1
Pod
documented
Condition50%1/2
$self->flips || []
MC/DC0%0/1
$self->flips || []
$self->flips
Truth table50%1/2
A
A= $self->flips
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||||||