fixed and optimized castling check
implemented castling logic