Conway's Life Fail...

Game Editor comments and discussion.

Conway's Life Fail...

Postby jimmynewguy » Sat Oct 15, 2011 10:01 pm

I wanted to see if I could get a *sorta* conway's game of life going on in the canvas, but I failed. Here's what my global code looked like.
Code: Select all
int array[360][240], timer;

int neighbors(int i, int j)
{
int count;
count += (!array[j-1][i]);
count += (!array[j+1][i]);
count += (!array[j-1][i+1]);
count += (!array[j+1][i+1]);
count += (!array[j-1][i-1]);
count += (!array[j+1][i-1]);
count += (!array[j][i-1]);
count += (!array[j][i+1]);
return count;
}

void createRand()
{
int i, j, life;
for(i=1; i<360; i++)
{
for(j=1; j<240; j++)
{
life = rand(25);
if(life > 0)
life = 1;

array[i][j]=life;
}
}
}

void display()
{
int i, j;
for(i=1; i<360; i++)
{
for(j=1; j<240; j++)
{
setpen(255, 255, 255, array[i][j], 1);
putpixel(i, j);
}
}
}

void simulate()
{
int i, j, count;
for(i=1; i<360; i++)
{
for(j=1; j<240; j++)
{
count = neighbors(i, j);
if(!array[i][j])
{
if(count == 2 || count == 3)
array[i][j] = 0;
else
array[i][j] = 1;
}
else
{
if(count == 3)
array[i][j] = 0;
}
}
}
display();
}
Pretty bad...

But the canvas just clears itself on the first "cycle" or whatever you want to call it.

For those who don't know the game (aka live under a rock :P)
http://www.math.com/students/wonders/life/life.html

Maybe someone sees where I went wrong? I feel like it's blatant. But oh well, just wanted to mess with it.
Attachments
Game of Life.zip
(3.8 KiB) Downloaded 82 times
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Conway's Life Fail...

Postby jimmynewguy » Sat Oct 15, 2011 11:28 pm

This one almost works, the rules seem to somehow be messed up.... But I followed them all! :(
Attachments
Game of Life.zip
(1.75 KiB) Downloaded 71 times
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest