C++ TicTacToe Minimax Issue

I seem to be having a hard time on the minimax function on my C++ app. I've been trying to emulate the minimax function I found on this link: https://gist.github.com/MatthewSteel/3158579

Most of the functionality within the minimax process is similar however, I keep getting the wrong results. For example, I have my board set up as this:

1 | 2 | 3
4 | 5 | 6
7 | 8 | 9

Playing against the ai, and I choose first (X), I put myself on 5, and the ai covers 1. That's great. The issue is that after I choose any number except those taken on the board like say 4, the ai chooses 1 still and then goes on an endless loop.

Here's the code if anyone wants to take a look. The process that calls the minimax function starts with doAiMove() which uses it to determine where to place the AI's mark. I know that there's a lot to fix such as the OOP aspect but for now I'd like to fix the AI before anything else.

Here is the link to the full source code:

https://www.reddit.com/r/learnprogramming/comments/46okav/new_c_tictactoe_code/
Topic archived. No new replies allowed.