public SolveStatus StepSolve() { var boardStateChanged = false; var solvableCells = CurrentBoard.BoardCells.Where(x => !x.SolvedCell).ToList(); var noChangeMade = 0; var solveMessage = ""; var stepType = SolverStepType.FailStep; while (!boardStateChanged && !CurrentBoard.PuzzleSolved) { var baseDifficulty = 1; var validatorSuccess = false; foreach (var validator in BoardValidators.Where(x => x.ValidatorDifficulty <= baseDifficulty).ToList()) { if (validatorSuccess) { break; } foreach (var cell in solvableCells) { if (validator.ValidatePotentialCellValues(cell, CurrentBoard, out solveMessage)) { validatorSuccess = true; stepType = SolverStepType.ValidatorStep; break; } } } if (validatorSuccess) { boardStateChanged = true; noChangeMade = 0; continue; } var methodSuccess = false; foreach (var method in SolverMethods.Where(x => x.MethodDifficulty <= baseDifficulty).ToList()) { if (methodSuccess) { break; } foreach (var cell in solvableCells) { if (method.ApplyMethod(cell, CurrentBoard, out solveMessage)) { methodSuccess = true; stepType = SolverStepType.MethodStep; break; } } } if (methodSuccess) { boardStateChanged = true; noChangeMade = 0; continue; } baseDifficulty++; noChangeMade++; if (noChangeMade >= 100) { Console.WriteLine("No Board State change for 100 iterations. Solve could not complete."); Console.WriteLine($"Total Steps = {CurrentStep.SolverStepId}"); return(SolveStatus.NoStateChange); } } SolverSteps.Add(CurrentStep); var nextStep = new SolverStep { SolverStepId = CurrentStep.SolverStepId + 1, StepComment = solveMessage, StepType = stepType, BoardState = new SolverState { BoardCells = CurrentBoard.BoardCells.ToList(), SolvedState = false } }; CurrentStep = nextStep; CurrentBoard = new PseudoBoard(CurrentBoard.BoardCells.ToList()); CurrentBoard.PrintBoard(); if (!string.IsNullOrEmpty(solveMessage)) { Console.WriteLine(solveMessage); } Console.WriteLine($"Total Steps = {CurrentStep.SolverStepId}"); if (CurrentBoard.PuzzleSolved) { return(SolveStatus.BoardSolved); } return(SolveStatus.StateChange); }