Beispiel #1
0
 /// <summary>
 /// Tries to construct and initialize a tracker for the given puzzle, rules, and heuristics.
 /// </summary>
 /// <param name="puzzle">The puzzle to solve.</param>
 /// <param name="ruleKeeper">The rule-keeper to satisfy.</param>
 /// <param name="heuristic">An optional heuristic to user.</param>
 /// <param name="tracker">
 /// An <c>out</c> param where the tracker will be created. Set to null if initialization
 /// fails (i.e. this method returns false).
 /// </param>
 /// <returns>
 /// False if initialization fails, for example if the puzzle violates a rule, else true.
 /// </returns>
 internal static bool TryInit(
     TPuzzle puzzle,
     IRuleKeeper ruleKeeper,
     IHeuristic?heuristic,
     out SquareTracker <TPuzzle>?tracker)
 {
     if (!ruleKeeper.TryInit(puzzle) ||
         (!heuristic?.TryInitFor(puzzle) ?? false))
     {
         tracker = null;
         return(false);
     }
     tracker = new SquareTracker <TPuzzle>(puzzle, ruleKeeper, heuristic);
     return(true);
 }