How to write fast Game of Life?

I like writing the Game of Life as a helloworld program when learning graphics libraries because the naive algorithm is very easy to implement. It is however pretty slow. I want to try writing something more efficient than doing a whole pass through the board each frame, so I wonder which "fast" algorithm is more or less easy to understand and implement?

6 points · 3 comments · view on lemmy.world

3 Comments

CameronDev@programming.dev · 6 pts · 223d (2 replies)

Rather than parsing the whole board, keep a hashset or list of all the cells that are live. Then apply the rules to all of those cells and their neighbours. Should avoid needlessly checking dead cells.

gera@feddit.nu · 3 pts · 223d (1 reply)

thanks for the idea, that was easy to implement! (odin, sdl)

look at it go:

CameronDev@programming.dev · 1 pts · 223d

Awesome. You may want to check out adventofcode.com, pt1 is usually brute forcible, pt2 requires optimisation.

!advent_of_code@programming.dev