What's wrong with my implementation of the game "life"?
1 AnswersThere is a cant:
if(nbs == birth) preMatrix[nowI][nowJ] = 1;
if (nbs < save || nbs > save) preMatrix[nowI][nowJ] = 0;
nbsis two - what then? Nothing. It seems to be correct, if there are two living neighbors, the cell should not change its state. However, setting the initial configuration, you are editing the
matrix, and in the
preMatrix, as there were zeros everywhere, they remain. And instead of copying the unit from
preMatrix, you are not doing anything. Therefore, cells with two neighbors turn out to be dead in the next generation.Anonymous
Your AnswerTo place the code, please use CodePen or similar tool. Thanks you!