Exemplo n.º 1
0
        public static bool NewNumberAssignment(int Cell, string[,] CellsArray, object p)
        {
            bool isSameElement = false;

            bool CicleEnd = false;

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if ((i * 9 + j) == Cell)
                    {
                        CellsArray[i, j] = null;
                        CicleEnd         = true;
                        isSameElement    = GameSolution.SearchSameElemnt(CellsArray, i, j, Convert.ToInt32(p));
                        break;
                    }
                }
                if (CicleEnd)
                {
                    break;
                }
            }

            if (isSameElement is true)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private static void DeepSolutionAlgorithm(int FirstElementToAssign, string[,] Field)
        {
            bool CanBreakCicle = false;
            bool isSameElementFounded;
            int  CurrentElement;
            int  CurrentElementItterationCount = 0;

            for (int i = 0; i < 9; i++)
            {
                CurrentElement = FirstElementToAssign;

                for (int j = 0; j < 9; j++)
                {
                    if (CurrentElement == 10)
                    {
                        CurrentElement = 1;
                    }

                    if (Field[i, j] != null)
                    {
                        continue;
                    }

                    isSameElementFounded = GameSolution.SearchSameElemnt(Field, i, j, CurrentElement);

                    CurrentElementItterationCount++;
                    if (isSameElementFounded is true)
                    {
                        CurrentElement++;
                        if (CurrentElement == 10)
                        {
                            CurrentElement = 1;
                        }
                        j--;
                        if (CurrentElementItterationCount == 10)
                        {
                            CanBreakCicle = true;
                            break;
                        }
                        continue;
                    }

                    CurrentElementItterationCount = 0;

                    if (isSameElementFounded is false)
                    {
                        Field[i, j] = CurrentElement.ToString();
                    }


                    CurrentElement++;
                }
                if (CanBreakCicle)
                {
                    break;
                }
            }
        }