protected bool Step(HopOptions hopOptions, Func <Hop, bool> callback) { while (hopOptions.OptionAvailable) { Hop hop = hopOptions.CurrrentHop; UndoStack.Push(hop); if (callback(hop)) { return(false); } List <Hop> allowedHops = board.GetAllowedHops(); bool cont = Step(new HopOptions(allowedHops), callback); if (!cont) { return(false); } UndoStack.Pop(); board.UndoHopPeg(hop); hopOptions.NextOptionIndex(); } return(true); }
public override bool Step() { ++Iterations; bool next = true; List <Hop> allowedHops = board.GetAllowedHops(); if (allowedHops.Count == 0) { // No solution. Unwind. next = Unwind(); } else { HopOptions hopOptions = new HopOptions(allowedHops); HopStack.Push(hopOptions); } return(next); }
protected IEnumerable <Hop> Step(HopOptions hopOptions) { while (hopOptions.OptionAvailable) { Hop hop = hopOptions.CurrrentHop; UndoStack.Push(hop); yield return(hop); List <Hop> allowedHops = board.GetAllowedHops(); foreach (Hop nextHop in Step(new HopOptions(allowedHops))) { yield return(nextHop); } UndoStack.Pop(); board.UndoHopPeg(hop); hopOptions.NextOptionIndex(); } }