Conway's Game of Life

Conway's Game of Life

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 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 on Wikipedia.

The world in this implementation is toroidal, meaning the top and bottom, as well as the left and right edges, are connected.

During the simulation, the history of the universe’s evolution is recorded, and you can scroll to any previous state when the simulation is paused. Additionally, while the simulation is paused, you can modify 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 a different size) using the buttons at the top (note that large universes may slow down the simulation). You can also select from several interesting predefined universes.

Any manual changes to the state of the universe (e.g., making a cell dead or alive, clearing the plane, randomly seeding, or creating a new universe) will cause its history to be cleared.

You can control the simulation speed and zoom the cell plane by adjusting the sliders at the top.

However, the history is unbounded and may consume a large amount of memory over 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 referred GitHub repository.