Course:CPSC312-2018-Conways-Game-Of-Life

From UBC Wiki

CPSC 312 Conway's Game of Life Simulation

Authors: Susie Chen, James Luo, Tom Lee

What is the problem?

Our goal is to simulate Conway's Game of Life. Conway's Game of Life is a zero-player deterministic game based on its initial state. The Life consists of NxN grid where each cell is either "populated" or "unpopulated". Each cell can change its state with each tick of the program following a set of rules:

  1. Any live cell with fewer than two live neighbours dies, as if by underpopulation.
  2. Any live cell with two or three live neighbours lives on to the next generation.
  3. Any live cell with more than three live neighbours dies, as if by overpopulation.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

End state of the game will either be:

  1. The cells have reached to edge of the screen where they will either all become stable with no more mutation or become extinct.
  2. There is no more cell mutation in the current board.

Source: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

What is the something extra?

We will be creating a UI which will display the game state and the cell evolutions. We have several options for user to start the simulation. User can either define location of populated cells on the terminal, or choose from a selection of generated boards.

For each iteration of the game, our program will filter through the current list of populate cells and output a list of survivors who met the surviving requirements, as well as generating a list of new populated cells. The concatentation of the survivors and the new generation list will be displayed on the terminal via IO function, and will be passed on as a new state for the next iteration.

Our program challenges the user to come up with a unique design patterns of cells to form some sort of moving image, or simulate the growth of a bacteria colony given certain location of the cells. User can also manipulate the growth rate of cells by strategically placing populated cells at key locations.

What did we learn from doing this?

Functional programming was a great choice for grid-based games like Conway’s Game of Life. Given Haskell’s programming features, they allowed us to code more concisely, allowing for short and easily understandable code. We were able to reduce the needed computations by just checking the alive cells rather than checking the entire board to see if the cells are alive or not.

We did run into a problem with trying to use a third-party library for a GUI especially due to lack of documentation. It was at times frustrating to see that there are no straightforward examples online for doing certain things such as regex. However, thanks to Haskell’s IO implementation, we were able to easily print the board in an optimal time. Additionally, IO made printing the board state at current generation simple. Although we did not get through the wish-list of things, we are very happy with the simplicity of Haskell code. 

Links to code etc

Github