public IEnumerable <SearchNode2> EnumeratePaths2() { var node = new SearchNode2(start); var queue = new Queue <SearchNode2>(); queue.Enqueue(node); while (queue.Count > 0) { var popped = queue.Dequeue(); if (popped.isWin) { yield return(popped); } else { var newNodes = popped.Explore(); foreach (var newNode in newNodes) { queue.Enqueue(newNode); } } } }
public SearchNode2(SearchNode2 parent, Cave newCurrent) { this.inOrder = new List <Cave>(parent.inOrder); this.inOrder.Add(newCurrent); this.smallCavesVisited = new HashSet <Cave>(parent.smallCavesVisited); // small visited once this.cantVisitSmall = parent.cantVisitSmall; this.Current = newCurrent; if (smallCavesVisited.Contains(Current)) { this.cantVisitSmall = true; } if (!Current.isBig) { smallCavesVisited.Add(Current); } }