Possibly fix intermittent stalemate issues
This commit is contained in:
parent
5e1553aaf6
commit
e2ca1c2f38
2 changed files with 3 additions and 2 deletions
|
@ -232,7 +232,7 @@ public class Board {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (getAllLegalMoves(movedPiece.black).isEmpty()) {
|
} else if (getAllLegalMoves(!movedPiece.black).isEmpty()) {
|
||||||
isGameOver = true;
|
isGameOver = true;
|
||||||
isStalemate = true;
|
isStalemate = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,11 @@ public class ChessAI {
|
||||||
|
|
||||||
public static Move findBestMove(Board board) {
|
public static Move findBestMove(Board board) {
|
||||||
int bestScore = Integer.MIN_VALUE;
|
int bestScore = Integer.MIN_VALUE;
|
||||||
Move bestMove = null;
|
|
||||||
|
|
||||||
ArrayList<Move> legalMoves = board.getAllLegalMoves(true);
|
ArrayList<Move> legalMoves = board.getAllLegalMoves(true);
|
||||||
|
|
||||||
Collections.shuffle(legalMoves);
|
Collections.shuffle(legalMoves);
|
||||||
|
Move bestMove = legalMoves.get(0);
|
||||||
for (Move move : legalMoves) {
|
for (Move move : legalMoves) {
|
||||||
board.move(move);
|
board.move(move);
|
||||||
int score = minimax(board, MAX_DEPTH, Integer.MIN_VALUE, Integer.MAX_VALUE, false);
|
int score = minimax(board, MAX_DEPTH, Integer.MIN_VALUE, Integer.MAX_VALUE, false);
|
||||||
|
|
Reference in a new issue