Course:CPSC312-2021/Snake

From UBC Wiki

Snake

Authors: Andy, Madeline, and Matthew

What is the problem?

State the general problem. If applicable, tell us what information you will use, e.g., a link to some web site that provides the information you used. What will you do?

We will implement a Haskell version of the game Snake. This game is played by directing a continuously moving line around a square board via user input. When the snake crosses paths with a food item (stationary and randomly placed around the board), it increases in length. When the snake runs into the edge of the board or into itself, the game is over. Points are calculated based on the length of the snake at the end of the game.

What is the something extra?

What is the in-depth aspect you will do? If the problem is related to some other group's project, tell us how they fit together. If in doubt, include the information.

The game will include a continuous time aspect, as the snake must be controlled in real time by the user, and be displayed in the console. The game will also save game scores by writing to disk and records a new high score once it surpasses the previous high score by reading from the disk.

What did we learn from doing this?

(This should be written after you have done the work.) What is the bottom-line? Is functional programming suitable for (part-of) the task? Make sure you include the evidence for your claims.

We gained a better understanding of monads, I/O and asynchrony after doing this project. The bottom line is a program that can simulate the classic snake game with a choice for the player to start the game, and restart or exit the game when the player's snake dies. Functional programming was suitable for most of the tasks as it supported the modularity component of our implementation. The only part of the task which we thought functional programming was less convenient than other programming paradigms was the fact that to maintain a continuous time aspect, we had to heavily rely on recursion in our implementation.

After typing "go" in console, a screen with instructions on how to play will appear.
When the player's snake dies, the player is given the option to restart or exit the game.

Links to code etc

https://github.com/mhinzz/Snake