For one of my first deep dives into AI, I decided to make an AI in Python3 that could always beat (or at least tie against) a human player.
The first task was to get the basic Connect4 game working in python utilizing Pygame for visuals. The first game allowed for two players to play a basic Connect4 game against each other.
Once I got the basic game working, I moved onto a very primitive AI that randomly placed a piece onto the board. It basically never wins.
Finally it was time to start implementing the beginning of the MiniMax algorithm. The first successful algorithm was able to look into a depth of 3 and could beat most human players.
Using the same algorithm, I tried raising the depth until I found it's upper limit. I found the limit very soon at a depth of 5 where the AI took 3-5 seconds per decision. Raising the depth to 6 would freeze and often crash the program so I knew some optimization was necessary.
The most common form of optimization for a Minimax algorithm is alpha-beta pruning, so that's what I implemented first. Here is the AI working at a depth of 5 with alpha-beta pruning and it is much faster. At this depth I could not find a human player that was able to beat the AI so I mostly considered this good enough. More optimizations could have been made to make it work quickly at larger depths but it did not seem necessary.
Now that I had a functioning, optimized AI, it was time to pit AI vs AI. The first test was an AI with a depth of 3 vs an AI with a depth of 4. Interestingly, the AI with a depth of 4 wins about 90% of the time, but not 100% of the time like I would have guessed. At first I thought this was highlighting an error in my AI but I believe it is highlighting the strength of first-turn-advantage.