-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver.cs
46 lines (43 loc) · 1.44 KB
/
solver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
namespace sr
{
static partial class Sudoku {
public static int count = 0;
public static int[,] solve(int[,] field, int px, int py, int value, bool printout, ref int count, bool stopOnOne) {
if(stopOnOne)if(count > 0) return field;
int[,] workerField = new int[9,9];
Array.Copy(field,workerField,field.Length);
workerField[px,py] = value;
for (int x = 0; x < 9; x++)
{
for (int y = 0; y < 9; y++)
{
if (workerField[x,y] == 0)
{
for (int val = 1; val <= 9; val++)
{
if(check(x,y,val,workerField))
solve(workerField,x,y, val, printout, ref count,stopOnOne);
}
return null;
}
}
}
if(printout) {
for (int x = 0; x < 9; x++)
{
for (int y = 0; y < 9; y++)
{
Console.Write(workerField[x,y]);
}
Console.WriteLine();
}
Console.WriteLine("---------");
}
count++;
//Sudoku.outputField = workerField;
Array.Copy(workerField,Sudoku.outputField,workerField.Length);
return workerField;
}
}
}