internal int PopulateBestGuesses(Span <Guess> toPopulate) { int maxPossibleValues = MaxGuessCount + 1; Objective?bestObjective = null; foreach (Objective?objective in _graph.GetUnsatisfiedRequiredObjectivesWithConcretePossibilities()) { if (!objective.AllUnknownPossibilitiesAreConcrete) { continue; } if (objective.AllUnknownPossibilitiesAreRequired) { Possibility possibility = (Possibility)objective .GetUnknownDirectPossibilities().First(); toPopulate[0] = new Guess(possibility.Coordinate, possibility.Index); return(1); } var numPossibilities = objective.CountUnknown; if (numPossibilities < maxPossibleValues) { maxPossibleValues = numPossibilities; bestObjective = objective; } } Debug.Assert( bestObjective is not null, $"{nameof(bestObjective)} was still null at the end of {nameof(PopulateBestGuesses)}."); return(_PopulateGuessesFromObjective(bestObjective, toPopulate)); }
private ExactCoverGraph(ExactCoverGraph other) { int length = other._possibilities.Length; _possibilities = new Possibility[length][][]; for (int rowIndex = 0; rowIndex < length; ++rowIndex) { _possibilities[rowIndex] = new Possibility[length][]; } _allPossibleValues = other.AllPossibleValues.ToArray(); ValuesToIndices = other.ValuesToIndices; }
private ExactCoverGraph(IReadOnlyPuzzle puzzle) { int size = puzzle.Size; _possibilities = new Possibility[size][][]; for (int rowIndex = 0; rowIndex < size; ++rowIndex) { _possibilities[rowIndex] = new Possibility[size][]; } _allPossibleValues = puzzle.AllPossibleValuesSpan.ToArray(); var valuesToIndices = new Dictionary <int, int>(_allPossibleValues.Length); for (int index = 0; index < _allPossibleValues.Length; index++) { valuesToIndices[_allPossibleValues[index]] = index; } ValuesToIndices = valuesToIndices; }