| 1 | package Game::Oware::Scoring; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 21 | ▶ | use Game::Oware::Board; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 21 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 21 | ▶ | use constant TO_WIN => 25; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use constant DRAW_AT => 24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 721280 | ▶ | sub captured { | ||||||||||||||||||||||||||
|
Subroutine
captured: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 721280 | my ($class, $board) = @_; | |||||||||||||||||||||||||||
| 15 | return { | ||||||||||||||||||||||||||||
| 16 | 721280 | p1 => $board->[ Game::Oware::Board->P1_STORE ], | |||||||||||||||||||||||||||
| 17 | p2 => $board->[ Game::Oware::Board->P2_STORE ], | ||||||||||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 469231 | ▶ | sub taken { | ||||||||||||||||||||||||||
|
Subroutine
taken: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 469231 | my ($class, $board, $chain) = @_; | |||||||||||||||||||||||||||
| 23 | 469231 | my $seeds = 0; | |||||||||||||||||||||||||||
| 24 | 469231 | $seeds += $board->[$_] for @$chain; | |||||||||||||||||||||||||||
| 25 | 469231 | return $seeds; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | sub leader { | ||||||||||||||||||||||||||
|
Subroutine
leader: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 2 | my ($class, $board) = @_; | |||||||||||||||||||||||||||
| 30 | 2 | my $captured = $class->captured($board); | |||||||||||||||||||||||||||
| 31 | 2 | ▶ | return undef if $captured->{p1} == $captured->{p2}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | return $captured->{p1} > $captured->{p2} ? 'p1' : 'p2'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 277026 | ▶ | sub target_reached { | ||||||||||||||||||||||||||
|
Subroutine
target_reached: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 277026 | my ($class, $board) = @_; | |||||||||||||||||||||||||||
| 37 | 277026 | my $captured = $class->captured($board); | |||||||||||||||||||||||||||
| 38 | 277026 | ▶ | return 'p1' if $captured->{p1} >= TO_WIN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 276487 | ▶ | return 'p2' if $captured->{p2} >= TO_WIN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 276268 | return undef; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 276268 | ▶ | sub is_draw { | ||||||||||||||||||||||||||
|
Subroutine
is_draw: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 276268 | my ($class, $board) = @_; | |||||||||||||||||||||||||||
| 45 | 276268 | my $captured = $class->captured($board); | |||||||||||||||||||||||||||
| 46 | 276268 | ▶ | return $captured->{p1} == DRAW_AT && $captured->{p2} == DRAW_AT ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$captured->{"p1"} == 24 and $captured->{"p2"} == 24
MC/DC100%2/2
$captured->{"p1"} == 24 and $captured->{"p2"} == 24
$captured->{"p1"} == 24
$captured->{"p2"} == 24
Truth table100%3/3
A and B
A= $captured->{"p1"} == 24B= $captured->{"p2"} == 24
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | ▶ | sub score { | ||||||||||||||||||||||||||
|
Subroutine
score: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 4 | my ($class, $board, $status) = @_; | |||||||||||||||||||||||||||
| 51 | 4 | ▶ | return undef unless defined $status && $status eq 'finished'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $status and $status eq "finished"
MC/DC50%1/2
defined $status and $status eq "finished"
defined $status
$status eq "finished"
Truth table66%2/3
A and B
A= defined $statusB= $status eq "finished"
| |||||||||||||||||||||||||||||
| 52 | 2 | return $class->captured($board); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 36 | ▶ | sub sweep_to { | ||||||||||||||||||||||||||
|
Subroutine
sweep_to: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 36 | my ($class, $board, $seat) = @_; | |||||||||||||||||||||||||||
| 57 | 36 | my $next = [ @$board ]; | |||||||||||||||||||||||||||
| 58 | 36 | my $store = Game::Oware::Board->store_of($seat); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 36 | for my $house (0 .. Game::Oware::Board->HOUSES - 1) { | |||||||||||||||||||||||||||
| 61 | 432 | $next->[$store] += $next->[$house]; | |||||||||||||||||||||||||||
| 62 | 432 | $next->[$house] = 0; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 36 | return $next; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 10 | ▶ | sub sweep_split { | ||||||||||||||||||||||||||
|
Subroutine
sweep_split: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 10 | my ($class, $board) = @_; | |||||||||||||||||||||||||||
| 70 | 10 | my $next = [ @$board ]; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 10 | for my $seat (qw/ p1 p2 /) { | |||||||||||||||||||||||||||
| 73 | 20 | my $store = Game::Oware::Board->store_of($seat); | |||||||||||||||||||||||||||
| 74 | 20 | for my $house (Game::Oware::Board->houses_of($seat)) { | |||||||||||||||||||||||||||
| 75 | 120 | $next->[$store] += $next->[$house]; | |||||||||||||||||||||||||||
| 76 | 120 | $next->[$house] = 0; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 10 | return $next; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 21 | 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||