private int maxMove(CheckersBoard board, int depth, int alpha, int beta) { if (cutOffTest(board, depth)) { return(eval(board)); } List sucessors; List move; CheckersBoard nextBoard; int value; sucessors = board.legalMoves(); while (mayPlay(sucessors)) { move = (List)sucessors.pop_front(); nextBoard = (CheckersBoard)board.clone(); nextBoard.move(move); value = minMove(nextBoard, depth + 1, alpha, beta); if (value > alpha) { alpha = value; } if (alpha > beta) { return(beta); } } return(alpha); }
private List minimax(CheckersBoard board) { List sucessors; List move, bestMove = null; CheckersBoard nextBoard; int value, maxValue = Int32.MinValue; sucessors = board.legalMoves(); while (mayPlay(sucessors)) { move = (List)sucessors.pop_front(); nextBoard = (CheckersBoard)board.clone(); nextBoard.move(move); value = minMove(nextBoard, 1, maxValue, Int32.MaxValue); if (value > maxValue) { maxValue = value; bestMove = move; } } return(bestMove); }