Chess board

Given Chess board, Piece and Spot class, develop functions to check the possible moves of Khight, Bishop and Pawn

class Spot {
Piece piece, int x, int y
}

class Piece {
boolean killed;
boolean isWhite;
}

class Board {

}
// for Knight

public boolean canMove(Board board, Spot start, Spot end) {
// we can't move the piece to a spot that has
// a piece of the same colour
if (end.getPiece().isWhite() == this.isWhite()) {
return false;
}

int x = Math.abs(start.getX() - end.getX());
int y = Math.abs(start.getY() - end.getY());
return x * y == 2;

}

Coudn't comeup for Pawn. Thought it would be helpful to share.

Comments (0)