Reputation: 39
Alright so I writing Conways Game of Life in C++, and so far I have only created the rule that allows users to create cells if it has 3 neighbors.
Here is the current code: http://tinypaste.com/f59b4463
When I launched the program I entered in the coordinates so that I would have the gameboard depicted in the photo below, and the output wasn't what I expected, it should have made it so that the cell 2,1 would be alive, but in the output it remained dead. I am not sure why it is not working. Any help?
Input & Output: https://i.sstatic.net/lWGc3.png
Upvotes: 1
Views: 118
Reputation: 11022
Alright. It's an algorithmic issue. When you call calculate, it creates extra cells because it's not exactly one generation. It's a mix of two and three - it acts on cells you just created. Get what I'm saying? I explained this on GMail.
Upvotes: 1
Reputation: 11022
Several things to address, and while this is not an answer, it's too big for a comment. Please fix these then I will get back to you...
In gameboard()
please arrange the code so that it consists of two for
loops instead of all the cout
s. Example:
int i, j;
for (i = j = 0; i < 10; i++) {
for (; j < 10; j++) {
cout << world[i][j];
}
}
it's much more concise.
Second, in cells()
, in the second for
loop, you can use another nested for
loop.
Third, I would avoid naming normal variables in ALL CAPS since that is generally reserved for preprocessor #define
s.
K, enjoy cleaning up :)
Upvotes: 2