示例#1
0
 public void StartNewGame(Grid grid, Difficulty difficulty = Difficulty.Unknown)
 {
     ValidatorGrid.EnsureGridIsValid(grid);
     _grid         = grid.Clone();
     _solutionGrid = _solver.SolveGivens(_grid);
     Difficulty    = difficulty;
     GridChanged();
     _historyManager.ClearRedo();
     _historyManager.ClearUndo();
     SetModalState(ModalState.None);
     _colorManager.Clear();
     _gameTimerManager.StartTimer();
 }
示例#2
0
        public override Grid Solve(Grid input)
        {
            ValidatorGrid.EnsureGridIsValid(input);

            var hashcode = GetGivensHashcode(input);

            if (!_solved.ContainsKey(hashcode))
            {
                var grid = input.Clone();
                grid.FillAllLegalCandidates();
                _solved[hashcode] = SolveStep(grid);
            }

            return(_solved[hashcode]);
        }
示例#3
0
        public ISolvingTechnique GetNextHint(Grid grid)
        {
            var stopwatch = Stopwatch.StartNew();

            if (!ValidatorGrid.AreAllGivensLegal(grid))
            {
                var positionsWithInvalidValues = Position.Positions
                                                 .Where(position => !grid.GetIsGiven(position) &&
                                                        !grid.IsCandidateLegal(position, grid.GetValue(position)));
                return(new InvalidValue(positionsWithInvalidValues.ToList()));
            }

            var step = GetAllHints(grid)
#if DEBUG
                       .ToList()
#endif
                       .FirstOrDefault();

#if DEBUG
            System.Console.WriteLine($"{stopwatch.ElapsedMilliseconds}ms - total");
#endif

            return(step ?? new HintNotFound());
        }