Last active
December 19, 2015 20:19
-
-
Save ft975/6012616 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
/** | |
* It goes to touching block. If the cond function returns true on that block, | |
* it goes on and operates on the values of that block using the op function. | |
* It then executes itself with that block as the base. | |
* To make a generic TreeCapitator, cond should be | |
* <code>return wrd.getBlockId(x, y, z) == Block.wood.blockID || wrd.getBlockId(x, y, z) == Block.leaves.blockID</code> | |
* op should be | |
* <code>wrd.destroyBlock(x, y, z, true)</code> | |
* | |
* For more information see the wikipedia page on recursion, especially Multiple Recursion | |
*/ | |
public void iterateTouching(int x, int y, int z, World wrd) { | |
if (cond(x + 1, y, z,world)) { | |
op(x + 1, y, z,world) | |
iterateTouching(x + 1, y, z,world) | |
} | |
if (cond(x - 1, y, z,world)) { | |
op(x - 1, y, z,world) | |
iterateTouching(x - 1, y, z,world) | |
} | |
if (cond(x, y + 1, z,world)) { | |
op(x, y + 1, z,world) | |
iterateTouching(x, y + 1, z,world) | |
} | |
if (cond(x, y - 1, z,world)) { | |
op(x, y - 1, z,world) | |
iterateTouching(x, y - 1, z,world) | |
} | |
if (cond(x, y, z + 1,world)) { | |
op(x, y, z + 1,world) | |
iterateTouching(x, y, z + 1, world) | |
} | |
if (cond(x, y, z - 1,world)) { | |
op(x, y, z - 1,world) | |
iterateTouching(x, y, z - 1, world) | |
} | |
} | |
private boolean cond(int x,int y,int z,World world){...} | |
private void op(int x, int y, int z, World world){...} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment