Example #1
0
        private IActionResult BuildSolutionModel(Puzzle puzzle, MessageLog log = null)
        {
            var model = new PageModel(log);

            model.InitialState = puzzle.Copy();
            model.Puzzle       = puzzle;
            model.PageTitle    = "Sudoku brain";

            var solver = new PuzzleSolver(model.Log);

            int previousNumberFilledIn = puzzle.CountFilledInCells;

            while (solver.ApplyAllStrats(puzzle))
            {
                int currentNumberFilledIn = puzzle.CountFilledInCells;
                if (currentNumberFilledIn > previousNumberFilledIn)
                {
                    puzzle.WriteGridAsText(model.Log);
                }
                if (currentNumberFilledIn == 81)
                {
                    break;
                }
                previousNumberFilledIn = currentNumberFilledIn;
            }
            solver.EndSolutionStats(puzzle);

            return(View("Index", model));
        }