Author |
Topic: SuDoku setup (Read 2087 times) |
|
chrispc
New Member
member is offline


Posts: 19
|
 |
SuDoku setup
« Thread started on: Jan 21st, 2014, 08:59am » |
|
Apologies first for this long question: I am trying to write a SoDoku program. I started with a program for inputting the data provided in the problem. First the X,Y for the box, then N for the number given (I inputted this as N(L), L from1 to 9 to fill all the 9 spaces that I intended giving to every box, especially those so far undecided, which would start with all the numbers 1-9 (before being eliminated one-by-one during the game). So I set up an array called Box having the variables X,Y, N. I understood that I would need the box identified by the X,Y, grid, but made what now seems to me a mistake of thinking I could keep only 9 places for the numbers as follows: DIM Box(9,9,9), as if I could call up a box and then look in it to see what numbers it contained, and maybe delete some. Now, after writing pages of code, suddenly it occurs to me that I will need to identify the numbers by the box as well. Therefore something like Box(X,Y, N(X,Y) ). Unless I do this it seems to me that Box(X,Y,N) will not identify WHICH N (i.e. the N in which box) is being sought or referred to. I hope this makes sense. Am I right in thinking I will have to use Box(X,Y, N(X,Y)) , or even Box(X,Y,N(X,Y,L) ) ? Therefore DIM Box(9,9,N(9,9,9) ). Will I really need to reserve all that space? And is that the right way to DIMension it? (Thanks for your previous help on REPEAT loops). chrispc
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: SuDoku setup
« Reply #1 on: Jan 21st, 2014, 12:05pm » |
|
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.
|
|
Logged
|
|
|
|
jalih
New Member
member is offline


Gender: 
Posts: 1
|
 |
Re: SuDoku setup
« Reply #2 on: Apr 16th, 2014, 09:18am » |
|
on Jan 21st, 2014, 12:05pm, admin wrote: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. |
|
That was helpful! I used it as a learning and testing tool for writing my Sudoku solver in PL/I.
I am still having trouble while reading BBC BASIC syntax, but luckily there are few holiday days coming. I will first try to port some simple games like MineSweeper for BBC BASIC for Windows.
|
|
Logged
|
|
|
|
|