| 1 | package Game::Oware::Notation; | ||||||||||||||||||||||||||||||||||||||||||
| 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 Game::Oware::Board; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 23 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 23 | my @LETTER = ('A' .. 'F', 'a' .. 'f'); | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 23 | my %INDEX = map { $LETTER[$_] => $_ } 0 .. $#LETTER; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub letters { return @LETTER } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
letters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 24795 | ▶ | sub letter_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
letter_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 24795 | my ($class, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 24795 | Game::Oware::Board->assert_house($house); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 24794 | return $LETTER[$house]; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2117 | ▶ | sub index_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
index_of: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2117 | my ($class, $letter) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | die 'Game::Oware::Notation: a house is one of ABCDEFabcdef' | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 2117 | ▶ | unless defined $letter && exists $INDEX{$letter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $letter and exists $INDEX{$letter}
MC/DC100%2/2
defined $letter and exists $INDEX{$letter}
defined $letter
exists $INDEX{$letter}
Truth table100%3/3
A and B
A= defined $letterB= exists $INDEX{$letter}
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2111 | return $INDEX{$letter}; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub seat_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seat_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | my ($class, $letter) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | return Game::Oware::Board->owner_of($class->index_of($letter)); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 488 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 488 | my ($class, $houses) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 488 | return join '', map { $class->letter_of($_) } @$houses; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 42 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 42 | my ($class, $text, $first) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 42 | ▶ | die 'Game::Oware::Notation: a transcript is a string' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 42 | ▶ | die 'Game::Oware::Notation: the first seat is p1 or p2' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $first and $first ne "p1" and $first ne "p2"
defined $first and $first ne "p1"
MC/DC0%0/3
defined $first and $first ne "p1" and $first ne "p2"
defined $first
$first ne "p1"
$first ne "p2"
Truth table75%3/4
A and B and C
A= defined $firstB= $first ne "p1"C= $first ne "p2"
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | if defined $first && $first ne 'p1' && $first ne 'p2'; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 42 | $text =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 42 | ▶ | return [] unless length $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 34 | my @houses; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 34 | ▶ | my $expect = $first // 'p1'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$first // "p1"
MC/DC100%1/1
$first // "p1"
$first
Truth table100%2/2
A
A= $first
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 34 | for my $letter (split //, $text) { | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1886 | my $house = $class->index_of($letter); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1886 | my $seat = Game::Oware::Board->owner_of($house); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1886 | ▶ | die "Game::Oware::Notation: $letter is ${seat}'s move, but it is " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | . "$expect to play, and the seats alternate" | ||||||||||||||||||||||||||||||||||||||||||
| 56 | unless $seat eq $expect; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 1882 | push @houses, $house; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 1882 | $expect = Game::Oware::Board->other($expect); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 30 | return \@houses; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | sub board_to_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_to_text: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my ($class, $board) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | die 'Game::Oware::Notation: a board is fourteen cells' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $board eq "ARRAY" and @$board == "Game::Oware::Board"->CELLS
MC/DC50%1/2
ref $board eq "ARRAY" and @$board == "Game::Oware::Board"->CELLS
ref $board eq "ARRAY"
@$board == "Game::Oware::Board"->CELLS
Truth table66%2/3
A and B
A= ref $board eq "ARRAY"B= @$board == "Game::Oware::Board"->CELLS
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | unless ref $board eq 'ARRAY' && @$board == Game::Oware::Board->CELLS; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my @top = map { $board->[$_] } reverse 6 .. 11; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my @bottom = map { $board->[$_] } 0 .. 5; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | return join "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 12 | ' ' . join(' ', map { sprintf '%2s', $_ } reverse 'a' .. 'f'), | |||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | ' ' . join(' ', map { sprintf '%2d', $_ } @top) | |||||||||||||||||||||||||||||||||||||||||
| 75 | . ' [' . $board->[Game::Oware::Board->P2_STORE] . ']', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 12 | ' ' . join(' ', map { sprintf '%2d', $_ } @bottom) | |||||||||||||||||||||||||||||||||||||||||
| 77 | . ' [' . $board->[Game::Oware::Board->P1_STORE] . ']', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ' ' . join(' ', map { sprintf '%2s', $_ } 'A' .. 'F'); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | sub text_to_board { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_to_board: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | my ($class, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | ▶ | die 'Game::Oware::Notation: a board is a string' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | my @rows; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | for my $line (split /\n/, $text) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | 14 | ▶ | next unless $line =~ /\d/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | ▶ | my ($counts, $store) = $line =~ /\A([^\[]*)(?:\[\s*(\d+)\s*\])?\s*\z/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | or die "Game::Oware::Notation: cannot read '$line'"; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 10 | my @counts = $counts =~ /(\d+)/g; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 10 | ▶ | die "Game::Oware::Notation: a row is six houses, not " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | . scalar(@counts) . " in '$line'" | ||||||||||||||||||||||||||||||||||||||||||
| 94 | unless @counts == 6; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 9 | ▶ | push @rows, [ \@counts, $store || 0 ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$store || 0
MC/DC100%1/1
$store || 0
$store
Truth table100%2/2
A
A= $store
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | ▶ | die 'Game::Oware::Notation: a board is two rows of houses' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | unless @rows == 2; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | my ($top, $bottom) = @rows; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | my @board; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | @board[0 .. 5] = @{ $bottom->[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | @board[6 .. 11] = reverse @{ $top->[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | $board[ Game::Oware::Board->P1_STORE ] = $bottom->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | $board[ Game::Oware::Board->P2_STORE ] = $top->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | return \@board; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||||||||||||||||