コード例 #1
0
ファイル: AStarContext.cs プロジェクト: end1220/PathFinding
 public void RemoveFromClosedList(ProcessingNode node)
 {
     if (closedList != null)
     {
         ProcessingNode prevNode = null;
         ProcessingNode curNode  = closedList;
         while (curNode != null)
         {
             if (node.astarNode.id == curNode.astarNode.id)
             {
                 if (prevNode != null)
                 {
                     prevNode.next = curNode.next;
                 }
                 else
                 {
                     closedList = curNode.next;
                 }
                 curNode.next = null;
                 break;
             }
             prevNode = curNode;
             curNode  = curNode.next;
         }
     }
 }
コード例 #2
0
ファイル: AStarContext.cs プロジェクト: end1220/PathFinding
 public void Reset()
 {
     astarNode = null;
     g         = 0;
     h         = 0;
     f         = 0;
     prev      = null;
     next      = null;
 }
コード例 #3
0
ファイル: AStarContext.cs プロジェクト: end1220/PathFinding
 public void SetRequest(AStarRequest request)
 {
     currentRequest = request;
     openList       = null;
     closedList     = null;
     for (int i = 0; i < nodes.Length; ++i)
     {
         nodes[i].Reset();
     }
 }
コード例 #4
0
ファイル: AStarContext.cs プロジェクト: end1220/PathFinding
 public void ResizeNodes(int size)
 {
     if (nodes.Length < size)
     {
         nodes = new ProcessingNode[size];
         for (int i = 0; i < size; ++i)
         {
             nodes[i] = new ProcessingNode();
         }
     }
 }
コード例 #5
0
ファイル: AStarContext.cs プロジェクト: end1220/PathFinding
        public ProcessingNode GetNode(AStarNode node)
        {
            int index = node.id;

            if (index >= nodes.Length)
            {
                int newLength = System.Math.Max(1, (int)(index * 1.5f));
                ResizeNodes(newLength);
            }
            ProcessingNode proNode = nodes[index];

            proNode.astarNode = node;
            return(proNode);
        }
コード例 #6
0
ファイル: AStarContext.cs プロジェクト: end1220/PathFinding
        public ProcessingNode FindInClosedList(ProcessingNode node)
        {
            if (closedList == null)
            {
                return(null);
            }
            else
            {
                ProcessingNode curNode = closedList;
                while (curNode != null)
                {
                    if (curNode.astarNode.id == node.astarNode.id)
                    {
                        return(curNode);
                    }

                    curNode = curNode.next;
                }

                return(null);
            }
        }
コード例 #7
0
ファイル: AStarContext.cs プロジェクト: end1220/PathFinding
 public void AddToClosedList(ProcessingNode node)
 {
     if (closedList == null)
     {
         closedList = node;
         node.next  = null;
     }
     else
     {
         ProcessingNode prevNode = null;
         ProcessingNode curNode  = closedList;
         while (curNode != null)
         {
             if (node.f < curNode.f || (node.f == curNode.f && node.g < curNode.g))
             {
                 node.next = curNode;
                 if (prevNode != null)
                 {
                     prevNode.next = node;
                 }
                 else
                 {
                     closedList = node;
                 }
                 break;
             }
             else if (curNode.next == null)
             {
                 curNode.next = node;
                 node.next    = null;
                 break;
             }
             prevNode = curNode;
             curNode  = curNode.next;
         }
     }
 }