def find_lowest_point(height_map, start_x, start_y):
queue = [(start_x, start_y)]
min_height = float('inf')
while queue:
x, y = queue.pop(0)
current_height = height_map[x][y]
# Update the minimum height if the current point is lower
if current_height < min_height:
min_height = current_height
# Add neighboring points to the queue
neighbors = get_valid_neighbors(height_map, x, y)
for neighbor_x, neighbor_y in neighbors:
queue.append((neighbor_x, neighbor_y))
return min_height
def get_valid_neighbors(height_map, x, y):
# Returns a list of neighboring points that are within the height map bounds
neighbors = []
# Check up, down, left, and right neighbors
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
neighbor_x = x + dx
neighbor_y = y + dy
if 0 <= neighbor_x < len(height_map) and 0 <= neighbor_y < len(height_map[0]):
neighbors.append((neighbor_x, neighbor_y))
return neighbors