int minmax(Board game, int depth)
{
if (game.IsFinished() || depth < 0)
return game.Score(game.Turn);
int alpha = int.MinValue + 1;
foreach (Point move in game.Generate_Moves())
{
Board currentBoard = game;
currentBoard.Do_Move(move);
alpha = max(alpha, -minmax(currentBoard, depth-1));
currentBoard.Undo_Move(move);
}
return alpha;
}
The thing is that this little function tells me if the game is a win, a lose or a draw, but how can i get the move that will led me to a win? My Point class is a simple Class With 2 coordinates X, Y and i want to get the answer as a point so i can latter say something like game.Do_Move(myPoint).
In case some functions aren't obvious:
game.IsFinished() - returns true if win/lose/draw else otherwise
game.Score(turn) - returns -1/0/1 in case is a lose/draw/win for the player with the next move
game.Generate_Moves() - returns a List with available moves
game.Do_Move() - void that applies the move to game
game.Undo_Move() - talks for itself