Reputation: 39
Alright, so I am coding the game of life, I am almost done, but I am having troubles with the algorithm used to make cells alive and dead, it can be found in the function calculate.
Here is the input I am getting: http://ideone.com/ywEtC
And here is a screenie (found in comments) from a site with the same pattern I used, and it shows the intended output.
I have tried making it so that it doesn't count newly created cells as neighbors, but that turned out even worse. The source for that for reference can be found here: https://github.com/Legitimate/Conway-s-Game-of-Life/blob/master/gameoflife4.cpp
Upvotes: 1
Views: 781
Reputation: 31609
You problem is that you need to double buffer, because after you changed a value, other values won't know its original value.
e.g.
---
+++
---
(0, 1): it has 1 neighbor and must die:
---
-++
---
(1, 1): it has 1 neighbor and must die:
---
--+
---
(2, 1): it has 0 neighbors and must die:
---
---
---
while the excpected output will be:
-+-
-+-
-+-
Also, the use of char array is highly inefficient, you need to warp bit_vector
to make it two dimensional, it will also make double buffering easier.
Upvotes: 6