Shop OBEX P1 Docs P2 Docs Learn Events
SX Sudoku? — Parallax Forums

SX Sudoku?

DuctapemasterDuctapemaster Posts: 90
edited 2007-12-23 20:05 in General Discussion
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

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-12-11 12:49
    There is a PIC version
    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
  • DuctapemasterDuctapemaster Posts: 90
    edited 2007-12-11 22:28
    I looked at the VB code for that and tried out the program, but it is basically the same thing as before. It just uses 6 patterns and rearranges the numbers. I may be trying to do something that isn't possible, but I want something that's not predictable.
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-12-13 20:42
    Why not add a real time clock chip in and randomize off that?· Pull the seconds off it and start with one of those number for the random number generator.
  • DuctapemasterDuctapemaster Posts: 90
    edited 2007-12-13 22:05
    I was planning on using the count in the RTCC register for the randomization, but the problem doesn't lie with finding random numbers. I would really like to have a puzzle that doesn't use the same pattern of blank spaces like most generators do. I may be asking for the impossible (at least with the processing power available) but I'll try.
  • bubbleheadbubblehead Posts: 36
    edited 2007-12-23 01:05
    I have a Python program around somewhere that generates random SuDoku puzzles.· Basically, it starts with a completely solved puzzle, randomly shuffles rows, columns, and blocks around in a way so that it remains a valid puzzle.· Then it randomly removes a bunch of·number pairs (i.e., two·numbers in symetrical positions in the grid).· I think is was about 30 pairs (60 numbers).
    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.
    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2007-12-23 20:05
    Generating pseudo-random numbers with the SX is not difficult. Here is a subroutine:

    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
Sign In or Register to comment.