Course:CPSC312-2023/Connect-4
Authors: Amaan, Steven, Gloria
What is the problem?
Connect 4 is a two-player game where players attempt to drop coloured disks into an upright game board such that a horizontal, vertical, or diagonal sequence of four disks of the same colour is created. We are planning to implement this game in Haskell. Players can face each other (PVP) or an AI.
What is the something extra?
We have implemented a GUI that displays the board. Players can use the command line to interact with the GUI. You can make the AI do a random strategy, choosing a random column when it's the AI's turn. The AI can also use a greedy strategy, choosing the action that will create the longest chain of slots of its colour.
What did we learn from doing this?
During this project, we got a lot of experience implementing a game loop using functional paradigms, by putting together building blocks without side effects. It was important to get the custom data types set up correctly, and do think carefully about how data is represented. For example, the decision to make the board a 2D array of columns makes it easier to insert disks into the board, but also complicates row-based iterations.
We also got some more insight into the minimax algorithm shown in class. Our first attempt at minimax resulted in a function that took way too long on boards of any non-trivial size. It's simply not feasible to check the whole game tree, even with caching and hashing tricks. We instead pivoted to implementing a greedy algorithm that looks only a small number of steps ahead.