So I was looking up Mini-max for a Tic-Tac-Toe Game, but couldn\'t understand how the recursion worked? Okay, so basically here are my questions:
1) How does minimax know whose turn is it? Whats the best way to indicate the player whose turn it is generating?
You have that depth
argument. If the depth is even, then it's one player's turn, if it's odd, then it's the other player's turn.
2) How do you generate possible moves?
Using the rules of the game. In tic tac toe, a possible move means placing one's mark into a free cell.
3) How do you know when you are at a terminal node, and how do you generate the terminal nodes?
A terminal node is a node where someone has won. You generate them by recursion. Each recursive call should be given the current state of the board. I guess that's the node
and child
parameters in your pseudocode. So if in that situation someone has won, then it's terminal, otherwise you try all legal moves and recurse.