def get_coordinate(coordinate, change, limit):
    """Get next coordinate, within 0 and limit."""
    next_coordinate = coordinate + change
    if next_coordinate < 0:
        return 0
    elif next_coordinate >= limit:
        return limit - 1
    return next_coordinate