The king rook switch in chess is called: castling. You can castle short or you can castle long.
Before you can castle certain conditions have to be met:
King Rook Switch Rules
When can you switch a king and rook?
1. There should be no pieces between the king and the rook. If you want to castle short (castling king side) this means you have to move the knight and the bishop first.
If you want to castle long (castling queen side) you have to move the knight, bishop and the queen first, before you are allowed to castle.
2. You are not allowed to castle if the king or the rook have been moved before in the game.
3. You are not allowed to castle away from a check or a checkmate.
4. You are not allowed to castle over an attacked square.
White moves – Short Castling
White can castle short now. He moves his king two squares to the right and places the rook beside the king on the other side.
White castles long – Queen Side Castling
White moves the King two squares to the left and places the rook beside the king on the other side. The king does NOT cross the attacked square at b1, (b1 is attacked by the black rook) so the castling is legal.
White is not allowed to castle because the square g1 is attacked by the black bishop.
White is not allowed to castle long because the king is in check.