Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Yabasic => Topic started by: daantje on December 18, 2011
-
I started making a program which should randomly creating sudokus but as you might know, there's the chance that in a certain square no number can be placed, because the last number that would fit in the series does not fit in the column, so the program will keep creating random numbers infinitely.
I made a goto which sends the program back to the beginning as to start over, but ofcourse all the variables already have numbers , is there anyway to reset all variables to 0 without having to manually type it? And without having to exit the program and start over? a function maybe?
thanks already
daan
-
When I just got into programming I made an attempt at a sudoku generator, but got scared after reading an interesting article explaining the mathematical difficulties surounding sudokus.
This may be of use: http://en.wikipedia.org/wiki/Mathematics_of_Sudoku
Can't help with your actual question though, sorry.
-
Hi daantje,
there really isn't any way to do that in yabasic (or any other language I know). You need to structure your program in such a way as it resets the variables before each time you try to generate the sodoku.
Jim
-
Hi!
I wroted a sudoku demo time ago and didn't have any problems.
The sudoku creator works 100% accuracy by placing random numbers and cheking if each number is under the rules.
The secuence to create sudokus is this:
Create a MATRIX 9x9. This will be the main board. In the main board you can store some FIXED numbers that will be the clue for doing the sudoku.
Place a temporally random number in the 9x9 main board in an empty cell.
Chek the rules of the sudoku with the new temporally number comparing with all the previous numbers in the matrix (Fixed or temporals) If the rules are passed, repeat placing numbers untill board is filled.
If the rules are breaked, you don't have to reset nothing (yet)
There's a secuence of actions to do in that case:
First, try to place the same number in other cell. (untill there's no more places to chek)
If the rules are still breaked, try to change the value from 0-9.
REMEMBER Each change of the number (place or value) must be cheked to pass the rules.
Every rule of the sudoku must be cheked everytime and whith every number on the board untill there's no more chances to create a sudoku under the rules. Thats a dead end, then the main board must be reseted...and start everything again.
Don't worry!!! If you do it right and chek the rules, placing random numbers will result finally in a nice SUDOKU! :)
I had a source code but it is for the ps2 and doesn't work very well in the emu. In the ps2 each sudoku takes about 1-3 minutes to be generated... (yes.. omg.. 3 minutes waiting numbers to be happily and randomly placed) but fortunatelly I've tried the routine in the emulator and it takes just a few seconds :D
There's a way of improve speed... instead of placing absolutelly random numbers along the board, you can place into split sub boards 3x3 so when the routine finds a dead end, theres no need to reset all main board (9x9) if you can reset only the last sub board and keep cheking until there's no more chances and needs to erase all.
By spliting the work into the subboards speeds really increase cos many times in a dead end the erasing of the last sub board (3x3) clears the problem.
Maybe i'll share some day, adapted for the emulator and with some remarks to explain how it works.
-
One of the problems I've encountered with this sort of program is working out how many positions you can empty before the sudoku becomes unsolvable.
-
Hi combatking, that is no problem at all!
You can leave as many cells empty as you want, in fact you can leave ALL the main board empty or show what you want.
How is it? You really must have at least TWO matrix.
One for temporally numbers in cell (that must be cheked) and other for the numbers once the sudoku have been succesfully created, we can call them TRUE NUMBERS and they are FIXED.
Never change his place. (cos' they r in the right place)
So what you have is a matrix that contains the TRUE numbers of the sudoku and other matrix that u have been using to put/chek/erase numbers untill you get the right one.
Once you have it, you can handle both matrix as you want.
The true numbers still there and never change place or value, but you can HIDE or SHOW... and you can use the temporally matrix to show other numbers such as the player imput numbers.
Theese numbers can even have different colors or been marked for the player if he/she is shure that is a right number.... numbers showed in the temporally matrix can be whatever you want, can be true numbers (showed as a clue) or even false numbers.... THAT DOESN'T CHANGE THE FACT THAT YOU HAVE STORED THE TRUE NUMBERS! :P So if you want to show a few numbers or a lot of them of even SHOW NOTHING AT ALL, that has no influence to solve the sudoku because the sudoku IS SOLVED FROM THE VERY BEGINNING IT WAS CREATED.
Remember that if you have cheked all the sudoku rules in the creator routine, sudoku can't be created unless it is 100% reliable to solve.
If anybody coding sudokus will like to see it.
I'm thinking on sharing my old sudoku creator but it's not compatible with the emu and needs several fixes, and english translation... maybe i'll post some day.
-
But if the generated sudoku, with the blanked-out numbers were to be printed, and too many spaces were empty, it could become unsolvable.
It may be possible to create a solving algorithm which could be used to decide if a given sudoku were solvable or not, after passing it the visible numbers only.
-
No, you must accept the fact that the sudoku is solved even you can't see the numbers. The really important question here is make a creating routine which cheks the rules for sudoku and doesn't finish until it gets a solved sudoku. As I said, in the ps2 this could take up to three minutes (because of the ps2 limitations) but the fact is that placing numbers randomly, you'll finally get a solved sudoku.. dosn't matter how many time takes to do it.
Once you have created the sudoku and stored in a matrix, you can show the numbers you want, just as if you were doing the sudoku in a paper with a pencil, you can draw numbers and erase and try all you want but the solved sudoku is stored and that doesn't change.
In my code I did it this way: (I'm gonna explain you cos' the code is buggie with the emu but gonna try post soon)
1) Create a solved sudoku... SOLVED! or anyway it wont never be created.
2) Hide all the numbers. (Hide for the player but still there stored!)
3) Decide how many clue numbers to show acording the difficult of
the game.
Those numbers are choosen random and doesn't matter how
many of them you show or where are placed because the showed
numbers dosn't change the fact that we have stored a solved
sudoku.
The only thing that changes by showing less clue numbers
is that the player may have not enough clues to be sure 100%
if a number is in the right place and would need to try different
posibilities until get enough info to decide, but remember!! The
player my not be sure of a number, but of course THE PROGRAM IS
because solved sudoke is stored.
Think that even if you show a EMPTY BOARD the sudoku could be
solved anyway... cos it is actually SOLVED BUT YOU CAN'T SEE IT
Hope you understand and start tryin'. I'm gonna share the sudoku creator as soon as posible to show hot it works and it is
100% ERROR FREE. The really important question of the sudoku creator is this: BE SURE THAT ALL THE SUDOKU RULES ARE CHEKED AND PASSED anytime you place a random number, so the creator will
be "trying" to create sudokus until it finally gets a solved sudoku, and think that the random numbers the creator is trying to place are just temporary numbers and are permanently cheked and deleted until all the number passed the rules, then the sudoku is created, the numbers became FIXED AND STORED.... and you... can do what you want... showing some of those number or no one at all.
The player can also place numbers in the board... but in a different matrix for not to lose the data of the solved sudoku... mess around, place numbers, delete... the player can do anything.
Although not able to see... THE SOLVED SUDOKU IS OUT THERE... :kewl:
See you! If your really interested in sudoku creator keep an eye around and i'll post something soon.
-
-
It is possible, if too many numbers are removed, that multiple valid solutions become available.
If one of these valid solutions is reached, but does not match the original sudoku which was generated by the program, it may produce a false negative, but the checking program at the end may not need to use the original data to check, only to confirm that the user-entered numbers obey the rules of sudoku.
So, I see your point. I was being too much of a perfectionist.
-
Shared my old ps2 sudoku generator with a quiqk fix to play in the emulator.
There is only one possible solution to solve the soduku combatking, since the soduku was created and stored:The numbers stay fixed in the matrix and never change.
The player may do all the changes he want to do, that dosn't affect the solved sudoku matrix. Remeber there must be at least two matrix: the one with the right numbers that are fixed and other one for temporary numbers where player may change numbers as will.
I see this is getting hot so i've decided to share my old sudoku generator, but it is not yet 100% compatible with the emu.
The game uses a combination of single and double display buffers that is buggie in the emu so need to configure the emu.
Instructions to configure emu are in the source code.
The controls are terrible wrong... they are based on the PS2 CPU process times to make some short pauses between key presses that in the emulator gets a horrible result.
I've just fixed some bugs and make the translation to english and share to start see how is it what we are talking about.
Promise to review the code and put it in clear and adapted for emulator.
The game is a demo that generates random sudokus you can play with no time limit until you solved it.
Can choose different difficulties and that will show more or less clue numbers in board at the beginning of the game.
Player can place numbers as will, and the game will chek if match automatically.
There are color codes for the numbers.
BLACK: Fixed numbers. This are the clue numbers and can't be erased
RED: Temporary numbers: This are the numbers the player puts on the board and can be true or false, dosn't matter
GREEN: This numbers have been cheked and are RIGHT. Can't be erased.
The controls were bassed on the dualshock, so there's no keyboard to input numbers!!
CONTROLS ARE EXPLAINED ON SCREEN.
Sudoku takes up to 1 minute to generate. I maded a creating screen for the while.
I have tried to generate sudokus as fast as possible and with no info on screen and in the emulators are generated in just a few seconds so i will change that cos' is boring to wait so many time.
This is it.. sudoku generator.. working horrible but enough to understand the basics. As i said, promise to review this and make an adapted version for the emulator working nice, but for now i will be a little bussy.
PLAY RANDOM SUDOKU! :D
See u combatking!
' S U D O K U G E N E R A T O R D E M O
'
' HI EVERYODY IN YABASIC FORUMS!
'
' This little demo was maded originally in 2006 for the ps2
' and i'm sharing to show routines to create sodokus are easy
' and 100% trustable.
'
' Sorry for the crappy source code, this is the originall old ps2
' code and i've just fix some changes for the emulator.
'
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' W A R N I N G !!!
'
' THIS GAME NEED AN ESPECIFIC CONFIGURATION OF THE
' EMULATOR TO RUN PROPERLY!
'
'
' GO TO: Win32 yabasic emulator>EDIT>OPTIONS
' and do the next settings:
'
' SYNC TO:Ps2
' FORCE FLUSH RATE:ON
'
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' Greetings to everybody, hope some day can put in clear this code
' and share somethingh pretty much beautiful than this is.
' PLAY RANDOM SUDOKU!! :)
open window 1,1:poke "textalign","lt"
total=2
lp=12
dim pl(150,150)
px=-20
py=-5
t=48
t2=t/lp
for z=0 to 9:for zz=1 to lp*lp
read pl(z,zz):rem figura,bit
next:next
dim n(9,9)
dim v(9,9)
dim p(9,9)
dim c(9,9)
for z=0 to 9
for zy=1 to lp
for zx=1 to lp
' if pl(z,zy*lp-lp+zx)=1 ?"$";
' if pl(z,zy*lp-lp+zx)=0 ?".";
next
next
next
dif=1
setrgb 0,120,120,120
label menu
s=s+1
jx=5
jy=5
nuevo=1
inpu=0
minu=0
segu=0
resul=0
setdrawbuf buf:setdispbuf 1-buf
clear window
setrgb 1,0,0,0
texto_1( 320,50,"S U D O K U M A N I A 0.1")
texto_1( 320,120,"DEMO VERSION.")
texto_1( 320,150,"P L A Y A R A N D O M S U D O K U ")
texto_1( 180,295,"D I F F I C U L T Y:")
texto_1( 320,395,"PRESS [Ins] TO CONTINUE")
texto_1( 320,370,"Press [ ] [ ] to choose game difficulty")
texto_1( 320,450,"© Sergio Baño Soeiro 2006,2012")
for z=320 to 520 step 50
circle z,290,20
next
for z=320 to 320+dif*50-50 step 50
setrgb 1,0,0,0
fill circle z,290,17
setrgb 1,222,222,0
fill circle z-2,288,16
setrgb 1,222,222,222
fill circle z-4,286,15
setrgb 1,222,222,0
fill circle z-2,288,14
next
setrgb 1,222,222,0
texto_1 (318,448,"© Sergio Baño Soeiro 2006,2012")
texto_1 (318,48,"S U D O K U M A N I A 0.1")
setdispbuf buf:buf=1-buf
label tec
k=peek("port1")
if k=128 then dif=dif-1:if dif<0 dif=0:pause .1:beep:goto menu:fi
if k=32 then dif=dif+1:if dif>5 dif=5:pause .1:beep:goto menu:fi
if not k=32768 goto tec
for y=1 to 9:for x=1 to 9
p(x,y)=0
c(x,y)=0
next:next
setdrawbuf buf:setdispbuf 1-buf
clear window
setrgb 1,0,0,0
texto_1( 320,15,"C R E A T I N G S U D O K U")
texto_1( 320,35,"P L E A S E W A I T . . .")
setdispbuf buf:buf=1-buf
crear()
1
setdrawbuf buf:setdispbuf 1-buf
clear window
setrgb 1,0,0,0
for zy=1 to 10 step 3
fill rect 28,py-3+zy*t,461,py+zy*t+3
next
for zx=1 to 10 step 3
fill rect px-3+zx*t,40,px+zx*t+3,478
next
for zy=1 to 9
for zx=1 to 9
setrgb 1,0,0,0
rect px+zx*t,py+zy*t,px+zx*t+t,py+zy*t+t
if v(zx,zy)>0 dib(n(zx,zy),zx,zy)
if p(zx,zy)>0 dib(p(zx,zy),zx,zy)
next
next
setdispbuf buf:buf=1-buf
if compl=81 then t(2):goto chek:goto menu:fi
2
if pul>0 then
k2=peek("port1")
if k2<>pul then timpul=0:fi
if k2=pul then timpul=timpul+1:fi
if k2=0 pul=0
if k2>=32768 timpul=33
fi
k=peek("port1")
if pul>0 then
if timpul<33 k=0
fi
if pul=0 pul=k
if and (k,16384)>0 then
if inpu=0 and p(jx,jy)>0 then beep:
pause .1
setrgb 1,120,120,120:fill rect -16+jx*t,jy*t,-24+jx*t+t,-10+jy*t+t:p(jx,jy)=0:fi
if inpu=1 then beep
pause .1
setrgb 1,120,120,120:fill rect -16+jx*t,jy*t,-24+jx*t+t,-10+jy*t+t:p(jx,jy)=0:inpu=0:fi
fi
if and (k,32768)=0 and inpu=1 then inpu=0
setrgb 1,120,120,120
fill rect -16+jx*t,jy*t,-24+jx*t+t,-10+jy*t+t
if nuevo>0 then p(jx,jy)=nuevo:dib(p(jx,jy),jx,jy)
z=p(jx,jy)
revi=0
faltan=0
compl=0
for y=1 to 9:for x=1 to 9
if n(x,y)=z and v(x,y)=0 and p(x,y)<>z faltan=faltan+1
if (v(x,y)>1 and n(x,y)=z) or (v(x,y)=0 and p(x,y)=z) then revi=revi+1:if revi>9 faltan=9:fi
if v(x,y)>0 or p(x,y)>0 compl=compl+1
next
next
if faltan=0 then for y=1 to 9:for x=1 to 9
if n(x,y)=z v(x,y)=2
next:next
w()
texto_1( 320,200,"A L L N U M B E R S "+str$(z)+" A R E R I G H T")
t(1):w()
goto 1
fi
fi:fi
if and (k,32768)>0 and v(jx,jy)=0 then
if inpu=0 then
setrgb 1,255,0,0
fill rect -16+jx*t,jy*t,-24+jx*t+t,-10+jy*t+t
fi
' if p(jx,jy)>0 nuevo=p(jx,jy)
inpu=1
dr=dr*1.1
dib (nuevo,jx,jy)
br=255
fi
if inpu=1 then
if and (k,16)>0 then
setrgb 1,120,120,120
fill rect -16+jx*t,jy*t,-24+jx*t+t,-10+jy*t+t
nuevo=nuevo+1:if nuevo=10 nuevo=1
br=255
dib(nuevo,jx,jy)
pause .1
fi
if and (k,64)>0 then
setrgb 1,120,120,120
fill rect -16+jx*t,jy*t,-24+jx*t+t,-10+jy*t+t
nuevo=nuevo-1:if nuevo=0 nuevo=9
br=255
dib(nuevo,jx,jy)
pause .1
fi
fi:rem inpu=1
if inpu=0 then
mov=0
if and (k,16)>0 then
setrgb 1,120,120,120
rect -17+jx*t,-2+jy*t,-24+jx*t+t,-9+jy*t+t
rect -16+jx*t,-1+jy*t,-25+jx*t+t,-10+jy*t+t
rect -15+jx*t,jy*t,-26+jx*t+t,-11+jy*t+t
jy=jy-1:if jy=0 jy=9
mov=1
fi
if and (k,64)>0 then
setrgb 1,120,120,120
rect -17+jx*t,-2+jy*t,-24+jx*t+t,-9+jy*t+t
rect -16+jx*t,-1+jy*t,-25+jx*t+t,-10+jy*t+t
rect -15+jx*t,jy*t,-26+jx*t+t,-11+jy*t+t
jy=jy+1:if jy=10 jy=1
mov=1
fi
if and (k,32)>0 then
setrgb 1,120,120,120
rect -17+jx*t,-2+jy*t,-24+jx*t+t,-9+jy*t+t
rect -16+jx*t,-1+jy*t,-25+jx*t+t,-10+jy*t+t
rect -15+jx*t,jy*t,-26+jx*t+t,-11+jy*t+t
jx=jx+1:if jx=10 jx=1
mov=1
fi
if and (k,128)>0 then
setrgb 1,120,120,120
rect -17+jx*t,-2+jy*t,-24+jx*t+t,-9+jy*t+t
rect -16+jx*t,-1+jy*t,-25+jx*t+t,-10+jy*t+t
rect -15+jx*t,jy*t,-26+jx*t+t,-11+jy*t+t
jx=jx-1:if jx=0 jx=9
mov=1
fi
fi:rem inpu=0
if k=2 then t=t*.9:t2=t/7:goto 1:fi
if k=4 then t=t*1.1:t2=t/7:goto 1:fi
if k=1 then
setrgb 1,0,0,0:fill rect 40,100,600,412
setrgb 1,222,222,222
for z=1 to 9
faltan=0
for y=1 to 9
for x=1 to 9
if n(x,y)=z and v(x,y)=0 and p(x,y)<>z faltan=faltan+1
next
next
if faltan=0 then texto_1( 320,120+z*20,"A L L N U M B E R S "+str$(z)+" A R E R I G H T")
for y=1 to 9:for x=1 to 9
if n(x,y)=z v(x,y)=2
next:next
fi
if faltan>0 texto_1( 320,120+z*20,"N U M B E R "+str$(z)+" : "+str$(faltan)+" L E F T")
next
pause 2
texto_1( 320,370,"PRESS [Ins] TO CONTINUE")
k(32768)
k(0)
goto 1:fi
if k=8 then
setrgb 1,0,0,0:fill rect 40,100,600,412
setrgb 1,222,222,222
texto_1(320,150,"C H E C K I N G S U D O K U . . .")
rect 138,200,502,240
loadb=0
resul=100
fallos=0
for y=1 to 9
for x=1 to 9
loadb=loadb+1
fill rect 140,202,140+loadb*4.46,238
if resul<>1 or loadb<15 pause .1
if p(x,y)=0 and v(x,y)=0 resul=1
if v(x,y)=0 and p(x,y)<>n(x,y) fallos=fallos+1
next:next
if resul<>1 and fallos>0 resul=2
if resul=1 texto_1( 320,300,"S U D O K U I S N O T C O M P L E T E D !")
if resul=2 and fallos=1 texto_1( 320,300,"I S N O T C O R R E C T! T H E R E I S A F A I L U R E")
if resul=2 and fallos>1 texto_1( 320,300,"I S N O T C O R R E C T! T H E R E A R E "+str$(fallos)+" F A I L U R E S!")
if resul=100 then texto_1( 320,300,"C O N G R A T U L A T I O N S! I T I S C O R R E C T ! :D"):fi
pause 2
texto_1( 320,370,"PRESS [Ins] KEY TO CONTINUE")
k(32768)
k(0)
goto 1:fi
3
br=br+dr:if br<1 dr=2:if br>255 dr=-3
segn=val(right$(time$,1))
if segn<>sego then sego=segn:segu=segu+1
if segu>59 then segu=0:minu=minu+1:fi
dibti=1:fi
if dibti=1 then
setrgb 1,0,0,0
fill rect 480,40,620,90
setrgb 1,222,222,222
texto_1(550,45,"TIME:")
texto_1(540,65,str$(minu)+":")
texto_1(560,65,str$(segu))
dibti=0
' pause .03
fi
if inpu=1 and v(jx,jy)=0 dib (nuevo,jx,jy)
if v(jx,jy)>1 dib (n(jx,jy),jx,jy)
' if v(jx,jy)=0 then
if mov=1 br=255
setrgb 1,br,br,br
rect -17+jx*t,-2+jy*t,-24+jx*t+t,-9+jy*t+t
rect -16+jx*t,-1+jy*t,-25+jx*t+t,-10+jy*t+t
rect -15+jx*t,jy*t,-26+jx*t+t,-11+jy*t+t
' fi
if mov=1 pause .1
goto 2
sub dib(num,xx,yy)
' if v(xx,yy)=0 return
if br=256 then
setrgb 1,br,br,br
rect -17+jx*t,-2+jy*t,-24+jx*t+t,-9+jy*t+t
rect -16+jx*t,-1+jy*t,-25+jx*t+t,-10+jy*t+t
rect -15+jx*t,jy*t,-26+jx*t+t,-11+jy*t+t
fi
setrgb 1,150,0,0
if inpu=1 setrgb 1,br,br,br
if v(xx,yy)=1 setrgb 1,0,0,0
if v(xx,yy)=2 setrgb 1,0,120,0
for y=1 to lp: for x=1 to lp
if pl(num,y*lp-lp+x)=1 fill rect px+xx*t+x*t2-t2,py+yy*t+y*t2-t2,px+xx*t+x*t2,py+yy*t+y*t2
next
next
end sub
sub k(z)
if z>0 then repeat k=peek("port1"):until (k=z):return:fi
if z=0 then repeat k=peek("port1"):until (k=0):return:fi
if z=-1 then repeat k=peek("port1"):until (k<>0):return:fi
end sub
sub w():setrgb 1,0,0,0:fill rect 40,100,600,412:setrgb 1,222,222,222:end sub
sub t(pau)
pause pau
k(0)
setrgb 1,0,0,0:fill rect 40,335,600,400
setrgb 1,222,222,222
texto_1( 320,370,"PRESS ANY KEY TO CONTINUE")
k(0):inkey$:k(0):end sub
label chek
compl=0
w()
texto_1( 320,150,"C H E C K I N G S U D O K U . . .")
rect 138,200,502,240
loadb=0:resul=100:fallos=0
for y=1 to 9:for x=1 to 9
loadb=loadb+1
fill rect 140,202,140+loadb*4.46,238
if resul<>1 or loadb<15 pause .05
if p(x,y)=0 and v(x,y)=0 resul=1
if v(x,y)=0 and p(x,y)<>n(x,y) fallos=fallos+1
next:next
if resul<>1 and fallos>0 resul=2
if resul=1 texto_1( 320,300,"T H E S U D O K U I S N O T C O M P L E T E D!")
if resul=2 and fallos=1 texto_1 (320,290,"I S N O T C O R R E C T! T H E R E I S A F A I L U R E")
if resul=2 and fallos>1 texto_1 (320,290,"I S N O T C O R R E C T! T H E R E A R E "+str$(fallos)+" F A I L U R E S!")
if resul=100 then texto_1( 320,290,"C O N G R A T U L A T I O N S! I T I S C O R R E C T ! :D")
text 120,330,"TIME TAKEN: "+str$(minu)+" MINUTES ","lc"
if segu=1 text 400,330,"AND ONE SECOND","lc"
if segu>1 text 400,330,str$(segu)+" SECONDS","lc"
fi
t(1.8):w()
if resul=100 goto menu
compl=0
goto 1
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,1,1,1,0,0,0,0,0
data 0,0,0,0,1,1,1,0,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,1,1,1,0,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,0,1,1,0,0,0
data 0,0,0,0,0,0,0,1,1,0,0,0
data 0,0,0,0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,0,0,0,1,1,0,0,0
data 0,0,0,0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,0,0,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0,0,0,0
data 0,0,0,1,1,0,1,1,0,0,0,0
data 0,0,0,1,1,0,1,1,0,0,0,0
data 0,0,0,1,1,1,1,1,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,1,1,1,1,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,0,0,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,1,1,1,1,0,0,0
data 0,0,0,0,0,0,0,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,1,1,1,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0,0,0,0
data 0,0,0,1,1,1,1,1,0,0,0,0
data 0,0,0,1,1,1,1,1,1,0,0,0
data 0,0,0,1,1,0,0,1,1,0,0,0
data 0,0,0,1,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,0,0,0,1,1,0,0,0
data 0,0,0,0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,1,1,1,0,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,0,1,1,0,0,0
data 0,0,0,0,0,1,1,1,0,0,0,0
data 0,0,0,0,0,1,1,1,0,0,0,0
data 0,0,0,0,1,1,0,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,0,1,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,1,1,1,1,1,1,0,0,0
data 0,0,0,1,1,0,0,1,1,0,0,0
data 0,0,0,1,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,0,0,0,1,1,0,0,0
data 0,0,0,0,1,1,1,1,1,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0
label s2
data 30,81,91,10,40,51,21,71,60
data 60,71,40,31,21,91,80,50,10
data 50,10,21,81,70,60,40,90,31
data 91,21,10,70,50,80,60,30,41
data 70,61,81,40,90,30,51,11,21
data 40,31,51,20,60,11,91,80,71
data 11,41,71,90,81,20,30,61,50
data 80,50,30,61,11,41,70,21,91
data 20,90,60,50,30,70,11,41,80
label s1
data 31,81,91,11,41,51,21,71,61
data 61,71,41,31,21,91,81,51,11
data 51,11,21,81,71,61,41,91,31
data 91,21,11,70,51,81,61,31,41
data 71,61,81,41,91,31,51,11,21
data 41,31,51,21,61,11,91,81,71
data 11,41,71,91,81,21,31,61,51
data 81,51,31,61,11,41,71,21,91
data 21,91,61,51,31,71,11,41,81
101 restore s1:return
102 restore s2:return
103 restore s3:return
104 restore s4:return
105 restore s5:return
106 restore s6:return
107 restore s7:return
108 restore s8:return
109 restore s9:return
sub crear()
' xxx=40:yyy=40
i=0
setrgb 1,0,0,0
texto_1(320,270,"CONTROLS FOR THE GAME:")
texto_1(320,300,"[ ] [ ][ ] : Move across the board.")
texto_1(320,320,"[Ins] : Place a new number in an empty cell.")
texto_1(320,340,"Keep pressed [Ins] and press [ ] or [ ] to switch numbers.")
texto_1(320,360,"[Delete]: Erase current number. (If allowed)")
texto_1(320,380,"[ScrUp]: FORCE NUMBERS CHEK.")
texto_1(320,400,"[ScrDwn]: FORCE SUDOKU CHEK.")
yyy=70
1
rect 40,450,600,490
setrgb 1,cc,cc,cc:cc=cc-6+r:xxx=xxx+10:yyy=yyy-2.5+r/2:if xxx>600 then xxx=40:yyy=yyy+25:fi:if yyy>420 yyy=40:if yyy<40 yyy=540:text xxx,yyy,str$(r)
i=i+1
for y=1 to 9:for x=1 to 9
n(x,y)=0:v(x,y)=0
next:next
for y=1 to 9:for x=1 to 9
celx=1+int(x/3.1):cely=1+int(y/3.1)
repeat
no=0
r=1+int(ran(9))
for yy=1 to y:if n(x,yy)=r no=1:next
for xx=1 to x:if n(xx,y)=r no=1:next
for yy=cely*3-2 to cely*3:for xx=celx*3-2 to celx*3:if n(xx,yy)=r and n(xx,yy)>0 no=1
next:next
setrgb 1,0,0,0:fill rect 40,450,40+((y*9-9)+x)*6.91,490
reset=reset+1
if reset=60 no=0
until(no=0)
if reset=60 goto 1
reset=0
n(x,y)=r:v(x,y)=1
' pause .03
next:next
beep
for x=1 to 9
des=2+int(ran(dif*1.2))
repeat
r=1+int(ran(9))
if v(x,r)=1 v(x,r)=0
des=des-1
until(des=0)
next
for y=1 to 9
des=2+int(ran(dif*1.2))
repeat
r=1+int(ran(9))
if v(r,y)=1 v(r,y)=0
des=des-1
until(des=0)
next
PRINT "New Sudoku created after ";:print i;:print " tryings!"
end sub
sub texto_1(x,y,t$)
x=x-len(t$)*5
text x,y,t$
end sub
REMEMBER TO CONFIGURE THE EMULATOR:
Sync to:ps2
Single buffer drawing only:ON
Force flush rate:ON