This is for a Brute-Force Algorithm I'm trying. Trying every combination.
The code produces every combination of moves of length 10 from 4 moves(up, down, left, right). So that's why the nested for loops are 10 deep. But what if there are less or more moves required like 9 or 11 or 12. How can I make the nested for loop dynamic. I'm having trouble with recursion.
int available = new int[] {TILT_MOVE.UP, TILT_MOVE.DOWN, TILT_MOVE.LEFT, TILT_MOVE.RIGHT}.length;
int n = 10;
int total = 1;
for (int i = 0; i < n; i++) {
total *= available;
}
int combinations[][] = new int[total][n];
int count = 0;
//My head got burnt up with the implementation of maze tilting logic so this is the best I can do for now.
for (int a = 0; a < available; a++) {
for (int b = 0; b < available; b++) {
for (int c = 0; c < available; c++) {
for (int d = 0; d < available; d++) {
for (int e = 0; e < available; e++) {
for (int f = 0; f < available; f++) {
for (int g = 0; g < available; g++) {
for (int h = 0; h < available; h++) {
for (int i = 0; i < available; i++) {
for (int j = 0; j < available; j++) {
int[] moves = new int[n];
moves[0] = a;
moves[1] = b;
moves[2] = c;
moves[3] = d;
moves[4] = e;
moves[5] = f;
moves[6] = g;
moves[7] = h;
moves[8] = i;
moves[9] = j;
combinations[count++] = moves;
}
}
}
}
}
}
}
}
}
}
TILT_MOVE.UP, TILT_MOVE.DOWN, TILT_MOVE.LEFT, TILT_MOVE.RIGHT