Hello guy´s
I´ve a problem with the implementation of Sudoku in c#....
i wrote 2 for-loops, one that tests the collums, one that tests the rows if the numbers 1-9 are unique in a row/col... The 2 Loops are working perfect, but only if i use ONE of them.. The 2 loops are not working together , I think it´s a Overflow...
I try to interlace the for-loops, but i´m with stupid.. I have to ask for help in this forum
here is a bit of code
using System;
using System.Collections.Generic;
using System.Text;
namespace sudoku
{
class sudoku
{
private int[] values_right = new int[81];
private int[] squareindex = new int[81] {0, 0, 0, 1, 1, 1, 2, 2, 2,
0, 0, 0, 1, 1, 1, 2, 2, 2,
0, 0, 0, 1, 1, 1, 2, 2, 2,
3, 3, 3, 4, 4, 4, 5, 5, 5,
3, 3, 3, 4, 4, 4, 5, 5, 5,
3, 3, 3, 4, 4, 4, 5, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 8,
6, 6, 6, 7, 7, 7, 8, 8, 8,
6, 6, 6, 7, 7, 7, 8, 8, 8};
private int[] posible_values = new int[9] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
public sudoku()
{
this.generate();
}
public void generate()
{
Random rnd = new Random();
int i;
for (i = 0; i < 81; i++)
{
while (this.values_right[i] == 0)
this.values_right[i] = rnd.Next(1, 90) % 10;
while (check_position(i) == 0)
{
this.values_right[i] = (this.values_right[i] + 1) % 10;
}
}
}
public int[] get_values_right()
{
return values_right;
}
int check_position(int i)
{
if (this.values_right[i] == 0)
return 0;
Random rnd = new Random();
int row = i - (i % 9);
int col = i % 9;
int position;
for (position = row; position < row + 9; position++)
{
if (position == i)
continue;
if (this.values_right[position] == this.values_right[i])
return 0;
}
return 1;
}
}
}
Thanks for help, members of coding...
I´m sure, its only a LITTLE 1-MINUTE problem 4 you..
Thank again..^^
modified on Thursday, August 27, 2009 2:25 AM
|