Course:CPSC312-2023-2048Game

From UBC Wiki

Authors: Yuefeng Zhao, Ethan Tan, Zet Zhou

What is the problem?

We aim to implement the popular 2048 game similar to this: https://en.wikipedia.org/wiki/2048_(video_game)

What is the something extra?

Play the game with arrow keys responsively, listening functionality.

Allow user to choose the board size (normal game is just 4x4 board).

What did we learn from doing this?

By doing this project, we learned about some of the advantages and disadvantages of using functional programming to make games.

While initially it was quite challenging to implement some basic functionality with Haskell (for example, choosing blank tiles in the board) which we knew would be easy to implement in a traditional OOP approach in Java, some advantages to the functional programming approach became clear. Our code relies on recursive functionality which was optimal to implement with functional programming in Haskell. Some of the explicit concepts we learned how to do are: use IO types, think and implement code recursively, use type abstractions, build programs from the bottom up, use list comprehensions, install external Haskell libraries, and more.

Haskell being a pure language with no side effects also made it easy for us to build our abstractions from the bottom up. For example, we were able to make many simple reusable abstraction components like allCoordinates or getEmptySquares which made it easy to understand the state of the program at various stages of the logic flow. Since Haskell's functional programming is effectively evaluating expressions, the code is also very concise compared to if we had used a language like Java. We also learned about how to install external Haskell packages using cabal. It was extremely simple with good documentation and community support. Testing is also very easy as it can be done directly in ghci using terminal commands. These are advantages that should be considered when deciding whether or not to use Haskell to make a game.

Conversely, we realized that some aspects of our program would have been easier to implement with another programming approach. For example, if we were able to modify our board directly (it is immutable in Haskell using functional programming), we can save on memory usage instead of creating a new board every time.

Our conclusion is that since our game works smoothly, is easy to test, and is quick and easy to use from a user perspective, we think programming the 2048 game is certainly feasible to do with functional programming. While there are various advantages and disadvantages like we highlighted above, we think that the benefits provide a unique approach to game design compared to other programming approaches, so it is absolutely worth considering functional programming for building games (especially ones with heavy recursion like our program).

Links to code etc

https://github.com/MaxonZhao/CPSC312-project1-2048