diff --git a/src/backend/AutoPlayer.java b/src/backend/AutoPlayer.java index 2e2e15a..dce920c 100644 --- a/src/backend/AutoPlayer.java +++ b/src/backend/AutoPlayer.java @@ -10,7 +10,7 @@ public class AutoPlayer { ArrayList possibleMoves = new ArrayList<>(); for (Piece piece : board.getPieces()) { - if (piece.isWhite() != board.isTurnWhite()) continue; + if (piece.isWhite() != board.isTurnWhite()) continue; int originX = piece.getX(); int originY = piece.getY(); @@ -31,5 +31,14 @@ public class AutoPlayer { if (possibleMoves.isEmpty()) return null; return possibleMoves.get(random.nextInt(possibleMoves.size())); } - -} \ No newline at end of file + + public void playBestMove(Board board) { + Move bestMove = computeBestMove(board); + if (bestMove != null) { + board.playMove(bestMove); + board.incrementTurn(); + } + } +} + + diff --git a/src/backend/Board.java b/src/backend/Board.java index 2a00a43..92b9bda 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -214,7 +214,7 @@ public class Board { // Reset selection and switch turn selectedCell = null; - turnNumber++; + turnNumber=turnNumber+1; System.out.println(this); @@ -437,7 +437,27 @@ public class Board { } } - + // In Board.java + + public void activateSelection(int x, int y) { + if (cells[x][y] != null && cells[x][y].isWhite() == isTurnWhite()) { + selectedCell = cells[x][y]; + } else { + selectedCell = null; + } + } + + public boolean isValidDestination(int x, int y) { + return isHighlighted(x, y); + } + + public Piece getPieceAt(int x, int y) { + if (x >= 0 && x < cNum && y >= 0 && y < lNum) { + return cells[x][y]; + } + return null; + } + public void playMove(Move move) { int fromX = move.getFromX(); @@ -494,6 +514,11 @@ public class Board { System.out.println(this); } + + public void incrementTurn() { + turnNumber++; + } + public boolean hasPiece(int x, int y) { return cells[x][y] != null; }