Last active
December 18, 2015 18:39
-
-
Save zidarsk8/5827509 to your computer and use it in GitHub Desktop.
test
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
package test; | |
public class Test { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
} | |
private int[] directions = { -1, 0, 1 }; | |
public int[][] test(int[][][] field, int x, int y, int z, int n) { | |
int[][] windir = new int[n][3]; | |
windir[0] = new int[] { x, y, z }; | |
// [dx, dy, dz] is a direction vector in which we check for n matching | |
// blocks | |
for (int dx : directions) { | |
for (int dy : directions) { | |
for (int dz : directions) { | |
// direction vector must be non zero otherwise all n blocks | |
// will match | |
if (dx != 0 || dy != 0 || dz != 0) { | |
int i = 0; | |
while (field[x + i * dx][y + i * dy][z + i * dz] == field[x][y][z]) { | |
i++; | |
windir[i] = new int[] { x + i * dx, y + i * dy, z + i * dz }; | |
} | |
int j = 1; | |
while (field[x - j * dx][y - j * dy][z - j * dz] == field[x][y][z]) { | |
j++; | |
windir[i+j-1] = new int[] { x - j * dx, y - j * dy, z - j * dz }; | |
} | |
// upon success return coordinates of the points in the | |
// line | |
// otherwise we will look into another direction | |
if (i+j > n) | |
return windir; | |
} | |
} | |
} | |
} | |
// we didn't find a set of n matching block in any direction | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment