[SUDOKU] Generator + Bonus Version

Post gaming related scripts
littlegandhi1199
Posts: 49
Joined: 29 Aug 2016, 23:58

[SUDOKU] Generator + Bonus Version

01 Jun 2019, 23:37

Let me first say that I haven't written the script to decide which cells should be given for free so that you can actually play the game to completion...
...but.... someone requested I post it anyways so here you go!

This 2 part script (Main script initialized through a secondary loop with launch options) will dump the cell values into a txt which you can select all (Ctrl+A) then copy and paste it in the first cell (A1) in Microsoft Excel or the free Open Office "Calc" and it will fill everything in it's appropriate location.

Sudoku rules state that 1 through 9 must appear once and only once in every column and row and all 9 3x3 squares inside of the 9x9 square
My bonus version also gives you the sum of the numbers in the cells between 1 and 9 in that column or row
This can make the game easier or harder. I'm not sure but I find it more fun. I call it 19Tween
Here's what it looks like >>> as you can see the sum of 5+7+6+4+8=30 on the right in the first row and in the 2nd row because the 1 and 9 are next to each other the sum = 0
Image

COMPILE Sudoku.ahk to Sudoku.exe

Code: Select all

#SingleInstance Force
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
Process, Priority, , H ;if unstable, comment or remove this line
CoordMode, Mouse, Screen
#Hotstring NoMouse
SetBatchlines, -1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

if (A_IsCompiled != 1)
{
msgbox, compile me and use Sudoku_RUN.ahk to start me
exitapp
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Launch option #1
stringtrimright, auto, 1, 1
auto = %auto%o
If (auto = "auto")
{
;;;;;;;;AUTO MODE
TLN := 9
TN := 9
}
else
{
stringtrimright, auto, auto, 1
auto = %auto%l
if (auto = "excel")
	ExCountY := 1
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Launch option #2
stringtrimright, gar, 2, 1
gar = %gar%r
If (gar = "gar")
{
Temp := Object()
toggle :=1
Loop
{
FilereadLine, out, gar.txt, %A_Index%
If Errorlevel
	break
else
{
if (toggle = 1)
{
var = %out%
toggle = 0
}
else
{
Temp[var] := out
%var% := out
toggle = 1
}
}
}
}
else if (gar = "defaultr")
{
stringtrimleft, default, 2, 7
}

;;Need to loop through the alphabet so used letters are defined here
1 = A
2 = B
3 = C
4 = D
5 = E
6 = F
7 = G
8 = H
9 = I
;;Need to randomize a default grid later so define it here
grid =
(
1
2
3
4
5
6
7
8
9
)

;;Initializing Abort so it doesn't fail
If (Abort = "")
	Abort := 0
;;Define when it actually aborts
If (AbortTop = "")
	AbortTop := 6
;;Define what number counts as a fail... default is 1 million
If (AbortFail = "")
	AbortFail := 25000

;;Initializing PrevNow so it doesn't fail
PrevNow := A_TickCount
;;Defining sleep time which is only used for debugging
If (SleepT = "")
	SleepT := 500

;;Define current Letter number (letter has to be retrieved at assign/lookup)
If (LN = "")
	LN = 1
;;Define current number
If (N = "")
	N = 1

;;Takes between 8k and 50k tries to get to the 6th grid
;;>>>If I want it to take 10 seconds to complete this grid with 10 frames per second=100 frames
;;>>>===100 frames = every 500th +++ every 100ms
If (ExGrids = "")
	ExGrids := 500
If (ExSleep = "")
	ExSleep := 100
;;TURN ON THE EXCEL FUNCTION MANUALLY ... or use "excel" launch option
;;ExCountY := 1
If (ExCountY = 1)
{
msgbox 4, Sudoku.ahk - Run 1 grid at a time?
IfMsgbox No
{
TLN := 9
TN := 9
}
}

;;Make string with linefeed characters of 1-9
;;^^^Randsort that string and you have a 3x3 grid
;;...If... instead I generate the rows or collumns It'll be harder to check 3x3s
;;Probably easiest to keep the current letter and number and just add 3 or subtract



;;Master loop which is in charge of sending off to rule check function
;;+++In charge of moving forward or backward through 3x3 grids by redefining L and N
loop
{
;;Turn on this function and customize it at top of the script
If (ExCountY = 1)
{
;;Excel dumping every ExGrids number of grids
ExCount := Fails/ExGrids
;;Rounding down to a whole number
ExCount := Floor(ExCount)
if (ExCount > ExPrev)
{
var = %A1%%A_Tab%%A2%%A_Tab%%A3%%A_Tab%%A4%%A_Tab%%A5%%A_Tab%%A6%%A_Tab%%A7%%A_Tab%%A8%%A_Tab%%A9%%A_Tab%%A10%`n%B1%%A_Tab%%B2%%A_Tab%%B3%%A_Tab%%B4%%A_Tab%%B5%%A_Tab%%B6%%A_Tab%%B7%%A_Tab%%B8%%A_Tab%%B9%%A_Tab%%B10%`n%C1%%A_Tab%%C2%%A_Tab%%C3%%A_Tab%%C4%%A_Tab%%C5%%A_Tab%%C6%%A_Tab%%C7%%A_Tab%%C8%%A_Tab%%C9%%A_Tab%%C10%`n%D1%%A_Tab%%D2%%A_Tab%%D3%%A_Tab%%D4%%A_Tab%%D5%%A_Tab%%D6%%A_Tab%%D7%%A_Tab%%D8%%A_Tab%%D9%%A_Tab%%D10%`n%E1%%A_Tab%%E2%%A_Tab%%E3%%A_Tab%%E4%%A_Tab%%E5%%A_Tab%%E6%%A_Tab%%E7%%A_Tab%%E8%%A_Tab%%E9%%A_Tab%%E10%`n%F1%%A_Tab%%F2%%A_Tab%%F3%%A_Tab%%F4%%A_Tab%%F5%%A_Tab%%F6%%A_Tab%%F7%%A_Tab%%F8%%A_Tab%%F9%%A_Tab%%F10%`n%G1%%A_Tab%%G2%%A_Tab%%G3%%A_Tab%%G4%%A_Tab%%G5%%A_Tab%%G6%%A_Tab%%G7%%A_Tab%%G8%%A_Tab%%G9%%A_Tab%%G10%`n%H1%%A_Tab%%H2%%A_Tab%%H3%%A_Tab%%H4%%A_Tab%%H5%%A_Tab%%H6%%A_Tab%%H7%%A_Tab%%H8%%A_Tab%%H9%%A_Tab%%H10%`n%I1%%A_Tab%%I2%%A_Tab%%I3%%A_Tab%%I4%%A_Tab%%I5%%A_Tab%%I6%%A_Tab%%I7%%A_Tab%%I8%%A_Tab%%I9%%A_Tab%%I10%`n%J1%%A_Tab%%J2%%A_Tab%%J3%%A_Tab%%J4%%A_Tab%%J5%%A_Tab%%J6%%A_Tab%%J7%%A_Tab%%J8%%A_Tab%%J9%%A_Tab%%J10%
sleep %ExSleep%
IfNotExist, tempEXCEL.txt
	fileappend, %var%, tempEXCEL.txt
}
ExPrev := ExCount
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, Master loop ^^^ with values %LN% and %N%

;;Moving onto next grid...
;;^^^letter increase when appropriate (when N = 7 at arrival)
;;+++ Exit master loop and dump sudoku when it arrives with "N = 7" and "LN = 7"
If (A_Index > 1)
{
If (Failure = 1)
{
;;Adding to count of times the sudoku has failed
Fails++
;;If Fails exceed 1 million it should back up a grid (BUT NEEDS TO WIPE LAST GRID FIRST)
If (Fails > AbortFail)
{
;;Reset fails so it can keep counting but reset when THAT one hits 1mil too
Fails := 0
;;Maintain count of total fails
resetFail++
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;Checking how far it made it so I can add option to abort impossible sudokus
If (LN < 7)
{
Abort += 9
}
else If ((LN = 7) && (N = 4))
{
Abort+= 6
}
else
	Abort++
If (Abort >= AbortTop)
{
;;Calculating true number of fails using resetFail
resetFail *= AbortFail
Fails += resetFail
var = %A1%%A_Tab%%A2%%A_Tab%%A3%%A_Tab%%A4%%A_Tab%%A5%%A_Tab%%A6%%A_Tab%%A7%%A_Tab%%A8%%A_Tab%%A9%%A_Tab%%A10%`n%B1%%A_Tab%%B2%%A_Tab%%B3%%A_Tab%%B4%%A_Tab%%B5%%A_Tab%%B6%%A_Tab%%B7%%A_Tab%%B8%%A_Tab%%B9%%A_Tab%%B10%`n%C1%%A_Tab%%C2%%A_Tab%%C3%%A_Tab%%C4%%A_Tab%%C5%%A_Tab%%C6%%A_Tab%%C7%%A_Tab%%C8%%A_Tab%%C9%%A_Tab%%C10%`n%D1%%A_Tab%%D2%%A_Tab%%D3%%A_Tab%%D4%%A_Tab%%D5%%A_Tab%%D6%%A_Tab%%D7%%A_Tab%%D8%%A_Tab%%D9%%A_Tab%%D10%`n%E1%%A_Tab%%E2%%A_Tab%%E3%%A_Tab%%E4%%A_Tab%%E5%%A_Tab%%E6%%A_Tab%%E7%%A_Tab%%E8%%A_Tab%%E9%%A_Tab%%E10%`n%F1%%A_Tab%%F2%%A_Tab%%F3%%A_Tab%%F4%%A_Tab%%F5%%A_Tab%%F6%%A_Tab%%F7%%A_Tab%%F8%%A_Tab%%F9%%A_Tab%%F10%`n%G1%%A_Tab%%G2%%A_Tab%%G3%%A_Tab%%G4%%A_Tab%%G5%%A_Tab%%G6%%A_Tab%%G7%%A_Tab%%G8%%A_Tab%%G9%%A_Tab%%G10%`n%H1%%A_Tab%%H2%%A_Tab%%H3%%A_Tab%%H4%%A_Tab%%H5%%A_Tab%%H6%%A_Tab%%H7%%A_Tab%%H8%%A_Tab%%H9%%A_Tab%%H10%`n%I1%%A_Tab%%I2%%A_Tab%%I3%%A_Tab%%I4%%A_Tab%%I5%%A_Tab%%I6%%A_Tab%%I7%%A_Tab%%I8%%A_Tab%%I9%%A_Tab%%I10%`n%J1%%A_Tab%%J2%%A_Tab%%J3%%A_Tab%%J4%%A_Tab%%J5%%A_Tab%%J6%%A_Tab%%J7%%A_Tab%%J8%%A_Tab%%J9%%A_Tab%%J10%
;;Saving failure carefully (without involving clipboard because it needs to keep trying!)
;;sleep %SleepT%
;;Random, randVAR, 1, 9999
;;fileappend, %var%, %RULESET%-FAILURE#%Fails%=%LN%_%N%-%randVAR%---%A_Now%.txt
exitapp
}
;;Wiping 9th grid
G7 =
G8 =
G9 =
H7 =
H8 =
H9 =
I7 =
I8 =
I9 =
;;Wiping 8th grid
G4 =
G5 =
G6 =
H4 =
H5 =
H6 =
I4 =
I5 =
I6 =
;;Wiping 7th grid
G1 =
G2 =
G3 =
H1 =
H2 =
H3 =
I1 =
I2 =
I3 =
;;Proceeding to generate from the 6th grid again @ LN 4 / N 7
;;...nvm... it spends too much time re-generating the 6th grid because it respects 3 grids
;;...instead... we'll re-do the 7th grid which only respects 2 grids :D
LN := 7
N := 1
}
;;Checking if failure message ignoring has been turned on or just not defined
If (NextGrid = 1)
{
if ((NLN != LN) || (NN != N))
{
proceed = 1
NextGrid = 0
}
}
else
{
If ((LN = TLN) && (N = TN))
{
proceed = 1
TLN =
TN =
}
else if ((TLN = "") && (TN = ""))
	proceed = 1
else
	proceed = 0
;;Respecting failure message toggle
If (proceed = 1)
{
var = %A1%%A_Tab%%A2%%A_Tab%%A3%%A_Tab%%A4%%A_Tab%%A5%%A_Tab%%A6%%A_Tab%%A7%%A_Tab%%A8%%A_Tab%%A9%%A_Tab%%A10%`n%B1%%A_Tab%%B2%%A_Tab%%B3%%A_Tab%%B4%%A_Tab%%B5%%A_Tab%%B6%%A_Tab%%B7%%A_Tab%%B8%%A_Tab%%B9%%A_Tab%%B10%`n%C1%%A_Tab%%C2%%A_Tab%%C3%%A_Tab%%C4%%A_Tab%%C5%%A_Tab%%C6%%A_Tab%%C7%%A_Tab%%C8%%A_Tab%%C9%%A_Tab%%C10%`n%D1%%A_Tab%%D2%%A_Tab%%D3%%A_Tab%%D4%%A_Tab%%D5%%A_Tab%%D6%%A_Tab%%D7%%A_Tab%%D8%%A_Tab%%D9%%A_Tab%%D10%`n%E1%%A_Tab%%E2%%A_Tab%%E3%%A_Tab%%E4%%A_Tab%%E5%%A_Tab%%E6%%A_Tab%%E7%%A_Tab%%E8%%A_Tab%%E9%%A_Tab%%E10%`n%F1%%A_Tab%%F2%%A_Tab%%F3%%A_Tab%%F4%%A_Tab%%F5%%A_Tab%%F6%%A_Tab%%F7%%A_Tab%%F8%%A_Tab%%F9%%A_Tab%%F10%`n%G1%%A_Tab%%G2%%A_Tab%%G3%%A_Tab%%G4%%A_Tab%%G5%%A_Tab%%G6%%A_Tab%%G7%%A_Tab%%G8%%A_Tab%%G9%%A_Tab%%G10%`n%H1%%A_Tab%%H2%%A_Tab%%H3%%A_Tab%%H4%%A_Tab%%H5%%A_Tab%%H6%%A_Tab%%H7%%A_Tab%%H8%%A_Tab%%H9%%A_Tab%%H10%`n%I1%%A_Tab%%I2%%A_Tab%%I3%%A_Tab%%I4%%A_Tab%%I5%%A_Tab%%I6%%A_Tab%%I7%%A_Tab%%I8%%A_Tab%%I9%%A_Tab%%I10%`n%J1%%A_Tab%%J2%%A_Tab%%J3%%A_Tab%%J4%%A_Tab%%J5%%A_Tab%%J6%%A_Tab%%J7%%A_Tab%%J8%%A_Tab%%J9%%A_Tab%%J10%
;;Saving failure carefully (without involving clipboard because it needs to keep trying!)
sleep %SleepT%
fileappend, %var%, %RULESET%-DEBUG_FAILURE#%Fails%=%LN%_%N%---%A_Now%.txt
msgbox, Sudoku.ahk - %Fails% Trys...failure has been dumped for your analysis
;;CHECKING IF EXCEL SPAM is turned on
If (ExCountY = 1)
{
loop
{
IfNotExist, tempEXCEL.txt
{
fileappend, %var%, tempEXCEL.txt
break
}
}
}
;;Option to force ignore all failures until it has arrived at target grid
msgbox 4, Sudoku.ahk - "Next grid?"
IfMsgbox Yes
{
NextGrid = 1
NLN := LN
NN := N
}
else
{
msgbox 4, Target grid?
IfMsgbox Yes
{
msgbox, Letter Number 1 4 7 ... set to 9 to ignore all failures until complete
msgbox, current Letter Number is %LN%
inputbox, TLN
TLN++
TLN--
msgbox, Number 1 4 7 ... set to 9 to ignore all failures until complete
msgbox, current Number is %N%
inputbox, TN
TN++
TN--
}
}
}
}
}
else if (N = 7)
{
LN += 3
N := 1
}
else
	N += 3
}
else
	DebugTCount := A_TickCount
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;^^DebugTCount is used for calculating average time


















;;Do a perfect check to see if sudoku is impossible
if ((N = 7) && (LN = 7))
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Loop horizontally 3 times and store 1H 2H 3H / 4H 5H 6H / 7H 8H 9H
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
T%cell% := 1
}
;;After the filled slots have been noted it will look for the last 3 in all 3 horizontal bars
if (A_Index = 7)
{
tribe =
loop, 9
{
out := T%A_Index%
If (Out != 1)
	tribe = %tribe%%A_Index%
}
1H := 2H := 3H := tribe
}
else if (A_Index = 8)
{
tribe =
loop, 9
{
out := T%A_Index%
If (Out != 1)
	tribe = %tribe%%A_Index%
}
4H := 5H := 6H := tribe
}
else if (A_Index = 9)
{
tribe =
loop, 9
{
out := T%A_Index%
If (Out != 1)
	tribe = %tribe%%A_Index%
}
7H := 8H := 9H := tribe
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Then loop vertically 3 times and store 1V 4V 7V / 2V 5V 8V / 3V 6V 9V
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
T%cell% := 1
}
;;After the filled slots have been noted it will look for the last 3 in all 3 vertical bars
if (A_Index = 7)
{
tribe =
loop, 9
{
out := T%A_Index%
If (Out != 1)
	tribe = %tribe%%A_Index%
}
1V := 4V := 7V := tribe
}
else if (A_Index = 8)
{
tribe =
loop, 9
{
out := T%A_Index%
If (Out != 1)
	tribe = %tribe%%A_Index%
}
2V := 5V := 8V := tribe
}
else if (A_Index = 9)
{
tribe =
loop, 9
{
out := T%A_Index%
If (Out != 1)
	tribe = %tribe%%A_Index%
}
3V := 6V := 9V := tribe
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, %1H%-%1V%`n%2H%-%2V%`n%3H%-%3V%`n%4H%-%4V%`n%5H%-%5V%`n%6H%-%6V%`n%7H%-%7V%`n%8H%-%8V%`n%9H%-%9V%








loop, 9
{
objN := A_Index
Obj%objN% := Object()
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, parse, %objN%H
{
cell := A_Loopfield
T%cell% := 1
}
loop, parse, %objN%V
{
cell := A_Loopfield
out := T%cell%
if (out > 0)
{
Obj%objN%.InsertAt(Obj%objN%.Length() + 1, cell)
}
else
{
T%cell% := 1
}
}
}

loop, % obj1.Length()
{
out1 := obj1[A_Index]
loop, % obj2.Length()
{
out2 := obj2[A_Index]
loop, % obj3.Length()
{
out3 := obj3[A_Index]
loop, % obj4.Length()
{
out4 := obj4[A_Index]
loop, % obj5.Length()
{
out5 := obj5[A_Index]
loop, % obj6.Length()
{
out6 := obj6[A_Index]
loop, % obj7.Length()
{
out7 := obj7[A_Index]
loop, % obj8.Length()
{
out8 := obj8[A_Index]
loop, % obj9.Length()
{
out9 := obj9[A_Index]


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, I MADE IT TO THE CENTER
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0

broke = 0
loop, 9
{
cell := out%A_Index%
if (cell = "")
{
broke = 1
break
}
out := T%cell%
if (out > 0)
{
broke = 1
break
}
else
	T%cell% := 1
}
if (broke = 0)
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, Now that is a proper 3x3 grid! But does it pass the rule check?...
G7 := out1, G8 := out2, G9 := out3, H7 := out4, H8 := out5, H9 := out6, I7 := out7, I8 := out8, I9 := out9
Failure = 1
Gosub Rules
If (Failure = 0)
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, sudoku complete
;;msgbox, %out1%-%out2%-%out3%`n%out4%-%out5%-%out6%`n%out7%-%out8%-%out9%
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;
;;SUDOKU IS COMPLETE
;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;Calculating true number of fails using resetFail
resetFail *= AbortFail
Fails += resetFail
;;Make sure to include totals at ends of collumns and rows so that I can reload
;;>>>the discovered puzzle grids and find the GIVENS using a seperate script
;;Define Var "`n" goes to the next row and "%A_Tab%" goes to the next collumn
;;MAKE SURE TO INDICATE RULESET IN FILENAME
var = %A1%%A_Tab%%A2%%A_Tab%%A3%%A_Tab%%A4%%A_Tab%%A5%%A_Tab%%A6%%A_Tab%%A7%%A_Tab%%A8%%A_Tab%%A9%%A_Tab%%A10%`n%B1%%A_Tab%%B2%%A_Tab%%B3%%A_Tab%%B4%%A_Tab%%B5%%A_Tab%%B6%%A_Tab%%B7%%A_Tab%%B8%%A_Tab%%B9%%A_Tab%%B10%`n%C1%%A_Tab%%C2%%A_Tab%%C3%%A_Tab%%C4%%A_Tab%%C5%%A_Tab%%C6%%A_Tab%%C7%%A_Tab%%C8%%A_Tab%%C9%%A_Tab%%C10%`n%D1%%A_Tab%%D2%%A_Tab%%D3%%A_Tab%%D4%%A_Tab%%D5%%A_Tab%%D6%%A_Tab%%D7%%A_Tab%%D8%%A_Tab%%D9%%A_Tab%%D10%`n%E1%%A_Tab%%E2%%A_Tab%%E3%%A_Tab%%E4%%A_Tab%%E5%%A_Tab%%E6%%A_Tab%%E7%%A_Tab%%E8%%A_Tab%%E9%%A_Tab%%E10%`n%F1%%A_Tab%%F2%%A_Tab%%F3%%A_Tab%%F4%%A_Tab%%F5%%A_Tab%%F6%%A_Tab%%F7%%A_Tab%%F8%%A_Tab%%F9%%A_Tab%%F10%`n%G1%%A_Tab%%G2%%A_Tab%%G3%%A_Tab%%G4%%A_Tab%%G5%%A_Tab%%G6%%A_Tab%%G7%%A_Tab%%G8%%A_Tab%%G9%%A_Tab%%G10%`n%H1%%A_Tab%%H2%%A_Tab%%H3%%A_Tab%%H4%%A_Tab%%H5%%A_Tab%%H6%%A_Tab%%H7%%A_Tab%%H8%%A_Tab%%H9%%A_Tab%%H10%`n%I1%%A_Tab%%I2%%A_Tab%%I3%%A_Tab%%I4%%A_Tab%%I5%%A_Tab%%I6%%A_Tab%%I7%%A_Tab%%I8%%A_Tab%%I9%%A_Tab%%I10%`n%J1%%A_Tab%%J2%%A_Tab%%J3%%A_Tab%%J4%%A_Tab%%J5%%A_Tab%%J6%%A_Tab%%J7%%A_Tab%%J8%%A_Tab%%J9%%A_Tab%%J10%
;;sleeping incase I ever run these super fast one after another
sleep %SleepT%
;;saving soduku incase Clipboard breaks script
End := A_Now
fileappend, %var%, %RULESET%-PERMUTATIONS#%Fails%---%End%.txt
gar = A1`n%A1%`nA2`n%A2%`nA3`n%A3%`nA4`n%A4%`nA5`n%A5%`nA6`n%A6%`nA7`n%A7%`nA8`n%A8%`nA9`n%A9%`nA10`n%A10%`nB1`n%B1%`nB2`n%B2%`nB3`n%B3%`nB4`n%B4%`nB5`n%B5%`nB6`n%B6%`nB7`n%B7%`nB8`n%B8%`nB9`n%B9%`nB10`n%B10%`nC1`n%C1%`nC2`n%C2%`nC3`n%C3%`nC4`n%C4%`nC5`n%C5%`nC6`n%C6%`nC7`n%C7%`nC8`n%C8%`nC9`n%C9%`nC10`n%C10%`nD1`n%D1%`nD2`n%D2%`nD3`n%D3%`nD4`n%D4%`nD5`n%D5%`nD6`n%D6%`nD7`n%D7%`nD8`n%D8%`nD9`n%D9%`nD10`n%D10%`nE1`n%E1%`nE2`n%E2%`nE3`n%E3%`nE4`n%E4%`nE5`n%E5%`nE6`n%E6%`nE7`n%E7%`nE8`n%E8%`nE9`n%E9%`nE10`n%E10%`nF1`n%F1%`nF2`n%F2%`nF3`n%F3%`nF4`n%F4%`nF5`n%F5%`nF6`n%F6%`nF7`n%F7%`nF8`n%F8%`nF9`n%F9%`nF10`n%F10%`nG1`n%G1%`nG2`n%G2%`nG3`n%G3%`nG4`n%G4%`nG5`n%G5%`nG6`n%G6%`nG7`n%G7%`nG8`n%G8%`nG9`n%G9%`nG10`n%G10%`nH1`n%H1%`nH2`n%H2%`nH3`n%H3%`nH4`n%H4%`nH5`n%H5%`nH6`n%H6%`nH7`n%H7%`nH8`n%H8%`nH9`n%H9%`nH10`n%H10%`nI1`n%I1%`nI2`n%I2%`nI3`n%I3%`nI4`n%I4%`nI5`n%I5%`nI6`n%I6%`nI7`n%I7%`nI8`n%I8%`nI9`n%I9%`nI10`n%I10%`nJ1`n%J1%`nJ2`n%J2%`nJ3`n%J3%`nJ4`n%J4%`nJ5`n%J5%`nJ6`n%J6%`nJ7`n%J7%`nJ8`n%J8%`nJ9`n%J9%`nJ10`n%J10%
fileappend, %gar%, %RULESET%-PERMUTATIONS#%Fails%---%End%---------------------------gar.txt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, SUDOKU IS COMPLETE!!!
;;msgbox, Dumping values for excel retrieval...It took %Fails% trys
Clipboard = %var%
exitapp
}
}


}
}
}
}
}
}
}
}
}
;;msgbox, there is no 9th grid for this sudoku! It's IMPOSSIBLE!!!
Failure = 1
Fails := AbortFail+1
continue
}
















;;Randsort default grid
Sort, grid, Random
;;Loop through new grid and push it into index "RGrid" for later cell assignment
;;RgridN is used to grab cell value from RGrid as it increases from 1-9
;;RN needs to keep track of position along horizontal plane (1/3>3x3 grids) A3>B1
;;RLN needs to keep track of position along vertical plan (needed for master loop)
RGrid := StrSplit(grid,"`n")
, RgridN := 1
, RN := N
, RLN := LN
loop, 3
{
;;Increase Letter for use on next return
;;N needs to be reset to left of 3x3 grid but along the horizontal plane A3>B1
L := %LN%
, LN++
, N := RN
loop, 3
{
;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;
;;SAVE THE CELL HERE
;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, %L%%N% @ %RgridN% ===
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, % Rgrid[RgridN]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, A1=%CellA1%`nA2=%CellA2%`nA3=%CellA3%`nA4=%CellA4%`nB1=%CellB1%`nB2=%CellB2%`nB3=%CellB3%`nB4=%CellB4%`nC1=%CellC1%
;;Increase RgridN for next return
;;Increase N for next return
%L%%N% := Rgrid[RgridN]
, RgridN++
, N++
}
}

;;Reset LN to it's start position
;;Reset N to it's start position
LN := RLN
, N := RN


;;Go check rules and if there has been a failure it should skip the following steps
;;(Which recurses over the top of previously failed grid)
;;+++Mark as failure so return is all that is necesary for all that code(except at sucess)
Failure = 1
Gosub, RULES
;;End of Master Loop...check failure at start of next one
}
msgbox, MASTER LOOP WAS BROKEN SOMEHOW...
;;Next do a full check through the collumns and rows with the rules function
;;^^^probably doing A1-9 and A1-I1
;;<<<I could also have it generate a few grids and check where the rule was broken
;;...if it finds a duplicate it should retry THAT 3x3
;;...inject custom variants here +++ rename ruleset here too




































RULES:
If (Default = "")
	Default = 1
;;1 = Default
;;2 = 19Tween
;;3 = 19TweenNo2uu

If (Default = 1)
{
RULESET = DEFAULT
;;RETURN HERE TO ANALYZE PROCESSING TIME SPENT in "random sort" and "Failure Resets"
;;Failure = 1
;;If (Fails = AbortFail)
;;{
;;DebugTotalCount := A_TickCount-DebugTCount
;;msgbox, %DebugTotalCount%ms to complete %AbortFail%
;;}
;;RETURN



If ((LN = 7) && (N = 7))
{
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
else If ((LN = 7) && (N = 4))
{
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
loop, 9
{
If ((A_Index = 4) || (A_Index = 5) || (A_Index = 6))
	noth = 1
else
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
else If ((LN = 7) && (N = 1))
{
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
loop, 9
{
If ((A_Index = 1) || (A_Index = 2) || (A_Index = 3))
	noth = 1
else
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
else If ((LN = 4) && (N = 7))
{
loop, 9
{
If ((A_Index = 4) || (A_Index = 5) || (A_Index = 6))
	noth = 1
else
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
else If ((LN = 1) && (N = 7))
{
loop, 9
{
If ((A_Index = 1) || (A_Index = 2) || (A_Index = 3))
	noth = 1
else
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
else
{
loop, 9
{
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
loop, 9
{
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}


}
else if (Default = 2)
{
RULESET = 19Tween
If ((LN = 7) && (N = 7))
{
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
	Tally += Cell
}
%Letter%10 := Tally
TempLN = %Letter%10
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
return
}
}
CloseTally = 0
Tally =
}
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
	Tally += Cell
}
J%Number% := Tally
TempLN = J%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
return
}
}
CloseTally = 0
Tally =
}
}
else If ((LN = 7) && (N = 4))
{
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
}
}
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 4) || (A_Index = 5) || (A_Index = 6))
	noth = 1
else
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
	Tally += Cell
}
J%Number% := Tally
TempLN = J%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
return
}
}
CloseTally = 0
Tally =
}
}
else If ((LN = 7) && (N = 1))
{
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 1) || (A_Index = 2) || (A_Index = 3))
	noth = 1
else
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
	Tally += Cell
}
J%Number% := Tally
TempLN = J%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
return
}
}
CloseTally = 0
Tally =
}
}
else If ((LN = 4) && (N = 7))
{
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 4) || (A_Index = 5) || (A_Index = 6))
	noth = 1
else
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
	Tally += Cell
}
%Letter%10 := Tally
TempLN = %Letter%10
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
return
}
}
CloseTally = 0
Tally =
}
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
else If ((LN = 1) && (N = 7))
{
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 1) || (A_Index = 2) || (A_Index = 3))
	noth = 1
else
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
	Tally += Cell
}
%Letter%10 := Tally
TempLN = %Letter%10
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
return
}
}
CloseTally = 0
Tally =
}
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
else
{
loop, 9
{
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
loop, 9
{
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
}
}
}
}
Else If (Default = 3)
{
RULESET = 19TweenNo2uu
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;LN = 7/ N = 7 	calculate G10 H10 I10 / J7 J8 J9
If ((LN = 7) && (N = 7))
{
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
;;G10/H10/I10 need to be saved once all 9 cells in the plane have been counted
%Letter%10 := Tally
TempLN = %Letter%10
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
;;Tally should be reset to 0 once per loop (not wiped or 1-9 next to each other will be "")
CloseTally = 0
Tally =
}
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
;;G10/H10/I10 need to be saved once all 9 cells in the plane have been counted
J%Number% := Tally
TempLN = J%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
;;Tally should be reset to 0 once per loop (not wiped or 1-9 next to each other will be "")
CloseTally = 0
Tally =
}
}
else If ((LN = 7) && (N = 4))
{
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
CloseTally = 0
Tally =
}
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 4) || (A_Index = 5) || (A_Index = 6))
	noth = 1
else
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
;;G10/H10/I10 need to be saved once all 9 cells in the plane have been counted
J%Number% := Tally
TempLN = J%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
;;Tally should be reset to 0 once per loop (not wiped or 1-9 next to each other will be "")
CloseTally = 0
Tally =
}
}
else If ((LN = 7) && (N = 1))
{
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
CloseTally = 0
Tally =
}
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 1) || (A_Index = 2) || (A_Index = 3))
	noth = 1
else
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
;;G10/H10/I10 need to be saved once all 9 cells in the plane have been counted
J%Number% := Tally
TempLN = J%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
;;Tally should be reset to 0 once per loop (not wiped or 1-9 next to each other will be "")
CloseTally = 0
Tally =
}
}
else If ((LN = 4) && (N = 7))
{
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 4) || (A_Index = 5) || (A_Index = 6))
	noth = 1
else
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
;;G10/H10/I10 need to be saved once all 9 cells in the plane have been counted
%Letter%10 := Tally
TempLN = %Letter%10
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
;;Tally should be reset to 0 once per loop (not wiped or 1-9 next to each other will be "")
CloseTally = 0
Tally =
}
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
CloseTally = 0
Tally =
}
}
else If ((LN = 1) && (N = 7))
{
CloseTally = 0
Tally =
loop, 9
{
If ((A_Index = 1) || (A_Index = 2) || (A_Index = 3))
	noth = 1
else
	continue
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
;;G10/H10/I10 need to be saved once all 9 cells in the plane have been counted
%Letter%10 := Tally
TempLN = %Letter%10
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != Tally)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
;;Tally should be reset to 0 once per loop (not wiped or 1-9 next to each other will be "")
CloseTally = 0
Tally =
}
CloseTally = 0
Tally =
loop, 9
{
If (A_Index < 7)
	continue
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
CloseTally = 0
Tally =
}
}
else
{
CloseTally = 0
Tally =
loop, 9
{
Letter := %A_Index%
T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
cell := %Letter%%A_Index%
If (cell = "")
	continue
else
{
TempLN = %Letter%%A_Index%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
CloseTally = 0
Tally =
}
CloseTally = 0
Tally =
loop, 9
{
Number := A_Index, T1 := 0, T2 := 0, T3 := 0, T4 := 0, T5 := 0, T6 := 0, T7 := 0, T8 := 0, T9 := 0
loop, 9
{
Letter := %A_Index%
cell := %Letter%%Number%
If (cell = "")
	continue
else
{
TempLN = %Letter%%Number%
TempCell := Temp[TempLN]
If (TempCell = "")
	noth = 1
else
{
If (TempCell != cell)
{
;;msgbox, %cell% != Target of %TempCelL% @ %TempLN%
return
}
}
}
out := T%cell%
if (out > 0)
	return
else
	T%cell% := 1
If ((Cell = 9) || (Cell = 1))
{
If (Tally != "")
	CloseTally = 1
else
	Tally := 0
}
else If ((Tally != "") && (CloseTally != 1))
{
If (Cell = 2)
	return
Tally += Cell
}
}
CloseTally = 0
Tally =
}
}


;;Refuse to handle sums in the rule checking code(until ALL potentially relevant cells are filled)
;;While searching for target grid first check if variable is empty ...if so... it isn't ready
;;...but... of course perform the check in the loop RIGHT AFTER it's been calculated



;;FINDING TARGET GRID can be easily handled by typing minimums out inside EXCEL
;;>>>Then copying and pasting into text document
;;...but... BEFORE I GO SEARCHING FOR MY FAVORITE ONE I NEED TO GENERATE A BUNCH
;;>>>>>>>>> Verify those...Then generate a bunch of target grids and verify those too
;;>>>>>>>>> SO... that when I find the target grid I'll have a high confidence and can play it :D







;;End of 19TweenNo2uu loop
}
;;If failure has not occured yet it will hit this return so...define it as such
Failure = 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
;;msgbox, Failure has not occured...returning now

;;return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
if (resetFail > 0)
{
;;Tracking elapsed time per grid
GridNow := A_TickCount-PrevNow
PrevNow := A_TickCount
GridNow -= SleepT
var = %A1%%A_Tab%%A2%%A_Tab%%A3%%A_Tab%%A4%%A_Tab%%A5%%A_Tab%%A6%%A_Tab%%A7%%A_Tab%%A8%%A_Tab%%A9%%A_Tab%%A10%`n%B1%%A_Tab%%B2%%A_Tab%%B3%%A_Tab%%B4%%A_Tab%%B5%%A_Tab%%B6%%A_Tab%%B7%%A_Tab%%B8%%A_Tab%%B9%%A_Tab%%B10%`n%C1%%A_Tab%%C2%%A_Tab%%C3%%A_Tab%%C4%%A_Tab%%C5%%A_Tab%%C6%%A_Tab%%C7%%A_Tab%%C8%%A_Tab%%C9%%A_Tab%%C10%`n%D1%%A_Tab%%D2%%A_Tab%%D3%%A_Tab%%D4%%A_Tab%%D5%%A_Tab%%D6%%A_Tab%%D7%%A_Tab%%D8%%A_Tab%%D9%%A_Tab%%D10%`n%E1%%A_Tab%%E2%%A_Tab%%E3%%A_Tab%%E4%%A_Tab%%E5%%A_Tab%%E6%%A_Tab%%E7%%A_Tab%%E8%%A_Tab%%E9%%A_Tab%%E10%`n%F1%%A_Tab%%F2%%A_Tab%%F3%%A_Tab%%F4%%A_Tab%%F5%%A_Tab%%F6%%A_Tab%%F7%%A_Tab%%F8%%A_Tab%%F9%%A_Tab%%F10%`n%G1%%A_Tab%%G2%%A_Tab%%G3%%A_Tab%%G4%%A_Tab%%G5%%A_Tab%%G6%%A_Tab%%G7%%A_Tab%%G8%%A_Tab%%G9%%A_Tab%%G10%`n%H1%%A_Tab%%H2%%A_Tab%%H3%%A_Tab%%H4%%A_Tab%%H5%%A_Tab%%H6%%A_Tab%%H7%%A_Tab%%H8%%A_Tab%%H9%%A_Tab%%H10%`n%I1%%A_Tab%%I2%%A_Tab%%I3%%A_Tab%%I4%%A_Tab%%I5%%A_Tab%%I6%%A_Tab%%I7%%A_Tab%%I8%%A_Tab%%I9%%A_Tab%%I10%`n%J1%%A_Tab%%J2%%A_Tab%%J3%%A_Tab%%J4%%A_Tab%%J5%%A_Tab%%J6%%A_Tab%%J7%%A_Tab%%J8%%A_Tab%%J9%%A_Tab%%J10%
;;Saving progress carefully (without involving clipboard because it needs to keep trying!)
;;sleep %SleepT%
;;fileappend, %var%, %RULESET%-WIN#%Fails%=%LN%_%N%---%A_Now%=%GridNow%ms.txt
}
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEBUG
F10::
msgbox, %Fails% Trys so far... RESETS=%resetFail%`n%Abort% out of %AbortTop% aborts so far`n%LN% & %N%
return










;;While determining GIVEN cells find the minimum needed +++ ask for a desired count
;;^^^More might be better then less for keeping you guessing (not just 1 solution)
;;+++if it hits a dead end then...give 1 free cell and take one away? idk...
;;...maybe... there is only 1 [email protected]

;;...or... it takes x givens and goes as far as possible and then...
;;^^^It picks from the remaining blanks (until 1 of them gives another step)
;;>>>Selecting the one that gives the most number of steps in a tree (not a CHAIN)
;;>>>if none of them give another step it marks them all visible and ENDS IT













/*
AS FAR AS I CAN SURMISE...IT'S WORSE TO GENERATE IN ORDER BECAUSE THERE ARE FAR TOO MANY REPEATS
...BECAUSE... at 50k randoms there is only a 5% repeat rate with 3x3 so far...

break it down into a 2x2 and see how to count AND LIST all permutations for it
then find equivalant forumla by randomly multiplying shit lol

...so... after 10 million random sorts it came up with 24 unique permutations of 2x2
4 characters...4 positions...2 wide...2 tall

...(2x2)^2/2=X+X ... which fails when trying it out on a 1x1 with 1 characters

>>>(2x4)x(4-1) IE 2*4=8 and 8 x 3 = 24
...(gridWidth x Characters) x (Characters - 1)
=== 216 permutations for 3x3 which is clearly false???










Don't need to compile the following...
then... as long as the following script is on it will keep looping and restarting Sudoku.exe making as many as possible based on the version you selected. It takes about 5 to 10 minutes per solution and generates 2 files per solve. 1 is just for debugging and is really long and has numbers and letters. You want the shorter one with only numbers!
Again... select all (Ctrl+A) then copy and paste it in the first cell (A1) in Microsoft Excel or the free Open Office "Calc" and it will fill everything in it's appropriate location.

Code: Select all

msgbox, make sure Sudoku.ahk is compiled to Sudoku.exe`n`nkeep in mind it takes 5 to 10 minutes per solve`nIt'll keep restarting silently so even if sudoku.exe is flashing over and over it doesn't mean it's broken
msgbox, Enter your desired number to select the version of Sudoku you want!
msgbox, 1 = Default
msgbox, 2 = 19Tween
inputbox, def
var = auto default%def%
loop
{
Process,Exist,Sudoku.exe
If ErrorLevel
	sleep 100
else
	Run, Sudoku.exe %var%
}
littlegandhi1199
Posts: 49
Joined: 29 Aug 2016, 23:58

Re: [SUDOKU] Generator + Bonus Version

02 Jun 2019, 00:08

Hope it all makes sense!
And if anyone has ideas for deciding the given cells let me know...Notes of my initial thoughts are at the bottom of the main script. Maybe that'll stimulate your big brain.
Let me know
Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285

Sudoku Grid Generator + BONUS Custom Variant - Fun Pending...
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=65054&p=279321#p279321

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 20 guests