I'm trying to build a GA to solve Sudoku but i have seemed to come across a strange problem i've never seen before. I am calling a variable through a procedure and assigning it to another variable however when one variable changes so does the other and it's all in a for loop.
Code Snippet
public class suduko{
public int Fitness = 0;
public int[,] grid = new int[9, 9];
}
public void Create(int [,] game)
{
Random Random = new Random();
int dummy = 0;
// populate population with random numbers
suduko su = new suduko();
for (int i = 0; i < PopSize; i++)
{
su.grid = game;
for (int j = 0; j < 9; j++)
{
for (int k = 0; k < 9; k++)
{
dummy = Random.Next(1, 10);
if (su.grid[j, k] == 0) { su.grid[j, k] = dummy; }
}
}
su.Fitness = fitness(su.grid);
pop.Add(su);
}
evolve(pop);
}
So game changes every for loop to whatever su.grid is even though game is never assigned to! Anyone have any ideas
Thanks
Daniel