Game of Life in Elixir

For your amusement: GitHub - davearonson/elixir-life: Conway's game of Life, in Elixir
Feedback welcome, since I’m still sort of an Elixir n00bie.

5 Likes

Heh, I like; got a glider after a few tries and it was unable to reach static/dynamic stability and is still going with the glider just flying around. ^.^

1 Like

Ah, yeah, it doesn’t detect stability forms with a longer cycle than 2. So, it gets the various totally static forms, and stoplights, but not gliders, pulsars, and so on. It would be easy enough to add pulsar detection, but that raises the question of how far back one should check – I don’t want it to bog down after a few hundred generations, due to checking against all prior gens…

1 Like

There are styles that can cause loops that are thousands long, so it seems an intractable problem to me. ^.^

Erlang has bitstrings, have you thought of encoding the information as a 64x64 bit hash or so (or many 8*8’s if you want to pack it into an integer for fast bit work)? I think that is a pattern that I’ve seen Life games do before, lets you have pretty arbitrary sized areas and it is fast to process, especially as you can take patterns and match them out for quick calculations. :slight_smile:

I like the idea detecting the static/dynamic stability. I build my version attempt to make the game as an OTP and make every cell as a process. My 2 cents for your code is you can build the neighbor vector using list comprehension like this.

1 Like

Oh wow, yes, I had totally forgotten about comprehensions! In a previous version, I had initialized the @neighbor_vectors list programmatically, but more awkwardly, less concisely. The change is now in the Github repo.

1 Like

Hmmm, yes, if I “binary-pack” it like that, and put the past generations in a MapSet, comparing to the past could be reasonably fast. Or better yet, just a Map, and the value would be the generation number, so we could still tell how long the cycle time is. I’ll try to remember to do that…

1 Like

I’ve only glanced over your code, not studied it, but I do see a number of similarities to my exploration of the Game of Life. If you’re curious you can find it here: https://github.com/gvaughn/elixir_kata/tree/master/conway

1 Like

Cool, I’ll try to take some time to grok yours and compare the algorithms.

1 Like