Ask coding questions

← Back to all posts
John Conway's Game of Life
EmmaGao8 (33)

I attempted to make john conway's game of life. The game is held on a grid. One the grid are cells. This game is a zero player game, meaning it plays itself. If you don't know how to play, rules are below:
1. If a cell is alive but has more than 3 living neighbors, it dies of overcrowding.
2. If a cell is alive but has less than 2 living neighbors, it dies of loneliness.
3. If a cell is dead but has exactly 3 living neighbors, it springs to life.

my code is here:

The thing that I struggle on is making a dict of the numbers of living neighbors, because all the dead cells considered same and so goes with the alive cells.

Thank you for your time and consideration.
Wish you luck!

SixBeeps (5234)

Usually when I go and implement CGoL (yes, I have done so multiple times), I'll use 2D arrays to hold the current board and the next board. Whenever the next generation is calculated, it clears out the next board and reads from the current board. For every current cell, it checks its living conditions and writes a dead or alive cell to the next board accordingly. Then, the current board is overwritten by the next board.

I'm not entirely sure what's happening in your code. It appears that you are using 2D arrays, but I don't see your dictionary implementation anywhere.