Код: Выделить всё
float Minimax(char[,] _board, int depth, bool isMax) {
if (depth == 0 || isFull(_board)) {
EvaluateBoard(_board);
}
if (isMax) {
float bestScore = -Mathf.Infinity;
float score = -Mathf.Infinity;
for (int i = 0; i < 7; i++) {
char[,] board = (char[, ]) _board.Clone();
if (Play(board, i, false)) {
score = Minimax(board, depth - 1, false);
bestScore = Mathf.Max(score, bestScore);
}
}
return bestScore;
} else {
float bestScore = Mathf.Infinity;
float score = Mathf.Infinity;
for (int i = 0; i < 7; i++) {
char[,] board = (char[, ]) _board.Clone();
if (Play(board, i, true)) {
score = Minimax(board, depth - 1, true);
bestScore = Mathf.Min(score, bestScore);
}
}
return bestScore;
}
}
Код: Выделить всё
float ABPruning(char[,] _board, int depth, float alpha, float beta, bool isMax) {
if (depth == 0 || isFull(_board)) {
return EvaluateBoard(_board);
}
if (isMax) {
float bestScore = -Mathf.Infinity;
for (int i = 0; i < 7; i++) {
char[, ] board = (char[,]) _board.Clone();
if (Play(board, i, false)) {
bestScore = ABPruning(board, depth - 1, alpha, beta, false);
alpha = Mathf.Max(alpha, bestScore);
if (beta
Подробнее здесь: [url]https://stackoverflow.com/questions/67952011/minimax-works-fine-but-alpha-beta-pruning-doesnt[/url]