private int AlphaBetaPruning(T board, bool machineMove, int depth, int alpha, int beta) { int winner = problem.CheckWinner(board); if (winner != 0) { return(problem.GetWinnerScore(winner, machineMove, depth)); } List <M> emptyFields = problem.GetPossibleMoves(board); // Draw if (emptyFields.Count.Equals(0)) { return(0); } int maxScore = alpha; for (int i = 0; i < emptyFields.Count; i++) { T newBoard = problem.GetProblem(board); if (machineMove.Equals(false)) { problem.Player1Move(newBoard, emptyFields[i]); } else { problem.Player2Move(newBoard, emptyFields[i]); } int score = -this.AlphaBetaPruning(newBoard, !machineMove, depth + 1, -beta, -maxScore); if (score > maxScore) { maxScore = score; if (maxScore >= beta) { break; } } } return(maxScore); }
private int MiniMaxAlgorithm(T board, bool machineMove, int depth) { int winner = problem.CheckWinner(board); if (winner != 0) { return(problem.GetWinnerScore(winner, machineMove, depth)); } List <M> emptyFields = problem.GetPossibleMoves(board); // Draw if (emptyFields.Count.Equals(0)) { return(0); } int maxScore = int.MinValue; for (int i = 0; i < emptyFields.Count; i++) { T newBoard = problem.GetProblem(board); if (machineMove.Equals(false)) { problem.Player1Move(newBoard, emptyFields[i]); } else { problem.Player2Move(newBoard, emptyFields[i]); } int score = -MiniMaxAlgorithm(newBoard, !machineMove, depth + 1); if (score > maxScore) { maxScore = score; } } return(maxScore); }