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(); }
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]); }
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()); }