July 20, 2018

Elevation VI: I Want to Be Free

Problems I can't solve tend to nag at me. Like the basin erosion. But I was reminded of a comment by Alex Schroeder a few months ago about how he lets water carve its own path out of a basin.

So I did that. It was a bit more complicated than I thought at first, since the code kept getting caught in loops. Initially, I was picking the lowest neighbors, but that was a mistake. Two hexes side by side could be each other's lowest neighbor, and they would simply trade blows until they both zeroed out. So instead, I just choose a hex randomly. This helped, at first. But I realized that the problem was that a hex is only aware of its immediate neighbors.

(I have yet to address the other part of the comment, about raising the water level until the water carves the canyon itself. My initial thought on this is to use some form of Djikstra's Algorithm to find the least-cost path to an exorheic basin, but that might clog the code even further. This generation is no joke to my poor system.)

The solution might lie in something like this, where basins are filled up working backwards from the ocean. Right now, my algorithm works by the drop model, where I start from the highest point and propagate drainage values downward. By working backwards, though, a hex always know if it ultimately drains into the sea.

This wouldn't be that hard to do. I already save the drainage directions, both in and out, for each hex. So all I have to do is follow the trail down and find out if the terminal hex is coastal or not. Still, that increases the complexity of the original algorithm. And once I know if it's part of a basin, then what?

Right now, I'm testing the following algorithm on each endorheic hex:

  1. Find all hexes that drain into this one.
  2. Find the lowest source hex such that at least one of its neighbors is not part of this basin (so it drains elsewhere).
  3. Get the lowest valid neighbor of the source hex.
  4. Follow its drainage trail until a hex is encountered that is lower than the original endorheic hex, with the added stipulation that it must be at least $\partial h$ feet lower, where $\partial h$ is the number of hexes between the two so far. So if there are 4 hexes between the endorheic hex and the river source, and 6 hexes between the source and the new low, then $\partial h = 10$.
  5. Adjust the altitude along the new path so that there is a constant slope from the endorheic hex to the new low hex.
Once this is completed for all endorheics, the new drainage network can be found and checked to see if we've hit our target number. If not, repeat. There are still a couple of edge cases to handle: if it hits another basin, if it hits a flat area, etc. The biggest problem with this is that it's very very slow. I loathe to even estimate the Big O complexity.

Fairly good

Not so good


That being said, a good solution is desirable regardless of time. So I may just have to deal with it. I don't have to run it every single iteration of the erosion mountain growth. That will require some more experimentation. In additional, I'll run erosion after it as well, so the spidery lines above might get washed out.

No comments:

Post a Comment