public class Queen extends Piece { public Queen(Cell cell, PieceColor pieceColor) { super(cell, pieceColor) ; } @Override public boolean isValidMove(Cell c, Cell board[][], Piece pw[], Piece pb[]) { if (super.isDeleted()) return false ; int sw=0 ; if (super.getPieceColor() == PieceColor.BLACK) { for (Piece p:pw) { if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()) sw=1 ; } } else { for (Piece p:pb) { if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()) sw=1 ; } } if ( ( (this.getCell().getCol() == c.getCol()) || (this.getCell().getRow() == c.getRow() ) || ( Math.abs(this.getCell().getCol()-c.getCol()) == Math.abs(this.getCell().getRow()-c.getRow())) ) && (c.isEmpty() || (!c.isEmpty() && sw==1)) ) { if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() < c.getRow()) { for (int i=-1 ; i>-8 ; --i) { if (!board[this.getCell().getRow()-i][this.getCell().getCol()-i].isEmpty()) return false; if (this.getCell().getRow()-i == c.getRow()) break ; } } if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() > c.getRow()) { for (int i=-1 ; i>-8 ; --i) { if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) { //System.out.println("294 294") ; return false ; } if (this.getCell().getRow()+i == c.getRow()) break ; } } if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() < c.getRow()) { for (int i=1 ; i<8 ; ++i) { if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) return false; if (this.getCell().getCol()-i == c.getCol()) break ; } } if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() > c.getRow()) { for (int i=-1 ; i>-8 ; --i) { if (!board[this.getCell().getRow()+i][this.getCell().getCol()+i].isEmpty()) return false; if (this.getCell().getCol()+i == c.getCol()) break ; } } if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() < c.getRow()) { for (int i=1 ; i<8 ; ++i) { if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) return false; if (this.getCell().getRow()+i == c.getRow()) break ; } } if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() > c.getRow()) { for (int i=-1 ; i>-8 ; --i) { if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) { //System.out.println("294 294") ; return false; } if (this.getCell().getRow()+i == c.getRow()) break ; } } if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() == c.getRow()) { for (int i=1 ; i<8 ; ++i) { if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false; if (this.getCell().getCol()+i == c.getCol()) break ; } } if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() == c.getRow()) { for (int i=-1 ; i>-8 ; --i) { if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false; if (this.getCell().getCol()+i == c.getCol()) break ; } } return true ; } else return false ; } }