Course:CPSC312-2024/Conways Game of Life

From UBC Wiki

Author: Mehrsa, Yichen Lu

What is the problem?

The core problem we tackled is implementing Conway's Game of Life, a cellular automaton devised by mathematician John Conway. This zero-player game evolves from an initial state by following simple rules, leading to complex patterns over time. Our challenge was to accurately simulate these dynamics and explore the application of functional programming paradigms to manage state transitions efficiently and effectively.

The basic rule follows:

  1. Birth: A dead cell becomes alive (is "born") in the next generation if it has exactly three alive neighbors.
  2. Survival: An alive cell remains alive in the next generation if it has two or three alive neighbors. If it has fewer than two alive neighbors, it dies of underpopulation, and if it has more than three alive neighbors, it dies of overpopulation.
  3. Death:
    • Underpopulation: An alive cell with fewer than two alive neighbors dies in the next generation.
    • Overpopulation: An alive cell with more than three alive neighbors dies in the next generation.

What is the something extra?

  • Users are able to specify the initial state using files or seeds.
  • The game is able to generate the initial state using seeds.
  • Users are able to enter and use boards as large or as small as they want
  • Users are able to observe each step of evolution and track the overall changes by having each step compared

What did we learn from doing this?

  • we observed how useful functional programming is to manage each state and how easily we can deduce the next state and also how it can give the users freedom to use boards of different sizes and input whatever seed they want which demonstrates Haskell's flexibility
  • choosing Haskell to implement Game of Life allowed us to make a robust program with short and easy-to-read lines of code
  • one of the challenges we faced was choosing an easy way for the users to input their desired initial state: whether to input through the ghci, using a txt file, giving the desired position (x,y), etc.

Links to code etc.

Github