def move_unit(caves, units, position, next_position):
    """Move unit from position to next_position."""
    row, col = position
    next_row, next_col = next_position
    caves[row][col], caves[next_row][next_col] = (
        caves[next_row][next_col], caves[row][col])
    units.remove((row, col))
    units.add((next_row, next_col))
    return units