public int Min(GameBoard board, int step,ref int alpha,ref int beta) { minCalls++; if (board.IsGameOver() || IsDepthReached(step)) return board.EvaluateBoard(PlayerColours.Black); else { int bestValue = int.MaxValue; List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.White); foreach (GamePieceMove move in PossibleMoves) { int currentValue = Max(CreateCurrentBoard(board, move), step + 1, ref alpha, ref beta); board.UnDoMove(move); if (currentValue < bestValue) { bestValue = currentValue; beta = currentValue; } if (beta <= alpha) return bestValue; } return bestValue; } }
public void MiniMaxWithoutAlphaBetaPruning(GameBoard board) { startTime = System.DateTime.Now; maxCalls = 0; minCalls = 0; int bestValue = 0; List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.Black); foreach (GamePieceMove move in PossibleMoves) { int currentValue = MinWithoutAlphaBetaPruning(CreateCurrentBoard(board, move), FIRSTSTEP); board.UnDoMove(move); if (currentValue > bestValue) { bestMove = move; bestValue = currentValue; } } endTime = System.DateTime.Now; }
public int MinWithoutAlphaBetaPruning(GameBoard board, int step) { minCalls++; if (board.IsGameOver() || IsDepthReached(step)) return board.EvaluateBoard(PlayerColours.Black); else { int bestValue = int.MaxValue; List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.White); foreach (GamePieceMove move in PossibleMoves) { int currentValue = MaxWithoutAlphaBetaPruning(CreateCurrentBoard(board, move), step + 1); board.UnDoMove(move); if (currentValue < bestValue) bestValue = currentValue; } return bestValue; } }
private int Max(GameBoard board, int step, ref int alpha, ref int beta) { if (board.IsGameOver() || IsDepthReached(step)) return board.EvaluateBoard(PlayerColours.Black); else { int bestValue = 0; List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.Black); foreach (GamePieceMove move in PossibleMoves) { GameBoard currentBoard = new GameBoard(); currentBoard = board.CloneBoard(); currentBoard.ApplyMove(move); currentBoard = MakeAddtionalMoves(currentBoard, move).CloneBoard(); int currentValue = Min(currentBoard, step + 1, ref alpha, ref beta); board.UnDoMove(move); if (currentValue > bestValue) { bestValue = currentValue; alpha = bestValue; } if (beta >= alpha) return bestValue; } return bestValue; } }
private void MiniMax(GameBoard board) { int bestValue = 0; List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.Black); foreach (GamePieceMove move in PossibleMoves) { GameBoard currentBoard = board.CloneBoard(); currentBoard.ApplyMove(move); currentBoard = MakeAddtionalMoves(currentBoard, move).CloneBoard(); int currentValue = Min(currentBoard, FIRSTSTEP,ref alpha,ref beta); board.UnDoMove(move); if (currentValue > bestValue) { bestMove = move; bestValue = currentValue; } } }