We will add a new function to the BoardAI class as follows:
- Create the ABNegamax function:
public static float ABNegamax( Board board, int player, int maxDepth, int currentDepth, ref Move bestMove, float alpha, float beta) { // next steps here }
- Validate the base case:
if (board.IsGameOver() || currentDepth == maxDepth) return board.Evaluate(player);
- Set the initial values:
bestMove = null; float bestScore = Mathf.NegativeInfinity;
- Loop through every available move and return the best score:
foreach (Move m in board.GetMoves()) { // next steps here } return bestScore;
- Create a new game state from the current move:
Board b = board.MakeMove(m);
- Set the values for calling the recursion:
float recursedScore; Move ...