Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean isMoveValid(int fromRow, int fromColumn,
- int toRow, int toColumn) {
- //out of bounds
- if (fromRow < 0 || fromRow > 7 || fromColumn < 0 || fromColumn > 7 ||
- toRow < 0 || toRow > 7 || toColumn < 0 || toColumn > 7)
- return false;
- //if piece you want to move is not there or you are grabbing and moving to the same color piece
- if (getPieceAt(fromRow, fromColumn) == PieceType.NONE ||
- getPieceAt(fromRow, fromColumn) == getPieceAt(toRow, toColumn))
- return false;
- if (getPlayerInTurn() == PlayerType.WHITE) {
- if ((fromRow - 1 == toRow && fromColumn + 0 == toColumn) ||
- (fromRow - 1 == toRow && fromColumn - 1 == toColumn) ||
- (fromRow - 1 == toRow && fromColumn + 1 == toColumn) ||
- (fromRow + 1 != toRow)) {
- if (getPieceAt(toRow, toColumn) == PieceType.BLACK ||
- getPieceAt(toRow, toColumn) == PieceType.NONE)
- return true;
- else return false;
- } else return false;
- } else if (getPlayerInTurn() == PlayerType.BLACK) {
- if ((fromRow + 1 == toRow && fromColumn + 0 == toColumn) ||
- (fromRow + 1 == toRow && fromColumn + 1 == toColumn) ||
- (fromRow + 1 == toRow && fromColumn - 1 == toColumn)) {
- if (getPieceAt(toRow, toColumn) == PieceType.WHITE ||
- getPieceAt(toRow, toColumn) == PieceType.NONE)
- return true;
- else return false;
- } else return false;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement