I am not sure about the fastest way but I used pre-defined bitboards with 1:s on the bishop and knight squares (and queen if castling queen side) respectively and AND those together with the all pieces bitboard (there can't be any oppoennt pieces on the squares either). If the resulting bitboard is empty and you have castling rights, then you are allowed to ...
Stockfish, at depth 20, evaluates Rfe1 with a score of -8.5, while cxd4 has one of -2.6. With so large a difference, the explanation is that
you were playing against a weak computer. There is usually
a gradient (e.g. from 1 to 10) of difficulty to choose from
when playing against a computer, so you have probably chosen something
far from 10. Chess.com (...
Yes, you can do this in the chess.com app (or at least you could in a previous version.)
Tap the "Computer" menu button.
When it shows the starting options, tap "Position". (This is the bottom option; you may need to scroll down to see it.)
It gives you a list of choices. Tap "Custom Setup".
You can now set up the position as ...
You can do this via Lichess:
Visit lichess and optionally create an account if you haven't done so.
Click Play with the computer.
Select "From Position" in the Variant field.
Insert the position FEN you want to play with the computer.
Choose a time control.
Choose the computer level. See this discussion for more info on what those mean.
Select a ...