int MinValue(CheckerBoard currentBoard, int depth, int alpha, int beta, int currentPlayer) { if (_nodeGeneration % 10000 == 0 && _nodeGeneration != 0) { Console.WriteLine("Max Depth: {0}", _maxDepth); Console.WriteLine("# of Pruning in Max: {0}", _maxPruning); Console.WriteLine("# of Pruning in Min: {0}", _minPruning); Console.WriteLine("# of Node Generated: {0}", _nodeGeneration); Console.WriteLine("Time Elapsed: {0}", TimeElapsed); } CheckerStatus status = currentBoard.GetStatus(_currentTurn); if (status != CheckerStatus.Continue) { return((int)status); } _maxDepth = Math.Max(_maxDepth, depth); if (depth == Difficulty) { return(currentBoard.EvaluateBoard(_currentTurn)); } int v = 999; //For each movable piece for (var i = 0; i < currentBoard.MovablePieces[currentPlayer].Count(); i++) { //for each possible positions that the piece can go for (var j = 0; j < currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]].Count(); j++) { _nodeGeneration++; //For each possible move make a new checkerboard and move it var newCheckerBoard = new CheckerBoard(currentBoard); var selectedPiece = newCheckerBoard.GetCheckerPiece(currentBoard.MovablePieces[currentPlayer][i].Row, currentBoard.MovablePieces[currentPlayer][i].Col); newCheckerBoard.SelectedPiece = selectedPiece; newCheckerBoard.HandleMove(currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]); newCheckerBoard.CheckAllAvailableMoves(); int nextTurn = newCheckerBoard.AINextTurn(currentPlayer); v = Math.Min(v, MaxValue(newCheckerBoard, depth + 1, alpha, beta, nextTurn)); //pruning if (v <= alpha) { _minPruning++; return(v); } if (v < beta) { beta = v; if (currentBoard == _checkerBoard) { _bestMoveSet = currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]; _bestPiece = currentBoard.MovablePieces[currentPlayer][i]; } } } } return(v); }
int MinValue(CheckerBoard currentBoard, int depth, int alpha, int beta, int currentPlayer) { if (_nodeGeneration % 10000 == 0 && _nodeGeneration != 0) { Console.WriteLine("Max Depth: {0}", _maxDepth); Console.WriteLine("# of Pruning in Max: {0}", _maxPruning); Console.WriteLine("# of Pruning in Min: {0}", _minPruning); Console.WriteLine("# of Node Generated: {0}", _nodeGeneration); Console.WriteLine("Time Elapsed: {0}", TimeElapsed); } CheckerStatus status = currentBoard.GetStatus(_currentTurn); if (status != CheckerStatus.Continue) { return (int) status; } _maxDepth = Math.Max(_maxDepth, depth); if (depth == Difficulty ) return currentBoard.EvaluateBoard(_currentTurn); int v = 999; //For each movable piece for (var i = 0; i < currentBoard.MovablePieces[currentPlayer].Count(); i++) { //for each possible positions that the piece can go for (var j = 0; j < currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]].Count(); j++) { _nodeGeneration++; //For each possible move make a new checkerboard and move it var newCheckerBoard = new CheckerBoard(currentBoard); var selectedPiece = newCheckerBoard.GetCheckerPiece(currentBoard.MovablePieces[currentPlayer][i].Row, currentBoard.MovablePieces[currentPlayer][i].Col); newCheckerBoard.SelectedPiece = selectedPiece; newCheckerBoard.HandleMove(currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]); newCheckerBoard.CheckAllAvailableMoves(); int nextTurn = newCheckerBoard.AINextTurn(currentPlayer); v = Math.Min(v, MaxValue(newCheckerBoard, depth + 1, alpha, beta, nextTurn)); //pruning if (v <= alpha) { _minPruning++; return v; } if (v < beta) { beta = v; if (currentBoard == _checkerBoard) { _bestMoveSet = currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]; _bestPiece = currentBoard.MovablePieces[currentPlayer][i]; } } } } return v; }
//Gets the Max Value int MaxValue(CheckerBoard currentBoard, int depth, int alpha, int beta, int currentPlayer) { if (_nodeGeneration % 10000 == 0 && _nodeGeneration != 0) { Console.WriteLine("Max Depth: {0}", _maxDepth); Console.WriteLine("# of Pruning in Max: {0}", _maxPruning); Console.WriteLine("# of Pruning in Min: {0}", _minPruning); Console.WriteLine("# of Node Generated: {0}", _nodeGeneration); Console.WriteLine("Time Elapsed: {0}", TimeElapsed); } //Checks to see if it is a utility value CheckerStatus status = currentBoard.GetStatus(_currentTurn); //If it is return the value if (status != CheckerStatus.Continue) { return((int)status); } _maxDepth = Math.Max(_maxDepth, depth); //Depth Limiter if (depth == Difficulty) { return(currentBoard.EvaluateBoard(_currentTurn)); } var v = -999; //Iterate through every movable pieces for (var i = 0; i < currentBoard.MovablePieces[currentPlayer].Count(); i++) { //Iterate through every possible move for the selected piece for (var j = 0; j < currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]].Count(); j++) { //Increment node counter _nodeGeneration++; //For each possible move make a new checkerboard and move it var newCheckerBoard = new CheckerBoard(currentBoard); //Select the piece that will be moved var selectedPiece = newCheckerBoard.GetCheckerPiece(currentBoard.MovablePieces[currentPlayer][i].Row, currentBoard.MovablePieces[currentPlayer][i].Col); newCheckerBoard.SelectedPiece = selectedPiece; //Move the piece to a piece location newCheckerBoard.HandleMove(currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]); newCheckerBoard.CheckAllAvailableMoves(); var nextTurn = newCheckerBoard.AINextTurn(currentPlayer); v = Math.Max(v, MinValue(newCheckerBoard, depth + 1, alpha, beta, nextTurn)); if (v >= beta) { _maxPruning++; return(v); } if (v > alpha) { alpha = v; if (currentBoard == _checkerBoard) { _bestMoveSet = currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]; _bestPiece = currentBoard.MovablePieces[currentPlayer][i]; } } } } return(v); }
//Gets the Max Value int MaxValue(CheckerBoard currentBoard, int depth, int alpha, int beta, int currentPlayer) { if (_nodeGeneration % 10000 == 0 && _nodeGeneration !=0) { Console.WriteLine("Max Depth: {0}", _maxDepth); Console.WriteLine("# of Pruning in Max: {0}", _maxPruning); Console.WriteLine("# of Pruning in Min: {0}", _minPruning); Console.WriteLine("# of Node Generated: {0}", _nodeGeneration); Console.WriteLine("Time Elapsed: {0}", TimeElapsed); } //Checks to see if it is a utility value CheckerStatus status = currentBoard.GetStatus(_currentTurn); //If it is return the value if (status != CheckerStatus.Continue) { return (int) status; } _maxDepth = Math.Max(_maxDepth, depth); //Depth Limiter if (depth == Difficulty ) return currentBoard.EvaluateBoard(_currentTurn); var v = -999; //Iterate through every movable pieces for (var i = 0; i < currentBoard.MovablePieces[currentPlayer].Count(); i++) { //Iterate through every possible move for the selected piece for (var j = 0; j < currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]].Count(); j++) { //Increment node counter _nodeGeneration++; //For each possible move make a new checkerboard and move it var newCheckerBoard = new CheckerBoard(currentBoard); //Select the piece that will be moved var selectedPiece = newCheckerBoard.GetCheckerPiece(currentBoard.MovablePieces[currentPlayer][i].Row, currentBoard.MovablePieces[currentPlayer][i].Col); newCheckerBoard.SelectedPiece = selectedPiece; //Move the piece to a piece location newCheckerBoard.HandleMove(currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]); newCheckerBoard.CheckAllAvailableMoves(); var nextTurn = newCheckerBoard.AINextTurn(currentPlayer); v = Math.Max(v, MinValue(newCheckerBoard, depth + 1, alpha, beta, nextTurn)); if (v >= beta) { _maxPruning++; return v; } if (v > alpha) { alpha = v; if (currentBoard == _checkerBoard) { _bestMoveSet = currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]; _bestPiece = currentBoard.MovablePieces[currentPlayer][i]; } } } } return v; }