ai but can't make it work well
This commit is contained in:
parent
4f71803aa7
commit
a3e65fcb81
|
|
@ -32,4 +32,13 @@ public class AutoPlayer {
|
||||||
return possibleMoves.get(random.nextInt(possibleMoves.size()));
|
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
|
// Reset selection and switch turn
|
||||||
selectedCell = null;
|
selectedCell = null;
|
||||||
turnNumber++;
|
turnNumber=turnNumber+1;
|
||||||
System.out.println(this);
|
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) {
|
public void playMove(Move move) {
|
||||||
|
|
||||||
|
|
@ -494,6 +514,11 @@ public class Board {
|
||||||
System.out.println(this);
|
System.out.println(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void incrementTurn() {
|
||||||
|
turnNumber++;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPiece(int x, int y) {
|
public boolean hasPiece(int x, int y) {
|
||||||
return cells[x][y] != null;
|
return cells[x][y] != null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue