Esempio n. 1
0
 //---------------------------------------------------------------------
 void _NewStep(EbAstarStep step)
 {
     for (int idx = 0; idx < step.RoundSteps.Count; ++idx)
     {
         EbAstarRoundStep roundStep = step.RoundSteps[idx];
         EbAstarStep      childStep = roundStep.node;
         if (childStep.IsClose)
         {
             continue;
         }
         float newG = roundStep.cost + step.G;
         if (childStep.IsOpen)
         {
             if (childStep.G > newG)
             {
                 childStep.G      = newG;
                 childStep.Key    = childStep.G + childStep.H;
                 childStep.Parent = step;
             }
         }
         else
         {
             childStep.G      = newG;
             childStep.H      = EbAstarStep.Distance(childStep, mStepDest);
             childStep.Key    = childStep.G + childStep.H;
             childStep.Parent = step;
             _AddToOpen(childStep);
         }
     }
 }
Esempio n. 2
0
        //---------------------------------------------------------------------
        public bool Search(EbAstarStep src, EbAstarStep dest)
        {
            src.G   = 0;
            src.H   = EbAstarStep.Distance(src, dest);
            src.Key = src.G + src.H;

            mStepStart = src;
            mStepBest  = src;
            mStepStart.Clear();
            mStepDest = dest;

            mStepCnt = 0;

            _AddToOpen(src);

            while (mOpenHeap.Size > 0)
            {
                mStepCurrent = mOpenHeap.Pop();
                if (DestChecker.isDest(mStepCurrent))
                {
                    mStepBest = mStepCurrent;
                    return(true);
                }
                if (mStepCnt > mStepCntMax)
                {
                    return(false);
                }
                if (mStepCurrent.H < mStepBest.H)
                {
                    mStepBest = mStepCurrent;
                }
                ++mStepCnt;

                _NewStep(mStepCurrent);
                mStepCurrent.AttachNode.Detach();
                _AddToClose(mStepCurrent);
            }
            return(false);
        }
Esempio n. 3
0
 //-------------------------------------------------------------------------
 public override bool isDest(EbAstarStep step)
 {
     return(EbAstarStep.Distance(step, Dest) < Diff);
 }