private boolean checkDiagonal(){//for bishop and queen int x = king_x; int y = king_y; while(x<7 && y<7){//northEast x++; y++; Piece temp= board.getPiece(x, y); if(temp!=null){ if(temp.getColor()==color) return false; else if(temp instanceof Bishop||temp instanceof Queen){ return true; } } } while(x>0 && y>0){} ... } } X and y have not been initialized before the second while loop, which will result in getting the wrong position information of king.