| 1 | package Game::Life::Faster; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use List::Util qw{ max min }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.007_01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use constant ARRAY_REF => ref []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use constant DEFAULT_BREED => [ 3 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use constant DEFAULT_LIVE => [ 2, 3 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use constant DEFAULT_SIZE => 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use constant NEW_LINE_RE => qr< \n >smx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use constant NON_NEGATIVE_INTEGER_RE => qr< \A [0-9]+ \z >smx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use constant POSITIVE_INTEGER_RE => qr< \A [1-9][0-9]* \z >smx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use constant TOGGLE_STATE => do { bless \my $x, 'Toggle_State' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use constant TOGGLE_STATE_REF => ref TOGGLE_STATE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | my ( $class, $size, $breed, $live ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | my $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | my $ref = ref $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | if ( ARRAY_REF eq $ref ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | $self->{size_x} = $size->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $self->{size_y} = $size->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } elsif ( ! $ref ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | $self->{size_x} = $self->{size_y} = $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | croak "Argument may not be $size"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | $self->{size_x} ||= DEFAULT_SIZE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"size_x"} ||= 100
MC/DC100%1/1
$self->{"size_x"} ||= 100
$self->{"size_x"}
Truth table100%2/2
A
A= $self->{"size_x"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | $self->{size_y} ||= DEFAULT_SIZE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"size_y"} ||= 100
MC/DC100%1/1
$self->{"size_y"} ||= 100
$self->{"size_y"}
Truth table100%2/2
A
A= $self->{"size_y"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | $self->{size_x} =~ POSITIVE_INTEGER_RE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | and $self->{size_y} =~ POSITIVE_INTEGER_RE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"size_x"} =~ / \A [1-9][0-9]* \z /msx and $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
MC/DC0%0/2
$self->{"size_x"} =~ / \A [1-9][0-9]* \z /msx and $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
$self->{"size_x"} =~ / \A [1-9][0-9]* \z /msx
$self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
Truth table33%1/3
A and B
A= $self->{"size_x"} =~ / \A [1-9][0-9]* \z /msxB= $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | or croak 'Sizes must be positive integers'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | $self->{max_x} = $self->{size_x} - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | $self->{max_y} = $self->{size_y} - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | bless $self, ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | $self->set_rules( $breed, $live ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | $self->clear(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | delete $self->{grid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | delete $self->{changed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | $self->{living_x} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | $self->{living_y} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | $self->{change_count} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | sub get_active_grid_coord { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_active_grid_coord: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | my ( $min_x, $max_x, $min_y, $max_y ) = ( $self->{size_x}, 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | $self->{size_y}, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | foreach my $ix ( keys %{ $self->{changed} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 10 | ▶ | $min_x = $ix if $ix < $min_x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 10 | ▶ | $max_x = $ix if $ix > $max_x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 10 | foreach my $iy ( keys %{ $self->{changed}{$ix} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 40 | ▶ | $min_y = $iy if $iy < $min_y; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 40 | ▶ | $max_y = $iy if $iy > $max_y; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | $max_x < $min_x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | and croak 'No active cells'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | return [ $min_x, $max_x, $min_y, $max_y ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | sub get_breeding_rules { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_breeding_rules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | return $self->get_rule( 'breed' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | sub get_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | my ( $self, $coord ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_grid: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | $coord ||= $self->get_grid_coord(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$coord ||= $self->get_grid_coord
MC/DC0%0/2
$coord ||= $self->get_grid_coord
$coord
$self->get_grid_coord
Truth table33%1/3
A ||= B
A= $coordB= $self->get_grid_coord
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | $self->{grid} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | or return [ ( [ ( 0 ) x ( $coord->[3] - $coord->[2] + 1 ) ] ) x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ( $coord->[1] - $coord->[0] + 1 ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | my @rslt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | foreach my $x ( $coord->[0] .. $coord->[1] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 10 | ▶ | if ( $self->{grid}{$x} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 7 | push @rslt, []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 7 | foreach my $y ( $coord->[2] .. $coord->[3] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 70 | ▶ | push @{ $rslt[-1] }, $self->{grid}{$x}{$y} ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 70 | $self->{grid}{$x}{$y}[0] ? 1 : 0 : 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | push @rslt, [ ( 0 ) x ( $coord->[3] - $coord->[2] + 1 ) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | return \@rslt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | sub get_grid_coord { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 9 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_grid_coord: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 9 | return [ 0, $self->{max_x}, 0, $self->{max_y} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | sub get_living_rules { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_living_rules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | return $self->get_rule( 'live' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub get_text_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 10 | ▶ | my ( $self, $living, $dead, $coord ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_text_grid: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 10 | ▶ | $living ||= 'X'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$living ||= "X"
MC/DC0%0/1
$living ||= "X"
$living
Truth table50%1/2
A
A= $living
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 10 | ▶ | $dead ||= '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$dead ||= "."
MC/DC0%0/1
$dead ||= "."
$dead
Truth table50%1/2
A
A= $dead
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 10 | ▶ | $coord ||= $self->get_grid_coord(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$coord ||= $self->get_grid_coord
MC/DC0%0/2
$coord ||= $self->get_grid_coord
$coord
$self->get_grid_coord
Truth table66%2/3
A ||= B
A= $coordB= $self->get_grid_coord
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 10 | my @rslt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 10 | ▶ | if ( $self->{grid} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 7 | foreach my $x ( $coord->[0] .. $coord->[1] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 58 | ▶ | if ( $self->{grid}{$x} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | push @rslt, join '', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 37 | ▶ | ( $self->{grid}{$x}{$_} && $self->{grid}{$x}{$_}[0]) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"grid"}{$x}{$_} and $self->{"grid"}{$x}{$_}[0]
MC/DC100%2/2
$self->{"grid"}{$x}{$_} and $self->{"grid"}{$x}{$_}[0]
$self->{"grid"}{$x}{$_}
$self->{"grid"}{$x}{$_}[0]
Truth table100%3/3
A and B
A= $self->{"grid"}{$x}{$_}B= $self->{"grid"}{$x}{$_}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | $living : $dead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } $coord->[2] .. $coord->[3]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 21 | push @rslt, $dead x ( $coord->[3] - $coord->[2] + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | @rslt = ( $dead x ( $coord->[3] - $coord->[2] + 1 ) ) x ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | $coord->[1] - $coord->[0] + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | ▶ | return wantarray ? @rslt : join '', map { "$_\n" } @rslt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | sub get_active_text_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | my ( $self, $living, $dead ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_active_text_grid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return $self->get_text_grid( $living, $dead, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | $self->get_active_grid_coord() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | sub get_used_text_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | my ( $self, $living, $dead ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_used_text_grid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | return $self->get_text_grid( $living, $dead, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | $self->get_used_grid_coord() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | sub get_used_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_used_grid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return $self->get_grid( $self->get_used_grid_coord() ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | sub get_used_grid_coord { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_used_grid_coord: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | my $min_x = $self->{size_x}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | for ( $min_x = 0; $min_x < $self->{size_x}; $min_x++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | $self->{living_x}[$min_x] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | my ( $max_x, $min_y, $max_y ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | for ( $max_x = $self->{size_x}; $max_x >= $min_x; ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | ▶ | $self->{living_x}[--$max_x] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | and last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | for ( $min_y = 0; $min_y < $self->{size_y}; $min_y++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | ▶ | $self->{living_y}[$min_y] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | and last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | ▶ | for ( $max_y = $self->{size_y}; $max_y >= $min_y; ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 12 | ▶ | $self->{living_y}[--$max_y] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | and last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | return [ $min_x, $max_x, $min_y, $max_y ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | croak 'No occupied cells'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | sub place_points { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | my ( $self, $x, $y, $array ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place_points: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | my $ix = $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | foreach my $row ( @{ $array } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | my $iy = $y; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | foreach my $state ( @{ $row } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | $self->set_point_state( $ix, $iy, $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | $iy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | $ix++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | sub place_text_points { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | my ( $self, $x, $y, $living, @array ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place_text_points: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | my $ix = $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | 1 == @array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
1 == @array and $array[0] =~ / \n /msx
MC/DC50%1/2
1 == @array and $array[0] =~ / \n /msx
1 == @array
$array[0] =~ / \n /msx
Truth table66%2/3
A and B
A= 1 == @arrayB= $array[0] =~ / \n /msx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | and $array[0] =~ NEW_LINE_RE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | and @array = split qr< @{[ NEW_LINE_RE ]} >smx, $array[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | foreach my $line ( @array ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 7 | my $iy = $y; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 7 | foreach my $state ( map { $living eq $_ } split qr<>, $line ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 17 | $self->set_point_state( $ix, $iy, $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 17 | $iy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 7 | $ix++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | sub process { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | ▶ | my ( $self, $steps ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | $steps ||= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$steps ||= 1
MC/DC100%1/1
$steps ||= 1
$steps
Truth table100%2/2
A
A= $steps
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | foreach ( 1 .. $steps ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 13 | my $changed = delete $self->{changed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 13 | $self->{change_count} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 13 | foreach my $x ( keys %{ $changed } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 60 | foreach my $y ( keys %{ $changed->{$x} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 253 | my $cell = $self->{grid}{$x}{$y}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | no warnings qw{ uninitialized }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 253 | ▶ | if ( $cell->[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 66 | ▶ | $self->{live}[ $changed->{$x}{$y} ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | or $self->unset_point( $x, $y ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 187 | ▶ | $self->{breed}[ $changed->{$x}{$y} ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | and $self->set_point( $x, $y ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | $self->{change_count} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 13 | ▶ | or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | return $self->{change_count}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | sub set_point { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 26 | ▶ | my ( $self, $x, $y ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 26 | return $self->set_point_state( $x, $y, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | sub set_point_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 74 | ▶ | my ( $self, $x, $y, $state ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_point_state: called CC=18 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 74 | ▶ | defined $x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $x and defined $y and $x =~ / \A [0-9]+ \z /msx and $y =~ / \A [0-9]+ \z /msx
defined $x and defined $y and $x =~ / \A [0-9]+ \z /msx
defined $x and defined $y
MC/DC0%0/4
defined $x and defined $y and $x =~ / \A [0-9]+ \z /msx and $y =~ / \A [0-9]+ \z /msx
defined $x
defined $y
$x =~ / \A [0-9]+ \z /msx
$y =~ / \A [0-9]+ \z /msx
Truth table20%1/5
A and B and C and D
A= defined $xB= defined $yC= $x =~ / \A [0-9]+ \z /msxD= $y =~ / \A [0-9]+ \z /msx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | and defined $y | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | and $x =~ NON_NEGATIVE_INTEGER_RE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | and $y =~ NON_NEGATIVE_INTEGER_RE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | or croak 'Coordinates must be non-negative integers'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 74 | ▶ | defined $state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | or return $state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 74 | ▶ | if ( $x >= 0 && $x < $self->{size_x} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%3/9
$x >= 0 and $x < $self->{"size_x"} and $y >= 0 and $y < $self->{"size_y"}
$x >= 0 and $x < $self->{"size_x"} and $y >= 0
$x >= 0 and $x < $self->{"size_x"}
MC/DC0%0/4
$x >= 0 and $x < $self->{"size_x"} and $y >= 0 and $y < $self->{"size_y"}
$x >= 0
$x < $self->{"size_x"}
$y >= 0
$y < $self->{"size_y"}
Truth table20%1/5
A and B and C and D
A= $x >= 0B= $x < $self->{"size_x"}C= $y >= 0D= $y < $self->{"size_y"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | $y >= 0 && $y < $self->{size_y} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # We're on-grid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # This autovivifies, but we're going to assign it anyway, so ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 74 | ▶ | my $prev_state = $self->{grid}{$x}{$y}[0] || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'grid'}{$x}{$y}[0] || 0
MC/DC100%1/1
$self->{'grid'}{$x}{$y}[0] || 0
$self->{'grid'}{$x}{$y}[0]
Truth table100%2/2
A
A= $self->{'grid'}{$x}{$y}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 74 | ▶ | $state = TOGGLE_STATE_REF eq ref $state ? 1 - $prev_state : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | $state ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 74 | $self->{grid}{$x}{$y}[0] = $state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 74 | ▶ | $self->{grid}{$x}{$y}[1] ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"grid"}{$x}{$y}[1] ||= 0
MC/DC100%1/1
$self->{"grid"}{$x}{$y}[1] ||= 0
$self->{"grid"}{$x}{$y}[1]
Truth table100%2/2
A
A= $self->{"grid"}{$x}{$y}[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 74 | ▶ | my $delta = $state - $prev_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | or return $state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 68 | $self->{living_x}[$x] += $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 68 | $self->{living_y}[$y] += $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 68 | $self->{change_count}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 68 | foreach my $ix ( max( 0, $x - 1 ) .. min( $self->{max_x}, $x + 1 ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 197 | foreach my $iy ( max( 0, $y - 1 ) .. min( $self->{max_y}, $y + 1 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $self->{changed}{$ix}{$iy} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 563 | $self->{grid}{$ix}{$iy}[1] += $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # A cell is not its own neighbor, but the above nested loops | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # assumed that it was. We fix that here, rather than skip it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # inside the loops. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | $self->{changed}{$x}{$y} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 68 | $self->{grid}{$x}{$y}[1] -= $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } elsif ( $state ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | croak 'Attempt to place living cell outside grid'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 68 | return $state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | my %dflt = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | breed => DEFAULT_BREED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | live => DEFAULT_LIVE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | sub get_rule { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | ▶ | my ( $self, $kind ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_rule: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | ▶ | $dflt{$kind} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | or croak "'$kind' is not a valid rule kind"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | return( grep { $self->{$kind}[$_] } 0 .. $#{ $self->{$kind} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | sub set_rule { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 6 | ▶ | my ( $self, $kind, $rule ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_rule: called CC=6 SCAR=19.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 6 | ▶ | $dflt{$kind} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | or croak "'$kind' is not a valid rule name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | ▶ | $rule ||= $dflt{$kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rule ||= $dflt{$kind}
MC/DC0%0/2
$rule ||= $dflt{$kind}
$rule
$dflt{$kind}
Truth table33%1/3
A ||= B
A= $ruleB= $dflt{$kind}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 6 | ▶ | ARRAY_REF eq ref $rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | or croak "\u$kind rule must be an array reference"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 6 | $self->{$kind} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 6 | foreach ( @{ $rule } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 9 | ▶ | $_ =~ NON_NEGATIVE_INTEGER_RE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | or croak "\u$kind rule must be a reference to an array of non-negative integers"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 9 | $self->{$kind}[$_] = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | sub set_rules { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | ▶ | my ( $self, $breed, $live ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_rules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 3 | $self->set_rule( breed => $breed ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | $self->set_rule( live => $live ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | sub toggle_point { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | ▶ | my ( $self, $x, $y ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toggle_point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | return $self->set_point_state( $x, $y, TOGGLE_STATE ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | sub unset_point { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 26 | ▶ | my ( $self, $x, $y ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unset_point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 26 | return $self->set_point_state( $x, $y, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||