SX Sudoku?
I came up with this idea yesterday...I want to build a sudoku game using the SX (or SX's). I plan on displaying all of the numbers on 7 segment displays arranged in a 9x9 pattern. I would use a SX48 to multiplex the displays (already have a good multiplexing scheme planned) and probably another SX(28?) for a game timer, generator, and LCD output. I really need help on the generation part though. I have been looking around for a sudoku generator in some form of BASIC, so I can transfer it to SX/B. Does anyone know of such things? The only ones I could find are coded for TI calculators. I am an experienced coder in TI BASIC (calculator programming language) and I could easily convert one of those programs to SX/B, but they don't really generate random puzzles. They all start with a base puzzle hard coded into the program and mix it up. I really want something more random than that.
Can anyone help me?
-Dan
Can anyone help me?
-Dan
Comments
http://homepages.nildram.co.uk/~starbug/files/pic_sudoku.zip
You can convert the pic asm to sasm (sx assembly):
http://www.sxlist.com/cgi-bin/mpasm2sasm2.exe
regards peter
Then the program tried to solve the puzzle.· If the puzzle was solvable with the given clues, the program would randomly remove another pair of clues and try to solve the puzzle again.· This would repeat until the puzzle couldn't be solved.· The last numbers deleted, would be added back to the grid and the puzzle printed out.
I suspect an SX would not have enough horsepower or resources.· That is probably why the PIC version shuffles around a known puzzle.
You can easily store a puzzle in 81 bytes of memory, 41 bytes if you store each grid square in a nibble.· So you could fit a lot of prebuilt puzzles in a serial·eeprom.· Have the SX randomly select a puzzle from the eeprom·and then randomly shuffle the puzzle as in the PIC program.
·
Randomize
mov w, Random+0
xor w, Random+1
snb wreg.1
not w
rl wreg
rl Random+0
rl Random+1
ret
This routine makes use of two registers at Random+0 and Random+1. At startup of your program, clear Random+1, and store 1 into Random+0. Also make sure that bit 7 in the OPTION register is cleared, so that the W register is mapped into address 01. Otherwise, the snb wreg.1 would not work correctly.
The trick now is to seed this random generator first. It is most likely that after startup your program enters into a loop, waiting for some user input. Call Randomize from within this loop frequently. As the time-interval between startup and the first user-entry is pretty random, this nicely seeds your randomizer. Whenever you need a random number in your program later, call Randomize before reading any of the two Random values.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G