hi Raed,
well, it is not an easy task, filling a complete sudoku. But, as I said,
a task that will give you quite some interesting things to experiment
with.
Okay, some words about how I did it.
First of all, my program simply solves sudoku's. I 'borrowed' the
Google Sudoku layout, and after the user had set up a sudoku, then,
as soon as the user pressed 'finished set up', I start a
Thread
with an arraylist of empty cells. I use a dedicated class for a cell.
Now, I just go from element 0 to element last, filling in possible
digits, until I reach a point where a cell cannot be filled for lack
of digits, or otherwise I'm done.
For the administration, I use arrays of size 9, three of 'm,
one for the nine columns, one for the nine rows and one for the nine
squares. The elements of these three arrays are, as I said earlier,
BitSets. I use BitSets of length 10, bit 0 is unused, I only
use the bits 1-9.
Now, suppose I have an empty cell. From instance members I know
the row R, column C and square S.
The BitSets for row R, column C and square S are br[R], bc[C] and
bs[S]. Now, a 1 in a BitSet, on position p, means that digit p is
still possible. A 0 means that digit p is not possible.
Now, what would I get if I do;
What about: possible.nextSetBit(0)? And what would it mean
if: possible.cardinality() == 0? And if I set the value of the cell
to digit D, what does that mean for the row, column and square
BitSets in question?
Well, all the above can be done with ArrayLists, Sets and the like.
But I found the use of BitSets to be ideal for this.
Hope I gave you some ideas, Think about it.
Greetz,
Piet