on Jan 21st, 2014, 08:59am, chrispc wrote:| I am trying to write a SoDoku program. |
|
I presume you are aware that SUDOKU.BBC is supplied with BB4W as one of the example programs (in the EXAMPLES\GAMES folder) and an expanded version of the program is available on the website.
Quote:| Will I really need to reserve all that space? And is that the right way to DIMension it? |
|
I don't really follow your arguments; I fear there is some muddled thinking there. SUDOKU.BBC uses a simple array A%(8,8) to represent the current state of the game. Each array element corresponds to one 'cell', and contains a bit-map in which bits 0 to 8 represent the digits 1 to 9 respectively.
The array is initialised to contain the value %111111111, meaning that every cell is as yet 'undecided', in other words all digits 1-9 are a possibility. As digits are eliminated the corresponding bit is zeroed, so for example if you know that a particular cell cannot contain a 3 or a 7 the value stored in the corresponding array element will be %110111011.
The puzzle is solved when every element of the array contains a value which has just one bit set. There's a neat trick you can use to test a binary value for this condition:
Code: IF (num% AND (num%-1)) = 0 THEN just_one_bit_set = TRUE
Richard.