The goal of this project was to apply the minimax algorithm to the game of connect 4 in order to create an AI that a user can play against.
First, the board is read by the computer and converted into a 2d array made up of a class giving info on the state of the board. In order to choose a move, the program generates a tree which has the current board as its root. Each subsequent level of the tree contains possible moves that could be made from the positions on the level above. The algorithm uses Alpha-Beta pruning in order to eliminate branches that can no longer contribute to the final result, which greatly reduces the amount of work to be done by the program.
It would take too long to generate a tree with all possible permutations of the game, so instead a maximum tree depth is set by the user in the difficulty setting box. This value represents how many moves ahead the algorithm will consider. A higher setting allows the program to make smarter moves, but requires more time to run. On the final level of the tree, each board is given a score according to a heuristic which attempts to score each board according to how favourable it is from the position of the computer player. It's these scores that are used to run the minimax algorithm which determines the move made by the program.