writing a cellular "game of life" program having a little trouble

Nov 18, 2008 at 3:45am
Thanks for the help
Last edited on Nov 20, 2008 at 12:45am
Nov 18, 2008 at 4:19am
What exactly is it supposed to be doing? I don't really understand what you are trying to get it to do.
Nov 18, 2008 at 4:53am
ok, it looks at the current generation, if the relative cells to it (that cell, one up, one down, one left, one right) if 3 or 4 of them are a 1 it stays or is made a 1 if <3 or >5 are a 1 it becomes a 0, it does this for 5 generations
Nov 18, 2008 at 5:03am
Line 41/43 don't seem to make sense together...I think you meant to reverse the < > on line 41...and you might as well just make line 43 an else statement.

Other then that...your display code is outside of the 5 loops, so you will never see the results of those, you need to move it inside of it.
Nov 18, 2008 at 5:26am
your right about line 41/43, but I dont understand what you mean about the display code, it seems to be in the loop to me, can you show me what you mean
Nov 18, 2008 at 5:42am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
int main ()
{
const int numrows = 10;
const int numcols = 10;
ifstream input;
ofstream results;
input.open("/Users/putyoursoxon/Documents/input.txt");//input file
results.open("/Users/putyoursoxon/Documents/results.txt");//application results go here
int i, j, g, h, count, loopa;
int arraypast[numrows][numcols];
int arrayfuture[numrows][numcols];

//BEGIN DISPLAY CODE
for (i=0; i < numrows; i ++)
{
for (j=0; j < numcols; j ++)
	input >> arraypast[i][j];
}

	for (i=0; i < numrows; i ++)
	{
		results << endl;
		for (j=0; j < numcols; j ++)
			results << arraypast[i][j];
	}
	results << endl;

//END DISPLAY CODE
	

//BEGIN LOOP CODE
for(loopa =1; loopa <= 5; loopa ++)
	{
	for (i=0; i < numrows; i++)
	 {
		 for (j=0; j < numcols; j++)
		 {
		 count = 0;
		 compare (arraypast, count, i, j);
		 if (count <=3 && count >=4)
			 arrayfuture[i][j] =1;
		 if (count > 3 || count == 5)
			 arrayfuture[i][j] =0;
		 }
	 }
		results << "Offspring #" << loopa << endl;
		for (g=0; i < numrows; i ++)
		{
			results << endl;
			for (h=0; j < numcols; j ++)
				results << arrayfuture[g][h];
		}
		results << endl;
		arraypast == arrayfuture;
		
	}
//END LOOP CODE
	return 0;
}
Nov 18, 2008 at 12:13pm
i cant see how that would work, the display code for the origin is outside the loop yes, but then the display code for the future array is inside, it is printed (not working) then arrayfuture is == arraypast and the loop is started again, so
Nov 18, 2008 at 4:00pm
I guess what I am trying to say is that the arrayfuture has to be inside the for loop since it changes every pass, it's printing offspring #1 etc. So the loop is working, but why am I getting no output at all for the array
Nov 18, 2008 at 6:13pm
Ah...Yeah I just noticed that ^^; the problem is:

1
2
3
4
5
6
for (g=0; i < numrows; i ++)
		{
			results << endl;
			for (h=0; j < numcols; j ++)
				results << arrayfuture[g][h];
		}


You forgot to change i/j to g/h.
Topic archived. No new replies allowed.