示例#1
0
        public state[] AS()
        {
            //thinking thinkform = new thinking();
            //thinkform.Show();
            Heap fring = new Heap(100000000);

            P.firststate.f = h(P.firststate);
            fring.Insert(P.firststate);
            while (true)
            {
                if (fring.IsEmpty())
                {
                    state[] SOLUTION = new state[1];
                    SOLUTION[0].lastaction = "failure";
                    return(SOLUTION);
                }
                state a = fring.Remove();
                //  if(a.Kseted)
                //      thinkform.showstate(a);
                //  thinkform.Refresh();
                //Thread.Sleep(50);
                if (P.GoalTest(a))
                {
                    thinkform.Hide();
                    state[] SOLUTION = new state[a.g];
                    int     i        = 0;
                    state   s        = a;
                    while (s.getparent() != null)
                    {
                        SOLUTION[i] = s;
                        i++;
                        s = s.getparent();
                    }
                    Array.Reverse(SOLUTION);
                    return(SOLUTION);
                }
                else
                {
                    foreach (state s in P.Succesorfunction(a))
                    {
                        if (!s.Kseted)
                        {
                            continue;
                        }
                        s.setparent(a);
                        s.f = h(s) + s.g;
                        if (!fring.Insert(s))
                        {
                            Console.WriteLine("OUT OF MEMORY");
                            state[] SOLUTION = new state[1];
                            SOLUTION[0].lastaction = "fring is out of memory";
                            return(SOLUTION);
                        }
                    }
                }
            }
        }