Skip to content

Commit

Permalink
Baby steps towards engine optimisation, may not be implemented in the…
Browse files Browse the repository at this point in the history
… final versions
  • Loading branch information
a2ys committed Jul 14, 2023
1 parent b46dc5e commit 808a8be
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/a2ys/chess/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Engine {
private final MoveGenerator moveGenerator = new MoveGenerator();
public static List<List<List<Integer>>> ZobristTable = new ArrayList<>();
private boolean lol = false;
private HashMap<Integer, ArrayList<ArrayList<ArrayList<Move>>>> moveListWithHash = new HashMap<>();
Board board;

public void initialize() {
Expand Down Expand Up @@ -687,4 +688,23 @@ public static int computeHash(Pieces[][] board) {
private Board getBoard() {
return board;
}

private ArrayList<ArrayList<ArrayList<Move>>> getLegalMoves(Pieces[][] boardArray, Board board) throws KingCapturedError {
ArrayList<ArrayList<ArrayList<Move>>> allLegalMoves = new ArrayList<>();
String activePlayer = getActivePlayer();

for (int i = 0; i < 8; i++) {
ArrayList<ArrayList<Move>> rowMoves = new ArrayList<>();
for (int j = 0; j < 8; j++) {
Pieces piece = boardArray[i][j];
ArrayList<Move> 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;
}
}

0 comments on commit 808a8be

Please sign in to comment.