Course:CPSC312/2024W/Project Snake

From UBC Wiki

Authors:

 Derek Huang, Quinn Tao, Chendong Luo

What is the problem?

The Snake game is a classic arcade game that has been popular since the late 1970s. https://en.wikipedia.org/wiki/Snake_(video_game_genre)

The main goal of this project is to develop a Haskell version of the Snake game that runs on the PC.

The primary goal for players is to control the snake using the arrow keys, avoiding the snake hitting the borders and themselves while finding food randomly generated in the game field to increase their snakes in length, avoid starvation, and gain scores. At the same time, the players should watch out for the AI snakes hunting and scrambling for the limited resourse for living.

What is the something extra?

AI Snake: To increase the difficulty and make the game more engaging, we added an AI snake that the snake will autonomously find the path navigating towards to food or hunting for players in the game field.

Diet System: If the snake fails to consume food within a specified timeframe, it will gradually shorten.

Score Board: The player's score will be shown in the score board.

What did we learn from doing this?

Haskell has a very relatively small community and limited support when compared to mainstream game development languages like C++ and C#. We spent a lot of time searching for usable UI libraries and making them work locally. At first, we thought "Brick" would be the best one to support our implementation, but it has a very steep learning curve and we failed to fix the compiling issues and cross-platform compatibility. Finally, we instead decided to use "Gloss" which seemed easier to use and had no compiling and runtime issues on our locals. However, at the time when we tried to add sound effects to our game, we found that "Gloss" didn't provide any support for adding sounds, and we had to integrate other libraries or create a new process for sound effects running independently of our game Gloss event loop. In this case, it didn't synchronize perfectly with our game events, and we had to stop the sound process separately when the game exits. Thus, we decided to remove the features of sound effects.

However, when the setup was ready, it was quite fun to implement the game. We finally had the chance to apply what we had learnt from the lecture to our own project. It was fun to write code in Haskell, to play with data and types, and to simplify code to make our codebase easier to maintain and understand by trying not to "repeat ourselves" when writing code in Haskell. During the course of implementing this Snake game using Haskell, we found Haskell has a very strong static type system which can catch errors at compile time that might only be caught at runtime in other languages. This led to fewer bugs and less time to debug during the implementation, which made our lives easier. Other than that, we also realized that the purity of functions played a very important role in reducing unexpected errors in game development where the state is constantly changing.

Work division

We split tasks and managed the team in an efficient way where we brainstormed together to split tasks into smaller pieces, and everyone had a focus and we were doing pair programming to help each other to debug and QA. We set daily meetings and everyone actively contributed to the project. In our collaborative way, everyone contributed equally.

Links to code etc.

https://github.com/derekhuang73/snake