Ejemplo n.º 1
0
        public SodukuSolver(string pSoduku)
        {
            Size = (int)Math.Sqrt(pSoduku.Length);
            //Count zeros
            _zeroCount = pSoduku.Count(pC => pC == '0' || pC == ' ');

            //Initialize map
            int[,] map = new int[(BoardSize * 4), (_zeroCount * Size) + (BoardSize - _zeroCount)];

            //Populate map
            int row = 0;

            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    int num = (int)Char.GetNumericValue(pSoduku[x + (y * Size)]);
                    if (num != 0)
                    {
                        CreateMapping(x, y, num - 1, ref row, ref map);
                    }
                    else
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            CreateMapping(x, y, i, ref row, ref map);
                        }
                    }
                }
            }

            _algorithmX = new AlgorithmX(map);
        }
Ejemplo n.º 2
0
        public SodukuSolver(int[,] pSoduku)
        {
            Size = pSoduku.GetLength(0);
            //Count zeros
            _zeroCount = 0;
            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    if (pSoduku[x, y] == 0)
                    {
                        _zeroCount++;
                    }
                }
            }

            //Initialize map
            int[,] map = new int[(BoardSize * 4), (_zeroCount * Size) + (BoardSize - _zeroCount)];

            //Populate map
            int row = 0;

            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    int num = pSoduku[x, y];
                    if (num != 0)
                    {
                        CreateMapping(x, y, num - 1, ref row, ref map);
                    }
                    else
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            CreateMapping(x, y, i, ref row, ref map);
                        }
                    }
                }
            }

            _algorithmX = new AlgorithmX(map);
        }