Exemplo n.º 1
0
 /// <summary>
 /// Initializes an instance with the specified grid.
 /// </summary>
 /// <param name="grid">The grid.</param>
 public BugChecker(IReadOnlyGrid grid)
 {
     if (grid.IsValid(out _))
     {
         (_emptyMap, _bivalueMap, _candMaps, _) = Grid = grid;
     }
     else
     {
         throw new ArgumentException(
                   "The specified grid does not have a unique solution.", nameof(grid));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// To check if the puzzle is diamond 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 IsDiamond(this IReadOnlyGrid @this)
 {
     // Using a faster solver to check the grid is unique or not.
     if (@this.IsValid(out _))
     {
         var result = new ManualSolver().Solve(@this);
         var(er, pr, dr) = (result.MaxDifficulty, result.PearlDifficulty, result.DiamondDifficulty);
         return(er == pr && er == dr);
     }
     else
     {
         // The puzzle does not have unique solution, neither pearl nor diamond one.
         return(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Search all backdoors whose level is lower or equals than the
        /// specified depth.
        /// </summary>
        /// <param name="grid">The grid.</param>
        /// <param name="depth">
        /// The depth you want to search for. The depth value must be between 0 and 3.
        /// where value 0 is for searching for assignments.
        /// </param>
        /// <returns>All backdoors.</returns>
        /// <exception cref="SudokuRuntimeException">
        /// Throws when the specified grid is invalid.
        /// </exception>
        public IEnumerable <IReadOnlyList <Conclusion> > SearchForBackdoors(IReadOnlyGrid grid, int depth)
        {
            if (depth < 0 || depth > 3)
            {
                return(Array.Empty <IReadOnlyList <Conclusion> >());
            }

            if (!grid.IsValid(out _))
            {
                throw new SudokuRuntimeException();
            }

            var result = new List <IReadOnlyList <Conclusion> >();

            for (int dep = 0; dep <= depth; dep++)
            {
                SearchForBackdoors(result, grid, dep);
            }

            return(result);
        }
Exemplo n.º 4
0
 /// <summary>
 /// To check whether the puzzle can be solved using only simple sudoku technique set.
 /// </summary>
 /// <param name="this">(<see langword="this"/> parameter) The puzzle.</param>
 /// <returns>A <see cref="bool"/> value indicating that.</returns>
 public static bool CanBeSolvedUsingOnlySsts(this IReadOnlyGrid @this) =>
 @this.IsValid(out _) ? new ManualSolver().Solve(@this).DifficultyLevel <= DifficultyLevel.Advanced : false;