| 1 | package Games::Go::Cinderblock::Rulemap::Rect; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use 5.14.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | extends 'Games::Go::Cinderblock::Rulemap'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | has h => ( #height | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | default => '19' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | has w => ( #width | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | default => '19' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | has wrap_v => ( #cylinder/torus | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | has wrap_h => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # LoL of all 0's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | sub empty_board{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
empty_board: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | my @rows = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | [ map {0} (1..$self->w) ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } (1..$self->h); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | return \@rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | sub copy_board{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy_board: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | my ($self, $board) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | return [ map {[@$_]} @$board ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 234 | ▶ | sub node_to_string{node_to_id(@_)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node_to_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub node_from_string{node_from_id(@_)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node_from_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | #turns [13,3] into 13*w+3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | #see also &pretty_coordinates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1063 | ▶ | sub node_to_id{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node_to_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1063 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | #return join '-', @$node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1063 | return $node->[0] * $self->w + $node->[1] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub node_from_id{ #return undef if invalid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node_from_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $row = $string / $self->w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $col = $string % $self->w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return [$row,$col]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | #return unless $string =~ /^(\d+)-(\d+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | #return unless $1 < $self->h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | #return unless $2 < $self->w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | #return $node->[0] * $self->w + $node->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | #return [$1,$2]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 359 | ▶ | sub stone_at_node{ #0 if empty, b black, w white, r red, etc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stone_at_node: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 359 | my ($self, $board, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 359 | my ($row, $col) = @$node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 359 | return $board->[$row][$col]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | ▶ | sub set_stone_at_node{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_stone_at_node: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | my ($self, $board, $node, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | my ($row, $col) = @$node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 8 | $board->[$row][$col] = $side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 9 | ▶ | sub all_nodes{ #return list coordinates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_nodes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 9 | my @nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | for my $i (0..$self->h-1){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 26 | push @nodes, map {[$i,$_]} (0..$self->w-1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 9 | return @nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 32 | ▶ | sub node_liberties{goto \&adjacent_nodes} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node_liberties: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 134 | ▶ | sub adjacent_nodes{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
adjacent_nodes: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 134 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 134 | my ($row, $col) = @$node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 134 | my @nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 134 | ▶ | if ($self->wrap_v){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 9 | push @nodes, [($row-1)% $self->h, $col]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | push @nodes, [($row+1)% $self->h, $col]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 125 | ▶ | push @nodes, [$row-1, $col] unless $row == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 125 | ▶ | push @nodes, [$row+1, $col] unless $row == $self->h-1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 134 | ▶ | if ($self->wrap_h){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | push @nodes, [$row, ($col-1)% $self->w]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 9 | push @nodes, [$row, ($col+1)% $self->w]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 125 | ▶ | push @nodes, [$row, $col-1] unless $col == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 125 | ▶ | push @nodes, [$row, $col+1] unless $col == $self->w-1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 134 | return @nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | my @cletters = qw/a b c d e f g h j k l m n o p q r s t u v w x y z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub pretty_coordinates{ #convert 1-1 to b18, etc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pretty_coordinates: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($row,$col) = $node =~ /^(\d+)-(\d+)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $col = $cletters[$col]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $row = $self->h - $row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return "$col$row"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | ▶ | use Scalar::Util::Numeric qw(isint); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 14 | ▶ | sub node_is_valid{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node_is_valid: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 14 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 14 | my ($row,$col) = @$node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | #check bounds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 14 | ▶ | return 0 if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$row < 0 or $col < 0 or $row >= $self->h or $col >= $self->w
$row < 0 or $col < 0 or $row >= $self->h
$row < 0 or $col < 0
MC/DC100%4/4
$row < 0 or $col < 0 or $row >= $self->h or $col >= $self->w
$row < 0
$col < 0
$row >= $self->h
$col >= $self->w
Truth table100%5/5
A or B or C or D
A= $row < 0B= $col < 0C= $row >= $self->hD= $col >= $self->w
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | $row < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | or $col < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | or $row >= ($self->h) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | or $col >= ($self->w); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | #check integeritude.. for row & col. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 10 | ▶ | return 0 unless isint $row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 10 | ▶ | return 0 unless isint $col; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||