A more complete castling function