Пример #1
0
        public filledBox[] shuffleBoxesCreateCheckingLists()
        {
            filledBox[] boxes = new filledBox[81];

            for (int i = 0; i < 81; i++)
            {
                boxes[i]        = new filledBox();
                boxes[i].values = new int[9] {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                boxes[i].values = shuffle(boxes[i].values);
            }

            generationLines   = new List <filledBox> [9];
            generationColumns = new List <filledBox> [9];
            generationGroups  = new List <filledBox> [9];

            for (int i = 0; i < 9; i++)
            {
                generationLines[i]   = new List <filledBox>();
                generationColumns[i] = new List <filledBox>();
                generationGroups[i]  = new List <filledBox>();
            }

            int boxIndex = 0;

            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    for (int innerY = 0; innerY < 3; innerY++)
                    {
                        for (int innerX = 0; innerX < 3; innerX++)
                        {
                            int subPanelIndex = x + y * 3;
                            int lineIndex     = innerY + y * 3;
                            int columnIndex   = innerX + x * 3;

                            boxes[boxIndex].textBoxIndex   = boxIndex;
                            boxes[boxIndex].groupIndex     = subPanelIndex;
                            boxes[boxIndex].columnIndex    = columnIndex;
                            boxes[boxIndex].lineIndex      = lineIndex;
                            boxes[boxIndex].nextIndexToTry = 0;
                            boxes[boxIndex].value          = 0;

                            generationLines[lineIndex].Add(boxes[boxIndex]);
                            generationColumns[columnIndex].Add(boxes[boxIndex]);
                            generationGroups[subPanelIndex].Add(boxes[boxIndex]);
                            boxIndex++;
                        }
                    }
                }
            }

#if !fast
            boxes = shuffle(boxes);
#endif

            return(boxes);
        }
Пример #2
0
        public bool createsError(filledBox box)
        {
            bool result = false;

            if (hasError(generationGroups[box.groupIndex], box))
            {
                result = true;
            }
            else if (hasError(generationLines[box.lineIndex], box))
            {
                result = true;
            }
            else if (hasError(generationColumns[box.columnIndex], box))
            {
                result = true;
            }

            return(result);
        }
Пример #3
0
        public bool hasError(List <filledBox> list, filledBox box)
        {
            bool result = false;

            foreach (filledBox filledBoxToCheck in list)
            {
                if (filledBoxToCheck.value == box.values[box.nextIndexToTry])
                {
                    if (box.lineIndex != filledBoxToCheck.lineIndex ||
                        box.columnIndex != filledBoxToCheck.columnIndex)
                    {
                        result = true;
                        break;
                    }
                }
            }

            return(result);
        }