Esempio n. 1
0
            /// <summary>
            /// Attempts to cut 2 locations from the current board, mirrored about a randomly chosen axis.
            /// </summary>
            /// <param name="Stream">An existing <see cref="Random"/> number generator</param>
            /// <returns>If the result has a unique solution, then the new <see cref="Board"/>. Otherwise, the original</returns>
            public Board Pair(Random Stream)
            {
                var result = new Board(_parent);

                var Filled = _parent.Find.FilledLocations().ToList();

                if (Filled.Count > 0)
                {
                    Location loc = new Location(Filled[Stream.Next(Filled.Count)]);

                    result[loc] = 0;

                    if (Stream.Next(2) == 1)
                    {
                        result[loc.FlipHorizontal()] = 0;
                    }
                    else
                    {
                        result[loc.FlipVertical()] = 0;
                    }

                    if (result.ExistsUniqueSolution())
                    {
                        return(result);
                    }
                }
                return(_parent);
            }
Esempio n. 2
0
        public void CreatePuzzle()
        {
            for (int iter = 0; iter < Iterations; iter++)
            {
                var Work = Factory.Solution(rnd);
                for (int i = 0; i < 3; i++)
                {
                    var step = new Board(Work);

                    for (int j = 0; j < 3; j++)
                    {
                        Location loc = rnd.Next(81);
                        step[loc] = 0;
                        step[loc.FlipHorizontal()] = 0;
                        step[loc.FlipVertical()] = 0;
                        step[loc.FlipVertical().FlipHorizontal()] = 0;
                    }

                    if (step.ExistsUniqueSolution())
                        Work = step;
                }

                givens[0].Add(Work.Find.FilledLocations().Count());
            }

            WriteStatistics("Givens in generated puzzles: ", givens[0]);
        }
Esempio n. 3
0
            /// <summary>
            /// Attempts to cut a single location
            /// </summary>
            /// <param name="Stream">An existing <see cref="Random"/> number generator</param>
            /// <returns>If the result has a unique solution, then the new <see cref="Board"/>. Otherwise, the original</returns>
            public Board Single(Random Stream)
            {
                var result = new Board(_parent);

                var Filled = _parent.Find.FilledLocations().ToList();

                if (Filled.Count > 0)
                {
                    result[Filled[Stream.Next(Filled.Count)]] = 0;

                    if (result.ExistsUniqueSolution())
                    {
                        return(result);
                    }
                }
                return(_parent);
            }
Esempio n. 4
0
            /// <summary>
            /// Attempts to cut a single location
            /// </summary>
            /// <param name="Stream">An existing <see cref="Random"/> number generator</param>
            /// <returns>If the result has a unique solution, then the new <see cref="Board"/>. Otherwise, the original</returns>
            public Board Single(Random Stream)
            {
                var result = new Board(_parent);

                var Filled = _parent.Find.FilledLocations().ToList();

                if (Filled.Count > 0)
                {
                    result[Filled[Stream.Next(Filled.Count)]] = 0;

                    if (result.ExistsUniqueSolution())
                        return result;
                }
                return _parent;
            }
Esempio n. 5
0
            /// <summary>
            /// Attempts to cut 4 locations from the current board, mirrored about both horizontal and vertical axes.
            /// </summary>
            /// <param name="Stream">An existing <see cref="Random"/> number generator</param>
            /// <returns>If the result has a unique solution, then the new <see cref="Board"/>. Otherwise, the original</returns>
            public Board Quad(Random Stream)
            {
                var result = new Board(_parent);

                var Filled = _parent.Find.FilledLocations().ToList();

                if (Filled.Count > 0)
                {
                    Location loc = new Location(Filled[Stream.Next(Filled.Count)]);

                    result[loc] = 0;
                    result[loc.FlipHorizontal()] = 0;
                    result[loc.FlipVertical()] = 0;
                    result[loc.FlipHorizontal().FlipVertical()] = 0;

                    if (result.ExistsUniqueSolution())
                        return result;
                }
                return _parent;
            }