ai but can't make it work well

This commit is contained in:
Alexandre ALTARIBA 2025-05-23 22:08:17 +02:00
parent 4f71803aa7
commit a3e65fcb81
2 changed files with 39 additions and 5 deletions

View File

@ -32,4 +32,13 @@ public class AutoPlayer {
return possibleMoves.get(random.nextInt(possibleMoves.size()));
}
public void playBestMove(Board board) {
Move bestMove = computeBestMove(board);
if (bestMove != null) {
board.playMove(bestMove);
board.incrementTurn();
}
}
}

View File

@ -214,7 +214,7 @@ public class Board {
// Reset selection and switch turn
selectedCell = null;
turnNumber++;
turnNumber=turnNumber+1;
System.out.println(this);
@ -437,6 +437,26 @@ 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) {
@ -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;
}