Excellent explanation!
Noah Overcash

Thank you for reading this article and taking the time to implement Minimax.

I evaluated the last AI move when it is clear it should choose index 8 over 3 and I got the following log.

0 returns a score of -10
3 returns a score of -10
5 returns a score of -10
8 returns a score of 0
AI fills spot 8

It seems like your algorithm is misevaluating index 3.

In my opinion, either the terminal state evaluation or the minimaxing ( where the algorithm chooses the minimum or the maximum score based on the player’s turn) needs a bit of tuning.