View previous topic :: View next topic |
Author |
Message |
| ukelebear
| Joined: 09 Dec 2008 | Posts: 3 | : | | Items |
|
Posted: Tue Dec 09, 2008 11:05 pm Post subject: Help on populating grid |
|
|
Hi there, 1st post. I've been given the task to create a sudoku game/solver.
I have been able to print out a grid from a string and now i have started to generate my own grid. At the moment I can only populate the grid with one number can someone help? I know this may sound a bit basic but my programming skills are the bees knees.
Here's the code where the String is converted
Code: |
public void initializeFromString(final String boardStr) {
clear(); // Clear all values from the board.
//int full =81; // parameter used
row = 0;
col = 0;
for (int i = 0; i <boardStr>= '1' && c <='9') {
if (row > 9 || col > 9) {
throw new IllegalArgumentException("SudokuModel: "
+ " Attempt to initialize outside 1-9 "
+ " at row " + (row+1) + " and col " + (col+1));
}
_board[row][col] = c - '0'; // Translate digit to int.
col++;
}
else if (c == '.')
{
setVal(row,col,rand);
col++;
}
else if (c == '/') {
row++;
col = 0;
}
else if (c == ','){
col++;
}
else
{
throw new IllegalArgumentException("SudokuModel: Character '" + c
+ "' not allowed in board specification");
}
}
}
|
I use a random to be generated but i want to know the best method on how to change the value on each pass. Any help greatly appreciated |
|
Back to top |
|
|
| ukelebear
| Joined: 09 Dec 2008 | Posts: 3 | : | | Items |
|
Posted: Tue Dec 09, 2008 11:12 pm Post subject: |
|
|
Its ok I have sorted it out now.
In the outest loop of the for loop I have simply put the code:
rand = generator.nextInt(9) + 1;
so it randomly generates a new number on each pass |
|
Back to top |
|
|
| Lunatic
| Joined: 11 Mar 2007 | Posts: 166 | : | Location: Ghent - Belgium | Items |
|
|
Back to top |
|
|
|