Course:CPSC312-2021/connect4

From UBC Wiki

Connect 4

Authors: Vandy Liu, Eric Jang

Our game

What is the problem?

The problem we are trying to tackle is how feasible is using functional programming and Haskell to create games. We've decided to tackle this problem by trying to code the game connect four in Haskell. Connect four is a two player game, where both players take turns making moves and try to have four markers in a row horizontally, vertically or diagonally. The board is 7 (wide) by 6 (high). The red player goes first and the yellow player goes second. A player can place their piece in any of the 7 columns, and the marker falls down to the first available spot (usually by gravity). The first player to have four markers in a row wins the game. If all the spots on the board are filled and no one has won yet, then it is a draw. More on the game can be seen here: https://en.wikipedia.org/wiki/Connect_Four.

What is the something extra?

We will be implementing various different CPU algorithms ranging in strength. We made a simple player that always plays a predetermined list of actions no matter what then a random player who plays randomly. We also added more complicated algorithms: Monte-Carlo tree search algorithm and Mini-Max algorithm.

We will also incorporate graphics using the Gloss package for a better user experience!

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.

The bottom-line is that Haskell and functional programming is indeed feasible for creating games. Although we struggled at first with designing the game without objects and classes, we realized that there are many strengths of functional programming for games. First of all, encoding a state is very easy and handing in the state as an argument to a function without side effects makes testing easier and makes us more confident that things are working correctly. We could test out how our computer algorithms worked in various states just by changing the input. Secondly, coding the algorithms were a lot simpler than expected because we didn't have to worry about side effects. Thirdly, creating abstractions made thinking about the project simpler and let us focus on one piece of the game at a time. Lastly, we were worried that graphics may be a little tough on Haskell but using the Gloss package, it was really easy and intuitive and we think we made a neat game with a very strong computer for endless fun!

Links to code, etc

https://github.com/vandyliu/connect4-haskell