// public static Node DLS(Node Start, State Goal, int depthLimit) { var successors = new List <Node>(); var s = new Stack <Node>(); s.Push(Start); while (s.Count != 0) { Node Parent = s.Pop(); if (Parent.State.Pegs[2].Count == Goal.Pegs[2].Count) { return(Parent); //break; } if (Parent.Depth == depthLimit) { continue; } else { successors = Parent.Expand(); for (int i = 0; i < successors.Count; i++) { var temp = successors[i]; s.Push(temp); } }//end else } return(null); }
}//end method public static Node DLS(Node Start, State Goal, int depthLimit, ref bool Cut_off) { var successors = new List <Node>(); List <Node> children = new List <Node>(); Stack <Node> Fringe = new Stack <Node>(); Fringe.Push(Start); while (Fringe.Count != 0) { Node Parent = Fringe.Pop(); if (Parent.state.Pegs[2].Count == Goal.Pegs[2].Count) { Cut_off = true; return(Parent); //break; }//end if if (Parent.depth == depthLimit) { continue; } else { children = Parent.Expand(); for (int i = 0; i < children.Count; i++) { var State = children[i]; Fringe.Push(State); //Node Tem = new Node(State); //Fringe.Push(Tem); } //end for } //end else } //end while return(null); } //end method
// public static Node BFS(Node node, State Goal) { var successors = new List <Node>(); var q = new Queue <Node>(); q.Enqueue(node); while (q.Count != 0) { Node Parent = q.Dequeue(); if (Parent.State.Pegs[2].Count == Goal.Pegs[2].Count) { //Console.WriteLine("Find Goal " + Parent.state); return(Parent); //break; }//end if successors = Parent.Expand(); for (int i = 0; i < successors.Count; i++) { Node Temp = new Node(successors[i]); q.Enqueue(Temp); }//end for // } return(null); }
} //end method // // // public static void Bidirectional_Search(Node Start, Node Goal) { var Children_1 = new List <Node>(); var Children_2 = new List <Node>(); Queue <Node> Fringe_IN = new Queue <Node>(); Queue <Node> Fringe_GO = new Queue <Node>(); Fringe_IN.Enqueue(Start); Fringe_GO.Enqueue(Goal); while ((Fringe_IN.Count != 0) && (Fringe_GO.Count != 0)) { Node Parent1 = (Node)Fringe_IN.Dequeue(); if ((Equ(Parent1, Goal)) || Contain(Fringe_GO, Parent1)) { Console.WriteLine(); Console.WriteLine("Find Goal " + Parent1.state.ToString()); break; }//end if Children_1 = Parent1.Expand(); for (int i = 0; i < Children_1.Count; i++) { Fringe_IN.Enqueue(Children_1[i]); }//end for Node Parent2 = (Node)Fringe_GO.Dequeue(); if ((Equ(Parent2, Start)) || Contain(Fringe_IN, Parent2)) { Console.WriteLine(); Console.WriteLine("Find Goal " + Parent2.state.ToString()); break; }//end if Children_2 = Parent2.Expand(); for (int i = 0; i < Children_2.Count; i++) { Fringe_GO.Enqueue(Children_2[i]); } //end for } //end while } //End Method