Ejemplo n.º 1
0
        public static Puzzle CreateSolvable()
        {
            var puzzle     = CreateEmptyPuzzle();
            var scratchpad = new PuzzleGeneratorState();

            SetPuzzleBox(puzzle, scratchpad);
            var i = 0;

            while (i < 35)
            {
                var index = RandomNumberThinger.Instance.PickAValue(81);
                if (puzzle.AllBoxes[index].IsGiven)
                {
                    continue;
                }
                var givenBox = puzzle.AllBoxes[index];
                givenBox.Guessed = givenBox.Assigned;
                givenBox.IsGiven = true;
                i++;
            }
            return(puzzle);
        }
Ejemplo n.º 2
0
        private static void SetPuzzleBox(Puzzle puzzle, PuzzleGeneratorState scratch)
        {
            if (scratch.CurrentIndex == 81)
            {
                return;
            }

            var possibles = puzzle.GetPossiblesForId(scratch.CurrentIndex);

            while (possibles.Count > 0 && scratch.CurrentIndex < 81)
            {
                var selector = RandomNumberThinger.Instance.PickAValue(possibles.Count);
                puzzle.SetValueAtId(scratch.CurrentIndex, possibles[selector]);
                possibles.RemoveAt(selector);
                scratch.CurrentIndex++;
                SetPuzzleBox(puzzle, scratch);

                if (scratch.CurrentIndex == 81)
                {
                    return;
                }
                puzzle.ReleaseValueAtId(--scratch.CurrentIndex);
            }
        }