diff --git a/src/main/java/com/a2ys/chess/Engine.java b/src/main/java/com/a2ys/chess/Engine.java index db98355..81e02a6 100644 --- a/src/main/java/com/a2ys/chess/Engine.java +++ b/src/main/java/com/a2ys/chess/Engine.java @@ -13,6 +13,7 @@ public class Engine { private final MoveGenerator moveGenerator = new MoveGenerator(); public static List>> ZobristTable = new ArrayList<>(); private boolean lol = false; + private HashMap>>> moveListWithHash = new HashMap<>(); Board board; public void initialize() { @@ -687,4 +688,23 @@ public static int computeHash(Pieces[][] board) { private Board getBoard() { return board; } + + private ArrayList>> getLegalMoves(Pieces[][] boardArray, Board board) throws KingCapturedError { + ArrayList>> allLegalMoves = new ArrayList<>(); + String activePlayer = getActivePlayer(); + + for (int i = 0; i < 8; i++) { + ArrayList> rowMoves = new ArrayList<>(); + for (int j = 0; j < 8; j++) { + Pieces piece = boardArray[i][j]; + ArrayList pieceMoves = new ArrayList<>(); + if (piece.getColor().equals(activePlayer)) { + pieceMoves = getLegalMoves(moveGenerator.pseudoLegalMoves(piece, boardArray), board, boardArray); + } + rowMoves.add(j, pieceMoves); + } + allLegalMoves.add(i, rowMoves); + } + return allLegalMoves; + } }