I'm a newbie to java programming and created a console-based Sudoku Game as practice. A backtracking algorithm generates a completed Sudoku and another method 'digs holes' into random cells (regarding the difficulty). Right now, the value 0 is set for blank cells but I don't like the way the Sudoku looks..its just too many numbers in the board and I think whitespace would be a good alternative. The player should then still be able to replace (now '0', later whitespace) in the cells with his own guess. Is there a way to replace the int value when it is 0? The algorithm and digHole method both use a setValue method on a 2D array (coordinates).
Thanks for any help!
Here's my board drawing:
public static void drawBoard() {
String[] abc = { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
// i := rows
for (int i = 0; i <= 8; i++) {
// first row
if (i == 0) {
System.out.println("");
// coordinates 1-9
System.out.println(" 1 2 3 4 5 6 7 8 9\n" + " _____________________________________ \n"
+ " | |");
}
// j := columns in row i
for (int j = 0; j <= 8; j++) {
if (j == 0) {
// coordinates A-I and first column
System.out.print(" " + abc[i] + " | " + sudokuCells[i][j].getValue() + " ");
} else if (j == 8) {
// last cell in current row
System.out.print(" " + sudokuCells[i][j].getValue() + " |");
System.out.println("");
} else if (j == 2 || j == 5) {
//frame
System.out.print(" " + sudokuCells[i][j].getValue() + " |");
} else {
//whitespace as seperation
System.out.print(" " + sudokuCells[i][j].getValue() + " ");
}
}
// last row with frame
if (i == 8) {
System.out.println(" |_____________________________________|");
System.out.println();
}