Possibly fix intermittent stalemate issues

main
Elnu 2 years ago
parent 5e1553aaf6
commit e2ca1c2f38

@ -232,7 +232,7 @@ public class Board {
break;
}
}
} else if (getAllLegalMoves(movedPiece.black).isEmpty()) {
} else if (getAllLegalMoves(!movedPiece.black).isEmpty()) {
isGameOver = true;
isStalemate = true;
}

@ -6,10 +6,11 @@ public class ChessAI {
public static Move findBestMove(Board board) {
int bestScore = Integer.MIN_VALUE;
Move bestMove = null;
ArrayList<Move> legalMoves = board.getAllLegalMoves(true);
Collections.shuffle(legalMoves);
Move bestMove = legalMoves.get(0);
for (Move move : legalMoves) {
board.move(move);
int score = minimax(board, MAX_DEPTH, Integer.MIN_VALUE, Integer.MAX_VALUE, false);