| 1 | package Game::Oware::Board; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 24 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 24 | ▶ | use constant HOUSES => 12; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 24 | ▶ | use constant CELLS => 14; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 24 | ▶ | use constant SEEDS => 48; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 24 | ▶ | use constant PER_HOUSE => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 24 | ▶ | use constant P1_STORE => 12; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 24 | ▶ | use constant P2_STORE => 13; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 82 | ▶ | sub opening { return [ (PER_HOUSE) x HOUSES, 0, 0 ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opening: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub clone { my ($class, $board) = @_; return [ @$board ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 122 | ▶ | sub total { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
total: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 122 | my ($class, $board) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 122 | my $total = 0; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 122 | $total += $_ for @$board; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 122 | return $total; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1670068 | ▶ | sub other { my ($class, $seat) = @_; return $seat eq 'p1' ? 'p2' : 'p1' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
other: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 469151 | ▶ | sub store_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
store_of: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 469151 | my ($class, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 469151 | ▶ | die "Game::Oware::Board: there is no seat '$seat'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seat eq "p1" or $seat eq "p2"
MC/DC0%0/2
$seat eq "p1" or $seat eq "p2"
$seat eq "p1"
$seat eq "p2"
Truth table66%2/3
A or B
A= $seat eq "p1"B= $seat eq "p2"
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | unless $seat eq 'p1' || $seat eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 469151 | ▶ | return $seat eq 'p1' ? P1_STORE : P2_STORE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1096710 | ▶ | sub owner_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
owner_of: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1096710 | my ($class, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1096710 | $class->assert_house($house); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1096708 | ▶ | return $house < 6 ? 'p1' : 'p2'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 1303584 | ▶ | sub houses_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
houses_of: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1303584 | my ($class, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 1303584 | ▶ | die "Game::Oware::Board: there is no seat '$seat'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seat eq "p1" or $seat eq "p2"
MC/DC0%0/2
$seat eq "p1" or $seat eq "p2"
$seat eq "p1"
$seat eq "p2"
Truth table66%2/3
A or B
A= $seat eq "p1"B= $seat eq "p2"
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | unless $seat eq 'p1' || $seat eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1303584 | ▶ | return $seat eq 'p1' ? (0 .. 5) : (6 .. 11); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 686751 | ▶ | sub seeds_on_side { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seeds_on_side: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 686751 | my ($class, $board, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 686751 | my $seeds = 0; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 686751 | $seeds += $board->[$_] for $class->houses_of($seat); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 686751 | return $seeds; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2984563 | ▶ | sub assert_house { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assert_house: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 2984563 | my ($class, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 2984563 | ▶ | die 'Game::Oware::Board: a house is 0 to 11' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $house and $house =~ /\A\d+\z/ and $house < 12
defined $house and $house =~ /\A\d+\z/
MC/DC66%2/3
defined $house and $house =~ /\A\d+\z/ and $house < 12
defined $house
$house =~ /\A\d+\z/
$house < 12
Truth table75%3/4
A and B and C
A= defined $houseB= $house =~ /\A\d+\z/C= $house < 12
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | unless defined $house && $house =~ /\A\d+\z/ && $house < HOUSES; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 2984555 | return $house; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 469236 | ▶ | sub sow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sow: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 469236 | my ($class, $board, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 469236 | $class->assert_house($house); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 469234 | my $hand = $board->[$house]; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 469234 | ▶ | die "Game::Oware::Board: house $house is empty, so there is nothing to sow" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | unless $hand; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 469233 | my $next = [ @$board ]; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 469233 | $next->[$house] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 469233 | my $i = $house; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 469233 | my $last = $house; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 469233 | ▶ | while ($hand) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1827860 | $i = ($i + 1) % HOUSES; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1827860 | ▶ | next if $i == $house; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1823579 | $next->[$i]++; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1823579 | $last = $i; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1823579 | $hand--; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 469233 | return ($next, $last, $board->[$house]); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 469234 | ▶ | sub capture_chain { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture_chain: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 469234 | my ($class, $board, $last, $sown, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 469234 | $class->assert_house($last); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 469233 | my $foe = $class->other($seat); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 469233 | my @chain; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 469233 | my $i = $last; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 469233 | ▶ | while (@chain < $sown) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 543501 | ▶ | last unless $class->owner_of($i) eq $foe; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 312721 | my $count = $board->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 312721 | ▶ | last unless $count == 2 || $count == 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$count == 2 or $count == 3
MC/DC100%2/2
$count == 2 or $count == 3
$count == 2
$count == 3
Truth table100%3/3
A or B
A= $count == 2B= $count == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 81388 | push @chain, $i; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 81388 | $i = ($i - 1) % HOUSES; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 469233 | return @chain; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||||||||||||||||