Course:CPSC312-2024/Connect4
What is the problem?
Implementing the game Connect 4 where the user can play against a computer with the traditional rules of the game (on a 7x6 board).
Connect 4: https://en.wikipedia.org/wiki/Connect_Four
What is something extra?
Giving players the option to choose the computer difficulty they want to play against with optimal moves being decided by our minimax algorithm
- Hard (always uses the minimax algorithm)
- Medium (uses minimax algorithm 60% of the time, randomized 40% of the time)
- Easy (fully randomized)
What did we learn from doing this?
- Got a lot more practice with the syntax, and getting to use what we learnt in class made things more concrete (e.g data types and constructors which we used for our TokenTypes). Using data types and using "let...in" made our code more readable to us
- We initially wrote a lot of code before testing everything, which made debugging and catching edge cases much more challenging. After building things bottom up, it was nice that we could more easily test functions individually to ensure everything was working as expected
- Learnt more about IO types in creating a random index for the computer's move selection (easy/medium mode), especially how getStdRandom returned an IO Int rather than an Int like we had expected
The bottom line is that functional programming is suitable for our task. The game abstraction shown in class was useful for our implementation and allowed us to represent our board states and internal states in ways without side effects affecting the other portions of our code. Being able to break our functionality into small individual functions allowed for a high level of reusability and abstraction such as using the same single function to check if a win occurred in a row, column and diagonal. Overall, functional programming enabled us to translate player actions into game states in a simple and clean way.
Work Division
How was the workload divided? Who did what? (This can be in a private communication to the TA if you do not want it to be public).