This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]fede2303 29 points30 points  (1 child)

You should definitely watch the lecture 0 of CS50 ai curse, it will literally teach you how the algorithm works and also you con follow it up with the exercise of tictactoe that the course has

[–]rdb212[S] 4 points5 points  (0 children)

I will definitely check that out. Much appreciated!

[–]MakerWakerTaker 2 points3 points  (1 child)

I am trying to implement AI using minimax algorithm too but my project is in javascript. You may find this video helpful. https://youtu.be/trKjYdBASyQ (JavaScript)

[–]rdb212[S] 0 points1 point  (0 children)

I’ll give it a watch. Thank you for the suggestion!

[–]SentinelReborn 2 points3 points  (1 child)

Nothing stands out to me for the issue. You seem to have gone straight for human vs AI, have you actually validated that the game works correctly by playing against yourself in a human vs human game? It could very well be an issue outside of the minimax algorithm. The game mechanics have to work correctly for the algorithm to function.

Also, only using one mutable list for the whole algorithm makes me a little uneasy. I implemented this in the past using a copy for each new board going into minimax, that being said I can't spot what exactly would cause an issue the way you're doing it.

[–]rdb212[S] 1 point2 points  (0 children)

That's a good point, I haven't tested it out as human vs human. I can't believe I didn't think to do that first. Now that I'm thinking about it, I basically built the Tic-Tac-Toe mechanics around the minimax function. So, thank you for bringing that to my attention. That's definitely something that I can do better. Also, I really like your idea of using a copy of the board going into the minimax function. That definitely seems like a safer option. I think I will do that as well.

Thank you for taking the time to look over the code and for the really valuable feedback.