Top

Connect Four

Built a computer agent in Python that intelligently plays the game Connect Four. The agent uses a minimax algorithm enhanced with alpha-beta pruning, in combination with a unique static evaluator function, to pick the optimal move in any situation. The algorithm currently generates states to a tree depth of seven, and each move takes approximately 30 seconds. When playing against another agent that chooses its next move randomly, my agent has a 100% success rate. The algorithm has yet to lose a game against a human player!

The User Interface for playing Connect Four was developed using WxPython. The GUI starts by presenting the user with player options for both participants. Each player can be a human player, or one of three AIs of varying difficulties. The easiest AI is an agent that chooses which column to play randomly. The mediocre program flips a coin to determine whether to choose randomly or use the minimax algorithm. The hard AI always uses the minimax algorithm. It is possible to have AI agents play against one another.

Pieces are played each turn by selecting the column into which it should be dropped. The GUI updates immediately by displaying the piece on the game board. It also displays a “Waiting for Player” message to indicate which player’s turn it is. In the middle of any game the button can be used to restart the match, and at the conclusion of a game it can be used to play again. Finally, if more than one game is played, the total number of wins for each player is tracked in the bottom-left hand corner of the display.