PDA

View Full Version : [AS3] Sudoku help


joshtremblay
12-10-2008, 02:44 PM
Ok, so i have a sudoku solver i am working on. It takes the user's input and calculates the answer and gives an output. I have 81 textboxed named f1,f2,f3,f4,f5....,f81. i have a datagrid which is:

var Datagrid:Array = [[f1.text,f2.text,f3.text,f4.text,f5.text,f6.text,f7 .text,f8.text,f9.text], [f10.text,f11.text,f12.text,f13.text,f14.text,f15.t ext,f16.text,f17.text,f18.text]... and so on. (every nine textboxes across is one row.)

So i can acsess a certain box using datagrid[i][j] (Example: Datagrid[0][3] = f4.text) now when the user clicks on the "CHECK" buttoon all boxes without values turn into 0s and then runs the datagrid check.

Example:
0,0,0,9,0,7,3,0,8
0,0,8,0,2,0,0,0,0
3,0,0,0,0,8,0,4,0
2,3,0,0,7,0,0,0,0
0,0,7,1,0,4,9,0,0
0,0,0,0,6,0,0,7,1
0,5,0,7,0,0,0,0,3
0,0,0,0,9,0,7,0,0
6,0,9,8,0,5,0,0,0

OK now here is the trickey part, i want the program to start at
Datagrid[0][0] and check if a value: "n", is in row one (Datagrid[0][1-9])
and colum 1 (Datagrid[1-9][0])

so i have tried using various loops, and if statements to checks this, such as:

if(n == Datagrid[i][j]){
n++;
}else{
j++;
.....etc.....

Now i really need help on this! to do a check to see if it is in the row and colum that the text box is in. (Example: box 1 checks row1,col1. box2 checks row1,col2)
-------------------------------------------------------------------------
Now this part may or may not be of any use to any of you but, if 'n' is in either row1 or col1 or both of them n++, if its not it either of them 'n' is placed in that box and it moves on to check the next box.
-------------------------------------------------------------------------
i think i have given all the possable information i can regarding this, however if any one needs any clearing up PLEASE!! e-mail me at

joshtremblay91@hotmail.com

Please help me, any help is greatly apriciated!!

rrh
12-10-2008, 06:01 PM
You could also have another set of arrays, where
colCount[3][5] will for example be set to true if 5 appears in the third column and false if it doesn't.

So once you've populated the count arrays, you can just check:

var possibleValues:Array=[];
for (counter=1;counter<=9;counter++) {
if (colCount[x][counter]==rowCount[y][counter]==squareCount[square][counter]==0) {
possibleValues.push(counter);
}
}
if (possibleValues.length==1) {
//it has to be this value
}