try to make cutoffs with a certain depth ... I don't think you need more than 4 or 5 depths to make the perfect move.
(java for 3 * 3 one-dimensional boards with depth):
int minimax(int turn, int depth) {
int val = -turn;
int result = NULVAL;
if (wins()) return turn;
if (depth == 0) return DRAW;
for (int i = 0; i < 9; i++) {
if (board[i] == EMPTY) {
board[i] = turn;
result = minimax(-turn, depth - 1);
board[i] = EMPTY;
if (result == turn)
return turn;
if (result == DRAW)
val = result;
}
}
if (result == NULVAL) return DRAW;
return val;
}
source
share