From e2ca1c2f38725050a4f4b788900b16519a0545bb Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Thu, 16 Mar 2023 01:01:31 -0700 Subject: [PATCH] Possibly fix intermittent stalemate issues --- src/Board.java | 2 +- src/ChessAI.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Board.java b/src/Board.java index 0722d8c..287a263 100644 --- a/src/Board.java +++ b/src/Board.java @@ -232,7 +232,7 @@ public class Board { break; } } - } else if (getAllLegalMoves(movedPiece.black).isEmpty()) { + } else if (getAllLegalMoves(!movedPiece.black).isEmpty()) { isGameOver = true; isStalemate = true; } diff --git a/src/ChessAI.java b/src/ChessAI.java index 9d3c1cd..f11128a 100644 --- a/src/ChessAI.java +++ b/src/ChessAI.java @@ -6,10 +6,11 @@ public class ChessAI { public static Move findBestMove(Board board) { int bestScore = Integer.MIN_VALUE; - Move bestMove = null; ArrayList 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);