Conway's Game of Life
Projects | Links: Live | Source
![Conway's Game of Life](/assets/img/projects/conways.jpg)
An implementation of Conway’s Game of Life using functional programming principles with Scala 3 and Scala.js
This is an implementation of Conway’s Game of Life in Scala 3. It was primarily developed as a project to become acquainted with Scala 3, aiming to swiftly achieve a satisfying product ready for release. The finished product can be accessed here.
The Game of Life is a classic cellular automaton devised by John Conway. It consists of a grid of cells, each of which can be alive or dead. The state of each cell evolves over time based on simple rules:
- Any live cell with two or three live neighbors survives.
- Any dead cell with exactly three live neighbors becomes alive.
- All other live cells die, and all other dead cells remain dead.
Despite its simple rules, the game can exhibit complex and fascinating patterns and behaviors such as a fully functioning computer or even the Game of Life itself.
The project draws significant inspiration from Ivan Yurchenko’s implementation of the Game of Life in Scala 2, adopting a similar architecture and logic. As Ivan’s implementation is relatively dated, some libraries needed replacement. You can find Ivan’s implementation here.
The project was developed using Scala.js, a prominent web development library for Scala. Airstream was used for state propagation, while Vite.js served as the local development server. The visual design was crafted using Tailwind CSS.
On the live application, the project is described as follows:
You can find more information about the game in Wikipedia.
The world of this implementation is toroidal - top and bottom, left and right edges are connected.
During the simulation, the history of the universe evolution is recorded, and you can scroll to any state when the simulation is stopped. Also when the simulation is stopped, you can change the state by adding or removing living cells.
The cell plane can be cleared or randomly seeded and you can create a new universe (with different size) by the buttons at the top (huge universes can slow down the simulation). You can also choose some interesting predefined universes.
Any manual changes to the state of the universe (making a cell dead or alive, clearing, randomly seeding, creating a new universe) causes its history to be cleared.
You can control the speed of the simulation and zoom the cell plane by moving the sliders at the top.
Unfortunately, the history is unbounded and may consume lots of memory with time.
Try it out and have some fun with the Game of Life.
For more detailed information about the project, please refer to the README file in the linked source repository.