What's wrong with my implementation of the game "life"?

  • 0
    I decided to write a game "life" in js. When I draw a glider (the first thing that comes to my mind), and then I start the game, not exactly what I want happens. Draw - left mouse button, launch - right. Drawn:
    JavaScript Holden Vaughn, May 22, 2019

  • 1 Answers
  • 0
    There is a cant:

    if(nbs == birth) preMatrix[nowI][nowJ] = 1;
    if (nbs < save[0] || nbs > save[1]) preMatrix[nowI][nowJ] = 0;

    If nbs is 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 matrix to preMatrix , you are not doing anything. Therefore, cells with two neighbors turn out to be dead in the next generation.

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!