Skip to content

Instantly share code, notes, and snippets.

@zacharycarter
Created December 24, 2016 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zacharycarter/7b3811dcc3d6ff4b46cd28e4af27f2c1 to your computer and use it in GitHub Desktop.
Save zacharycarter/7b3811dcc3d6ff4b46cd28e4af27f2c1 to your computer and use it in GitHub Desktop.
private Coord findLowerElevation(Coord currentLocation, GreasedRegion riverBlockages) {
GreasedRegion heights = new GreasedRegion(heightData.data, Sand, heightData.data[currentLocation.x][currentLocation.y]);
GreasedRegion nonBlockedHeights = heights.andNot(riverBlockages);
int searchDistance = 40;
int cx = currentLocation.x, cy = currentLocation.y;
int x = 0, y = 0;
for(int rx = -searchDistance/2; rx < searchDistance/2; rx++) {
for(int ry = -searchDistance/2; ry < searchDistance/2; ry++) {
int dx = cx + rx, dy = cy + ry;
if(!contains(dx, dy)) continue;
if(nonBlockedHeights.contains(dx,dy)) return Coord.get(dx,dy);
y++;
}
y = 0;
x++;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment