public boolean isValidMove(int move, boolean isInCheck) {

        int type = Move.getType(move);
        int indexTo = Move.getTo(move);
        int indexFrom = Move.getFrom(move);
        int indexKing = king.get(sideToMove, 0);
        int piece = Square.getPiece(squares[indexFrom]);
        int inc = Increment.getIncrement(indexKing - indexFrom);

        assert Move.isOk(move);
        assert indexFrom != Move.getTo(move) : "to != from!";

        // We need to handle king moves, ep-captures and checks specifically:
        if (piece == KING || type == Move.MOVE_EP_CAPTURE || isInCheck) {
            make(move);
            boolean checked = isAttacked(king.get(oppColor(sideToMove), 0), sideToMove);
            retract(move);
            return (!checked);
        }

        if (inc == 0) {
            // No relation between the from and the king square!
            return true;
        }
        if (inc == Increment.getIncrement(indexKing - indexTo)) {
            // The piece moved within it's line - this could not have led to a invalid move.
            return true;
        }

        int target;

        for (target = indexKing + inc; Square.isEmpty(squares[target]); target += inc) ;
        if (target != indexFrom) {
            // There is a piece in the way between the king and the from square = valid move.
            return true;
        }

        for (target += inc; Square.isEmpty(squares[target]); target += inc) ;
        if (Square.isOfColor(squares[target], sideToMove)) {
            // A side-to-move piece was found - valid move!
            return true;
        }

        int attackPiece = Square.getPiece(squares[target]);
        return Increment.getPieceIncrement(attackPiece, indexKing - target) == 0;
    }