Hello, there are a few things that I do not understand between your gh script and your description.
1. You say that you want to find the shortest point between the lowest and highest point on your terrain. I would guess you would find the lowest and highest points on your terrain and make them fixed start and end points, thereafter you can vary the path connecting the two? Yet on your script the start and end points shift along each of the short edges of the terrain, so what the script calculates is the shortest distance to cross between the two opposite short edges, if I am not mistaken.
2. The second is a point of clarification. You say you do not want the path to cross any slopes steeper than 10 degrees. If I take it literally, we subdivide the terrain into patches, and we do not want the path to cross into any patch where the terrain slope is greater than 10 degrees. Or actually, it is the path that should never go steeper than 10 degrees? The difference is we can move sideways on a slope steeper than 10 degrees (along the contour instead of across the contour), such that the curve itself does not go steeper than 10 degrees.
I think those clarifications will affect how the script should work, so I did not attempt to do anything on it, yet.
However, my thoughts on the general approach to your task is:
1. We want to get a minimum value as our target
2. Primarily we get it from the total path length (let’s say our range of values are in the hundreds for example).
3. We want to factor in the slope
4. (Depending on what you say you intend to do), we split the path into segments (smaller segments = more accuracy). And for each segment we measure its slope.
5. Any slope less than 10 degrees we assign it a value of zero, anything greater than 10 we assign it a ridiculously high value compared to possible lengths (say a thousand).
6. For each path iteration, we add (the path length) and (the sum of all segment slope penalties). This result will be our fitness.
7. The effect is that any slope greater than 10 will push the fitness beyond even the largest values for path length alone, making them poor choices for our goal.