I've got a tic-tac-toe game up and running using SDL, but I'm having a little problem implementing the AI. I looked up on google and learnt of something called the "MiniMax Theorem", which should help me with my task. The problem is while I understand how its supposed to work, I'm having a little problem actually implementing the theorem. A book or some help in the right direction would be welcome.
Here's a small article from lazyfoo's website on AI - With Tic-Tac-Toe. This might come in handy for you, might not. If not let me know and I'll help out a little. This does have some SDL code for it as well.
I wanted to know how I would implement AI using the MiniMax theorem, but I guess that article should do. The article itself is very interesting though, so thanks.
The evaluator function takes as input two parameters - the player whose turn it is to move and the board position. The function returns an int.
The function must return a position "score" with respect to the player whose turn it is to move. A score > 0 means the position is favorable for the player, with higher scores being more favorable; a score < 0 means the position is not favorable for the player, with more negative scores being even less favorable, and 0 meaning the position is even (neither favorable nor disadvantageous).
And I believe this function would be recursive, calling itself every time after evaluation a particular move?
Here's how I understand it, if the player makes a move the postion evaluator function is called. This function creates a copy of the board (since the board is an array) and "plays" a move on it. It then determines how closer this move brings the computer or the player to winning the game. It then calls itself with the other player and the copied board as arguments until the entire board has been filled.
Maybe it doesnt make a lot of sense, but this is the first time I'm trying to make a game, so forgive me if I'm wrong.
That's right, although for performance reasons I'd have the evaluator not copy the board, but rather make the move on the board, do some work, and then undo the move before it returns.