Hallo,
folgendes ist ein Codestück aus meinem Programm:
Irgendwie funktioniert das Backtracking nicht. Es liefert auch eine true zurück, auch wenn step_count ungleich counter ist. Somit probiert es hier nicht alle Lösungen durch. Was habe ich falsch gemacht?
folgendes ist ein Codestück aus meinem Programm:
Java:
public static boolean springtour(int[][] sol, int i, int j, int step_count, int[] x_move, int[] y_move, boolean[][] board, int counter) {
if (step_count == counter)
return true;
for(int k=0; k<8; k++) {
int nextI = i+x_move[k];
int nextJ = j+y_move[k];
if (isValid(nextI, nextJ, sol, board)) {
sol[nextI][nextJ] = step_count;
realsol[nextI][nextJ] = step_count;
if (springtour(sol, nextI, nextJ, step_count+1, x_move, y_move,board, counter)) {
return true;
}
sol[nextI][nextJ] = 0;
realsol[nextI][nextJ] = 0;
}
}
return false;
}
Irgendwie funktioniert das Backtracking nicht. Es liefert auch eine true zurück, auch wenn step_count ungleich counter ist. Somit probiert es hier nicht alle Lösungen durch. Was habe ich falsch gemacht?