Buggy code:
public boolean isBlackKnightMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isBlackCannibalKnightMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isWhiteQueenMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isWhiteCannibalQueenMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isBlackQueenMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isBlackCannibalQueenMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isWhiteKingMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isWhiteCannibalKingMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isBlackKingMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isBlackCannibalKingMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isWhiteMoveLegal ( int from , int to ) throws ChessboardException { } public boolean isBlackMoveLegal ( int from , int to ) throws ChessboardException { } private int constructMoveNumber ( int from , int to ) { } private static boolean isPositionLegal ( int position ) { } private static int getRankFromPosition ( int position ) { } private static int getFileFromPosition ( int position ) { } private boolean isPieceWhite ( int pieceNumber ) throws ChessboardException { } private boolean isPieceBlack ( int pieceNumber ) throws ChessboardException { } private void constructPiecePositionFromBoard ( ) { } public int distanceBewteenKings ( ) { } public boolean willBlackKingBeInOppositionIfItMovesTo ( int position ) { } public boolean isPositionUnderAttackByBlack ( int position , boolean ignoreBlackKing ) throws ChessboardException { } public boolean isPositionUnderAttackByWhite ( int position , boolean ignoreWhiteKing ) throws ChessboardException { } public boolean isPositionAdjacentToWhiteKing ( int position ) { } public boolean isPositionAdjacentToBlackKing ( int position ) { } public boolean isPositionProtectedByKingIfKingIsMovedTo ( int position , int kingPos ) { } public ArrayList < Move > movesWhereBlackKingEatsWhite ( ) throws ChessboardException { } public ArrayList < Move > movesWhereBlackKingEvadesOposition ( ArrayList < Move > blackKingPossibleMoves ) throws ChessboardException { } public ArrayList < Move > movesWhereBlackKingTriesToEatRook ( ArrayList < Move > possibleBlakKingMoves ) { } public ArrayList < Move > movesWhereWhiteIsntNearBlackKing ( ArrayList < Move > moves ) throws ChessboardException { } public ArrayList < Move > movesWhereWhiteRooksArentPlaceOnSameLine ( ArrayList < Move > possibleRookMoves ) throws ChessboardException { } public ArrayList < Move > movesWherePieceIsNotInCorner ( ArrayList < Move > moves ) { } public ArrayList < Move > movesWhereWhiteRookTryToStayOnNearestLines ( ArrayList < Move > possibleRookMoves ) throws ChessboardException { } public ArrayList < Move > movesWhereWhiteAvoidBeingEatenByBlackKing ( ArrayList < Move > moves ) { } public ArrayList < Move > movesWhereWhiteKingMovesCloserToBlackKind ( ArrayList < Move > posKingMoves ) { } public ArrayList < Move > movesWhereWhiteKingMovesCloserOrEqualToBlackKind ( ArrayList < Move > posMoves ) { } public ArrayList < Move > movesWhereWhiteRookLikePieceBoundsBlackKing ( ArrayList < Move > posQueenMoves ) { } public ArrayList < Move > movesWhereWhiteKQKIsSafe ( ArrayList < Move > moves ) throws ChessboardException { } public ArrayList < Move > movesWhereWhiteOnePieceEndingIsSafe ( ArrayList < Move > moves ) { } public ArrayList < Move > whiteUrgentMoves ( ArrayList < Move > allWhiteMoves ) { } public ArrayList < Move > whiteSafeMoves ( ArrayList < Move > allWhiteMoves ) { } public ArrayList < Move > KRKWhiteMovesWhereRookChecksIfKingsAreInOpposition ( ArrayList < Move > allWhiteMoves ) { ArrayList < Move > rez = new ArrayList < Move > ( ) ; int blackKingPos = this . piecePosition [ 28 ] ; int rookPos = this . piecePosition [ 0 ] ; if ( rookPos == ( - 1 ) ) { rookPos = this . piecePosition [ 7 ] ; } if ( this . willBlackKingBeInOppositionIfItMovesTo ( blackKingPos ) ) { int blackKingRank = Utils . getRankFromPosition ( blackKingPos ) ; int blackKingFile = Utils . getFileFromPosition ( blackKingPos ) ; for ( Move currMove : allWhiteMoves ) { int movedPiece = Utils . getMovedPieceFromMoveNumber ( currMove . moveNumber ) ; int to = Utils . getToFromMoveNumber ( currMove . moveNumber ) ; if ( ( movedPiece == 0 ) || ( movedPiece == 7 ) ) { int rank = Utils . getRankFromPosition ( to ) ; int file = Utils . getFileFromPosition ( to ) ; int from = Utils . getFromFromMoveNumber ( currMove . moveNumber ) ; boolean sameRank = rank == blackKingRank ; boolean sameFile = file == blackKingFile ; <START_BUG> if ( ( sameFile || sameRank ) && ( ! ( ChessboardUtils . isPositionBetweenPositionsOnLine ( this . piecePosition [ 4 ] , blackKingPos , from ) ) ) ) { <END_BUG> rez . add ( new Move ( currMove . moveNumber ) ) ; } } else { int whiteKingPos = this . piecePosition [ 4 ] ; int whiteKingFile = Utils . getFileFromPosition ( whiteKingPos ) ; int whiteKingRank = Utils . getRankFromPosition ( whiteKingPos ) ; int rookRank = Utils . getRankFromPosition ( rookPos ) ; int rookFile = Utils . getFileFromPosition ( rookPos ) ; boolean areRanksSame = ( whiteKingRank == blackKingRank ) && ( whiteKingRank == rookRank ) ; boolean areFilesSame = ( whiteKingFile == blackKingFile ) && ( whiteKingFile == rookFile ) ; if ( areRanksSame ) { int rank = Utils . getRankFromPosition ( to ) ; if ( rank != whiteKingRank ) { rez . add ( new Move ( currMove . moveNumber ) ) ; } } if ( areFilesSame ) { int file = Utils . getFileFromPosition ( to ) ; if ( file != whiteKingFile ) { rez . add ( new Move ( currMove . moveNumber ) ) ; } } } } } else { return allWhiteMoves ; } return rez ; } public ArrayList < Move > KBBKWhiteUrgentMoves ( ArrayList < Move > allWhiteMoves ) { } public ArrayList < Move > KBBKWhiteSafeMoves ( ArrayList < Move > allWhiteMoves ) { } public ArrayList < Move > KBBKWhiteMovesWhereBishopsAreOnAdjacentDiagonals ( ArrayList < Move > allWhiteMoves ) { }

Fix:
if ( ( sameFile || sameRank ) && ( ! ( ChessboardUtils . isPositionBetweenPositionsOnLine ( this . piecePosition [ 4 ] , blackKingPos , to ) ) ) ) {