• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What the heck is wrong with my Game of Life implementation?

Train

Lifer
So a few years back I implemented Conway's Game of Life, in JavaScript. To follow along, you can view the jsFiddle here: jsfiddle_net/1v18fog6/ (EDIT: apparently JSFiddle links are blocked?) PM me if you want the GitHub repo

Lately I've been playing with /improving it, mostly as a demonstration of JS/jQuery (Yes, I know JQuery is probably a slow solution for this problem, but I don't really care about speed)

After visiting the wikipedia page for the game (http://en.wikipedia.org/wiki/Conway's_Game_of_Life) I tried to re-create some of the interesting structures they have there, such as oscillators, gliders, and guns.

I cleared the board and re-created them by manually setting a few up, but for some reason I get different results. I have checked my code against the rules stated on the Wikipedia page, and don't seem to have missed anything. Maybe I just need a fresh set of eyes.

the wiki states
1. Any live cell with less than two live neighbours dies, as if caused by under-population.
2. Any live cell with two or three live neighbours lives on to the next generation.
3. Any live cell with more than three live neighbours dies, as if by overcrowding.
4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

My rules are in the DetermineNextCellState function.
 
Last edited:
I'm too lazy to ask for and read your code, but are you using separate "old" and "new" board arrays? And clearing the new board? If you update in place using a single board I think you'll mess it up.
 
I'm too lazy to ask for and read your code, but are you using separate "old" and "new" board arrays? And clearing the new board? If you update in place using a single board I think you'll mess it up.

Yeah, each cell has a "NextState" property. It then gets flipped to its next state after a whole generation is processed.
 
Shit, I figured it out.

was doing $(this) inside a function call when I should have been using the passed in var, so it should have been $(cell)

I'm actually surprised it worked at all. But I guess that's javaScript for you.
 
Last edited:
Back
Top