Last active
December 17, 2015 18:49
-
-
Save fbrubacher/5655491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LENGTH = inputParam - 1; | |
List<Set<Basin>> myBasinSets = new List<HashSet<Basin>>(); | |
Basin[][] basins = new Basin[LENGHT][LENGHT] | |
for (int i = 0; i < LENGTH; i++) { | |
for (int j = 0; j < LENGTH; j++) { | |
Basin currentBasin = basins[i][j]; | |
if(isSink(currentBasin)) { | |
HashSet currentBasinTree = new HashSet<Basin>(); | |
currentBasinTree.add(currentBasin) | |
checkAdjacentBasins(currentBasin, currentBasinTree); | |
myBasinSet.add(currentBasinTree); | |
} | |
} | |
} | |
public checkAdjacentBasins(Basin intialBasin, HashSet<Basin> currentBasinTree) { | |
if(intialBasin.x+1 < LENGTH-1 ) { | |
downBasin = initialBasin.getDownBasin(); | |
if(currentBasinTree.get(downBasin) == null) { | |
// We haven't checked this direction yet | |
boolean treeContinues = checkAdjacentBasin(initialBasin, downBasin, currentBasinTree); | |
if(treeContinues) { | |
currentBasinTree.add(downBasin); | |
checkAdjacentBasins(downBasin, currentBasinTree); | |
} | |
} | |
} | |
// repeat for all four directiosn | |
} | |
public Basin checkAdjacentBasin(Basin initialBasin, Basin trialBasin, HashSet<Basin> basinTree) { | |
int needsToBeTheLowest = deltaValue(initalBasin, trialBasin); | |
if(needsToBeTheLowest <= deltaValue(trialBasin, trialBasin.getDownBasin()) && | |
needsToBeTheLowest <= deltaValue(trialBasin, trialBasin.getUpBasin()) && | |
needsToBeTheLowest <= deltaValue(trialBasin, trialBasin.getRightBasin()) && | |
needsToBeTheLowest <= deltaValue(trialBasin, trialBasin.getLeftBasin())) { | |
return true; | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment