To castle, move the king two squares to the right for kingside castling and 2 squares to the left for queenside castling.
Castling is allowed under the following conditions:
- all the squares between the king and the rook must be empty
- neither the king nor the rook should have left their original position.
- none of the three squares (starting square, passing squares, final square) should be controlled by an opponent's piece. (The rook then does not allow avoiding a failure)