public Grid GetNewInitialSolution(Grid initialGrid)
        {
            Random r = new Random();
            Grid g = new Grid(initialGrid);
            for (int i = 0; i < InitiPopulationIterationCount;i++ )
            {
                var n = r.Next(1, g.Size+1);
                var row = r.Next(0, g.Size);
                var col = r.Next(0, g.Size);
                if (g.Get(row, col) != 0)
                {
                    g.Place(n,row,col);

                }
            }
            return g;
        }
        public int GetNextPosition(Grid g)
        {
            int min = int.MaxValue;
            int minPos = -1;
            for(int i = 0; i < g.Size; i++)
                for (int j = 0; j < g.Size; j++)
                {
                    if (g.Get(i, j) != 0)
                        continue;
                    var l = g.GetAvailableNumbersFor(i, j);
                    if (l.Count < min)
                    {
                        min = l.Count;
                        minPos = i*g.Size + j;

                    }
                    if (min == 1)
                        return minPos;
                }

            return minPos;
        }
示例#3
0
 public void TestGet()
 {
     Grid g = new Grid(9,0);
     g.Place(3,1,1);
     Assert.AreEqual(3,g.Get(1,1));
 }