#I made a recusive function,Help xD
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
i can't help but notice you did not ask a question
Im trying to count every time the Method set a value in the Sudoku game, but thank you
the variables and functions are not even named in English
public RandomSudoku(SudokuLoader sudokuLoader) {
super(sudokuLoader);
}
/**
- A method that randomly solves the Sudoku
*/
@Override
public void solve() {
int i = 0;
int j = 0;
int n = 5;
int indexCounter = 5;
this.sudokuState = SudokuState.SOLVING_ATTEMPT;
System.out.println("\nStatus: " + sudokuState + "...\n");
recursivelySolve(i, j, indexCounter, n);
}
/**
- Recursive method that fills the Sudoku with random values
- @param i = row
- @param j = column
- @param indexCounter = counts the attempts
- @param n = number of attempts
*/
public void recursivelySolve(int i, int j, int indexCounter, int n) {
int steps = 0;
// System.out.println("Coordinate:"+ "[" + i + "]" + "[" + i + "]");
// Base case: Sudoku has been solved
if (isSolved()) {
return;
} else { // not solved
if ((this.getRows()[i].getField(j).getValue() != 0)) {
recursivelySolve(new Random().nextInt(9), new Random().nextInt(9), indexCounter, n);
} else { // no value in the box
int value = new Random().nextInt(9) + 1;
//System.out.println("inserted value" + "[" + value + "]");
if (!this.getRows()[i].contains(value) && !this.getColumns()[j].contains(value) && !this.getQuadrants()[((i / 3) * 3) + (j / 3)].contains(value)) {
this.getRows()[i].getField(j).setFixedValues(value);
recursivelySolve(new Random().nextInt(9), new Random().nextInt(9), n, n);
} else {
if (indexCounter == 0) {
return;
}
recursivelySolve(i, j, indexCounter - 1, n);
}
}
}
}
@analog valley here u go