Monday, May 30, 2011

Part III: Breadth First Search

Lets from here begin to code the uninformed Search Strategies:
v      Breadth First Search
public static void Breadth_First_Search(Node Start, Node Goal)
        {
            GetSucc x = new GetSucc();
            ArrayList children = new ArrayList();
            Queue Fringe = new Queue();
            Fringe.Enqueue(Start);
            while (Fringe.Count != 0)
            {
                Node Parent = (Node)Fringe.Dequeue();
                Console.WriteLine("Node {0} Visited ", Parent.State);
                //Console.ReadKey();
                if (Parent.State == Goal.State)
                {
                    Console.WriteLine();
                    Console.WriteLine("Find Goal   " + Parent.State);
                    break;
                }//end if
                children = x.GetSussessor(Parent.State);
                for (int i = 0; i < children.Count; i++)
                {
                    int State = (int)children[i];
                    Node Tem = new Node(State, Parent);
                    Fringe.Enqueue(Tem);
                }//end for
            }//end while
        }//end method

No comments:

Post a Comment