コード例 #1
0
 public List <MapNodes.Node> FindBFSPath()
 {
     mapNodes.ResetNodes();
     queueNodes = new Queue <MapNodes.Node>();
     queueNodes.Enqueue(mapNodes.GetSelectedNode(start));
     while (queueNodes.Count > 0)
     {
         MapNodes.Node next = queueNodes.Peek();
         if (next.isEnd)
         {
             while (next != mapNodes.GetSelectedNode(start))
             {
                 nodeList.Add(next);
                 next = next.parent;
             }
             return(nodeList);
         }
         else
         {
             if (isEligibleNode(next.index + 1))
             {
                 QPush(next.index + 1, next);
             }
             if (isEligibleNode(next.index - 1))
             {
                 QPush(next.index - 1, next);
             }
             if (isEligibleNode(next.index - mapNodes.width))
             {
                 QPush(next.index - mapNodes.width, next);
             }
             if (isEligibleNode(next.index + mapNodes.width))
             {
                 QPush(next.index + mapNodes.width, next);
             }
         }
         queueNodes.Dequeue();
     }
     return(null);
 }
コード例 #2
0
 private void QPush(int i, MapNodes.Node n)
 {
     mapNodes.nodeGrid[i].parent  = n;
     mapNodes.nodeGrid[i].visited = true;
     queueNodes.Enqueue(mapNodes.nodeGrid[i]);
 }