Пример #1
0
        /// <summary>
        /// To check if the puzzle is minimal or not.
        /// </summary>
        /// <param name="this">(<see langword="this"/> parameter) The puzzle to check.</param>
        /// <returns>A <see cref="bool"/> value indicating that.</returns>
        public static bool IsMinimal(this IReadOnlyGrid @this)
        {
            int hintCount = 0;

            int[] array     = @this.ToArray();
            var   valueList = new Queue <(int, int)>();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (array[i * 9 + j] != 0)
                    {
                        hintCount++;
                        valueList.Enqueue((i, j));
                    }
                }
            }

            int[][] tempArrays = new int[hintCount][];
            for (int i = 0; i < hintCount; i++)
            {
                var(r, c)                = valueList.Dequeue();
                tempArrays[i]            = (int[])array.Clone();
                tempArrays[i][r * 9 + c] = 0;
            }

            var solver = new BitwiseSolver();

            return(tempArrays.All(gridValues => !solver.Solve(Grid.CreateInstance(gridValues)).HasSolved));
        }