ai but can't make it work well
This commit is contained in:
parent
4f71803aa7
commit
a3e65fcb81
|
|
@ -10,7 +10,7 @@ public class AutoPlayer {
|
|||
ArrayList<Move> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void playBestMove(Board board) {
|
||||
Move bestMove = computeBestMove(board);
|
||||
if (bestMove != null) {
|
||||
board.playMove(bestMove);
|
||||
board.incrementTurn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue