Note: This is a group project for CSE 230, principles of functional programming language. I am responsible for coding the GUI and handling the interaction between the front-end and back-end using the brick library based on the Haskell programming language. Runnable project can be seen at: t3chou/haskell-game-of-life (github.com)
In this project, we
- Designed the core logic in pure functional language
- Wrote the GUI in pure functional language
- Designed a user-friendly interface
- Did property tests to catch logical errors
Overview
This project implements Conway’s Game of Life by using Haskell, which is great for modeling complex mathematical concepts with the design of Haskell. The Game of Life, a zero-player game, evolves from an initial state, showing emergent behavior based on some rules and status (Birth, Survival, and Death). Haskell’s strong typing and pure functionality align perfectly with this game.
Game Description
The Game of Life occurs on an infinite grid of cells. The status of each cell will be changed based on neighboring cells following those rules:
- Birth: A dead cell with three live neighbors becomes alive.
- Survival: A live cell with two or three live neighbors stays alive.
- Death:
- Overpopulation: A live cell with over three live neighbors dies.
- Loneliness: A live cell with under two live neighbors dies.
implementation
Haskell’s fits for expressing the game’s rules. Key aspects of our implementation include:
- Functional Grid Representation: Using list comprehensions and higher-order functions for the grid.
- State Transformation: Pure functions for state transitions between generations.
- Interaction Functionality: Implementing pause/continue in the game, boosting the interaction between users and the game with the help of the brick library.
- Unit Testing: Using QuickCheck to test each functionality, and game logic.
- Managing Dependencies: Making use of tools like Cabal or Stack to manage dependencies.
Project Goals
- Mathematical Fidelity: Ensure full implementation of the game following Conway’s rules.
- User Interactions: Interacting with a user-friendly interface by key presses for pausing/continuing the game or quitting using the brick library.
- Using existing libraries of the hackage ecosystem: Utilizing existing libraries like containers and vector.
This project aims to create a Conway’s Game of Life simulation in Haskell, as well as representing a string connection between a mathematical model and functional programming.
Source acknowledgment
- As required by the course website, we are using the Brick library to implement the GUI interface. We did look at the official guidelines from https://github.com/jtdaugherty/brick to implement any components relevant to GUI because the Brick library has never been taught in class.
- We use Haskell’s Hoodle to explore and employ functions for implementing our project because not all Haskell components were covered during class.
- We use QuickCheck library to accomplish the unit testing requirments as required by the course website.
Code
The following shows codes for the front-end interface based on the brick library. In more detail, the GUI contains clickable buttons, a user-friendly setting interface, and a playable game with everything being programmed using state in Haskell:
1 | clickable |