/// <summary> /// <see cref="ISearchAgent"/> ProcessVariables event handler. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <inheritdoc /> protected override void OnProcessVariables(object sender, ProcessVariablesEventArgs e) { ISudokuPuzzle candidate = new SudokuPuzzle(); // In this case we know that there is a Single Aspect. var aspect = Aspects.SingleOrDefault(); Assert.NotNull(aspect); for (var row = MinimumValue; row < MaximumValue; row++) { for (var col = MinimumValue; col < MaximumValue; col++) { // ReSharper disable once PossibleNullReferenceException candidate[row, col] = (int)aspect.Cells[row, col].Value(); } } /* If we're here processing variables, it should be because we are processing the next * solution. However, in the event we still do not have a solution, then simply return. */ // TODO: TBD: we really should never land here I don't think... if (candidate.IsSolved) { Solution = candidate; // False is the default, so only mark whether ShouldBreak when we have one. e.ShouldBreak = true; } base.OnProcessVariables(sender, e); }
/// <summary> /// <see cref="ISearchAgent"/> ProcessVariables event handler. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void OnProcessVariables(object sender, ProcessVariablesEventArgs e) { var candidate = new SudokuPuzzle(); ISudokuPuzzle local = candidate; // In this case we know that there is a Single Aspect. var aspect = Aspects.SingleOrDefault(); Assert.That(aspect, Is.Not.Null); const int size = SudokuProblemSolverAspect.Size; for (var row = 0; row < size; row++) { for (var col = 0; col < size; col++) { // ReSharper disable once PossibleNullReferenceException local[row, col] = (int)aspect.Cells[row, col].Value(); } } /* If we're here processing variables, it should be because we are processing the next * solution. However, in the event we still do not have a solution, then simply return. */ // TODO: TBD: we really shoul never land here I don't think... if (!local.IsSolved) { return; } Solution = local; // False is the default, so only mark whether ShouldBreak when we have one. e.ShouldBreak = true; base.OnProcessVariables(sender, e); }