Introducing

Connect 4 Agent

The Connect 4 Agent is a simple AI Agent that can play the game Connect 4. This was a project that I was excited to work on and was part of the CS2109S module in NUS. For my project, I found similar projects online which detailed how I could build a Connect 4 Solver. I then used these projects as a base and built upon them to create my own Connect 4 Agent.

Stack

PythonC++

The Connect 4 Agent used the minimax algorithm with alpha-beta pruning to make the best decision at every particular move. While working on this project, one major constraint that we had to work with was that the agent had to be initialized and make a move within 1 second, and the app size could not exceed 1MB. This proved to be a tough challenge indeed as there were a lot of optimization steps that I needed to take to ensure that the agent could operate within these constraints.

Connect 4 Agent in play

Some key features of Connect 4 Agent include:

  • Bitboard representation of the Connect 4 board
  • Minimax algorithm with alpha-beta pruning
  • Evaluation function to evaluate the board state
  • Efficient move ordering to increase efficiency of pruning
  • Anticipate opponent's direct winning moves and block them
  • Transposition table to store previously computed positions
  • 12-move lookup table to store the best move for the first 12 moves

Final Thoughts

Overall, I am happy with the way the connect 4 agent turned out, and this was something that I genuinely interested in. After this module, I plan to continue working on more AI-ML and game theory related projects and hope to learn more about this field.