AI-powered 3D Connect Four

Work in progress

During my last Christmas holiday at home I stumbled upon a 90s children's bedroom staple, a 3D Connect Four game made of wood:

What's the best strategy?

We played a few games and I became interested in figuring out whether there's a computational way to determine the best strategy or even train a model to play against.

The first step I took was to build a 2D Connect Four game from scratch, to be played in the terminal. It's a common coding channel at universities and bootcamps and there are plenty of repos. I purposefully chose not to look at any of them and instead came up with my own approach.

2D Connect Four has an interesting history — entire Master's theses have been written about the game, and solving Connect Four positions is also used as a benchmark for computer performance.

Connect Four in the terminal

I used Replit again so you can try it out yourself here. After every move the code checks whether one of the three winning options is fulfilled, namely four stones in a row vertically, horizontally or diagonally. If so it announces the winner and ask whether you want to play again. Here's what it looks like during the game:

Next steps

It's work in progress. There are two options that I'm considering which lead to different learning outcomes:

  1. The ML route: Figure out how to use an existing algorithm (most commonly used are minimax approaches) and train a model using my existing code. From there I can then build a 3D version and train (I think?)
  2. The UI route: Build a 3D game similar to the existing 2D game, i.e. something that can be played in the terminal. Presumably I'd have to learn a different tool to build a 3D UI that can be used to play the game.

Right now it looks like option 1, if I can get away from a GPT-based project.