public static RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider(); //for the random numbers
public static void PrintSudoku(int[,] x) //to Print, obviously
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
Console.Write(x[i, j] + " ");
}
Console.WriteLine();
}
}
public static bool RunList(List<int> l, int j) //to check if the place is used already
{
bool li = true;
if (l.IsEmpty() == true) //if no place was used before, then good and be true;
{
li = true;
}
else
{
Node<int> p = l.GetFirst();
while (p.GetNext() != null)
{
if (p.GetInfo() == j) //if this place was used, change to false to keep in the loop
{
li = false;
}
p.GetNext();
}
}
return li;
}
public static void Test(int[,] x, List<int> l)
{
byte[] randomNumber = new byte[1];
rngCsp.GetBytes(randomNumber); //random numbers
bool li = false;
int count = 1;
int j = (byte)((randomNumber[0] % 9 + 1));
while (count < 10) //for 10 numbers 1-9
{
for (int i = 0; i < 9; i++) //for 9 rows of array 0-8
{
while (x[i,j] != 0 || li == false) //to check if the spot is occupied by a number and if there is already the same number above it
{
j = (byte)((randomNumber[0] % 9 + 1)); //new random number
li = RunList(l, j); //to check if there is already the same number above
}
x[i, j] = count; //to make the point a number other than 0
Node<int> p = l.GetFirst();
for (int y = 1; y < count; y++)
{
p.GetNext();
}
l.Insert(p, j);//to put the place on the line that was used in the "memory bank" to check later if this row was used already
li = false;//restart
}
List<int> l1 = new List<int>();
//l = l1; tried to restart the list, I probably need a better method
}
}
static void Main(string[] args)
{
int[,] x = new int[9, 9];
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
x[i, j] = 0;
Console.Write(x[i, j] + " ");
}
Console.WriteLine(); //making everything 0
}
//for (int y = 0; y < 9; y++) IGNORE THIS PLEASE
//{
// for (int i = 0; i < 9; i++)
// {
// for (int j = 0; j < 9; j++)
// {
// VerticalTest(x, i, j);
// HTest(x, i, j);
// }
// }
//}
//for (int y = 0; y < 9; y++)
//{
// for (int j = 0; j < 9; j++)
// {
// for (int i = 0; i < 9; i++)
// {
// VerticalTest(x, i, j);
// }
// }
//} IGNORE THAT ABOVE
List<int> l = new List<int>();
Test(x, l); //to use the function
Console.WriteLine("------------------");
PrintSudoku(x); //to print it
//byte[] randomNumber = new byte[1];
//rngCsp.GetBytes(randomNumber);
//Console.WriteLine((byte)((randomNumber[0] % 9 + 1))); code for me for random numbers
}