Thank you for you input, I hope this version is more readable, with improved spacing. I think I've tracked down the problem: Inexplicably for me, the array @wholepattern gets changed, albeit it shouldn't in the following code. In the line
#@wholepattern = @wholepattern2;
It would usually copy the edited @wholepattern2 array to @wholepattern, but I've specifically canceled it out. If I'm running 2 iterations, why does @wholepattern still change? What am I missing here?!
#5. attempt Game of Life 79x39
use strict;
my @wholepattern = (
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','0','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','0','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','0','0','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','0','0','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','0','0','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','
+.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.
+','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'
+,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
+'.','.','.','.','.','.','.','.','.']
);
#new wholepattern2
my @neighbours2;
my @wholepattern2 = @wholepattern;
print "iterations: ";
my $z = <stdin>;
$z--;
my $t = 0;
my $row = ();
my $one = ();
my @neighbours = ();
print "t:$t";
print "\n";
$t++;
my $i=0;
foreach $row (@wholepattern) {
my $j=0;
foreach $one (@$row) {
if ($wholepattern[$i][$j] eq '0') {
print "*";
} else {
print ".";
}
$j++;
if ($j == 78) {
print "\n";
}
}
$i++;
}
print "\n";
select(undef, undef, undef, 1);
while ($t <= $z) {
my $i=0;
foreach $row (@wholepattern) {
my $j=0;
foreach $one (@$row) {
my $a1 = $i - 1;
my $a2 = $i;
my $a3 = $i + 1;
my $b1 = $j - 1;
my $b2 = $j;
my $b3 = $j + 1;
if ($a1 == -1)
{
my $a1 = 78;
}
if ($a3 == 79)
{
my $a3 = 0;
}
if ($b1 == -1)
{
my $b1 = 78;
}
if ($b3 == 79)
{
my $b3 = 0;
}
if ($wholepattern[$a1][$b1] eq '0')
{
push (@neighbours, '0');
}
if ($wholepattern[$a1][$b2] eq '0')
{
push (@neighbours, '0');
}
if ($wholepattern[$a1][$b3] eq '0') #
{
push (@neighbours, '0');
}
if ($wholepattern[$a2][$b1] eq '0')
{
push (@neighbours, '0');
}
#if ($wholepattern[$a2][$b2] eq '0')
# {
# push (@neighbours, '0');
# }
if ($wholepattern[$a2][$b3] eq '0') #
{
push (@neighbours, '0');
}
if ($wholepattern[$a3][$b1] eq '0') #
{
push (@neighbours, '0');
}
if ($wholepattern[$a3][$b2] eq '0') #
{
push (@neighbours, '0');
}
if ($wholepattern[$a3][$b3] eq '0') #
{
push (@neighbours, '0');
}
my $neighbours = @neighbours;
if ($neighbours < 2) {
$wholepattern2[$a2][$b2] = 'A';
}
if ($neighbours == 2) {
$wholepattern2[$a2][$b2] = '2';
}
if ($neighbours == 3) {
$wholepattern2[$a2][$b2] = '3';
}
if ($neighbours > 3) {
$wholepattern2[$a2][$b2] = 'B';
}
@neighbours = ();
$neighbours = ();
$j++;
}
$i++;
}
#displaying
print "t:$t";
print "\n";
my $k=0;
foreach $row (@wholepattern2) {
my $l=0;
foreach $one (@$row){
if ($wholepattern2[$k][$l] ne ' ') {
print $wholepattern2[$k][$l];
}
else {
print ".";
}
$l++;
if ($l == 78) {
print "\n";
}
}
$k++;
}
print "\n";
$t++;
select(undef, undef, undef, 0.2);
#@wholepattern = @wholepattern2;
}
print $wholepattern[2][2];