i deleted autoplyer
This commit is contained in:
parent
ca414277ec
commit
8fa267a893
|
|
@ -13,29 +13,13 @@ public class AutoPlayer {
|
|||
* @return
|
||||
*/
|
||||
public Move computeBestMove(Board board) {
|
||||
List<Move> allPossibleMoves = new ArrayList<>();
|
||||
boolean isWhiteTurn = board.isTurnWhite();
|
||||
|
||||
for (Piece piece : board.getPieces()) {
|
||||
if (piece.isWhite() == isWhiteTurn) {
|
||||
board.userTouch(piece.getX(), piece.getY()); // triggers highlighting
|
||||
|
||||
for (int newX = 0; newX < board.getWidth(); newX++) {
|
||||
for (int newY = 0; newY < board.getHeight(); newY++) {
|
||||
if (board.isHighlighted(newX, newY)) {
|
||||
allPossibleMoves.add(new Move(piece.getX(), piece.getY(), newX, newY, piece));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allPossibleMoves.isEmpty()) return null;
|
||||
|
||||
Random rand = new Random();
|
||||
return allPossibleMoves.get(rand.nextInt(allPossibleMoves.size()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -393,30 +393,8 @@ return false; }
|
|||
}*/
|
||||
|
||||
public void playMove(Move move) {
|
||||
if (move == null || move.getPieceMoved() == null) return;
|
||||
int fromX = move.getOldX();
|
||||
int fromY = move.getOldY();
|
||||
int toX = move.getNewX();
|
||||
int toY = move.getNewY();
|
||||
|
||||
Piece piece = board[fromX][fromY];
|
||||
if (piece == null) return;
|
||||
|
||||
// Capture any piece at destination
|
||||
board[toX][toY] = null;
|
||||
|
||||
// Move piece
|
||||
board[fromX][fromY] = null;
|
||||
board[toX][toY] = piece;
|
||||
piece.setPosition(toX, toY); // <-- make sure Piece has this method
|
||||
|
||||
// Update turn
|
||||
isTurnWhite = !isTurnWhite;
|
||||
turnNumber++;
|
||||
|
||||
// Clear selection/highlight
|
||||
chosenPiece = null;
|
||||
highlightedSquares.clear();
|
||||
//TODO
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue