Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Stuck on an a* pathfinding algorithm [modified]

Stuck on an a* pathfinding algorithm [modified]

Scheduled Pinned Locked Moved Algorithms
helpalgorithmsannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venomation
    wrote on last edited by
    #1

    SOLVED For anyone interested here is the solution to my problem:

        public IEnumerable<Tile> PathFind(Tile startNode, Tile endNode)
        {
            List<Tile> openNodes = new List<Tile>() { startNode };
            List<Tile> closedNodes = new List<Tile>();
            Tile lowestFScore = null;
            while (openNodes.Count > 0 && lowestFScore != endNode)
            {
                lowestFScore = GetLowestScoringTile(openNodes, endNode);
    
                openNodes.Remove(lowestFScore);
    
                if (lowestFScore == null)
                    return null;
    
                SwitchFromOpenToClosedList(lowestFScore, openNodes, closedNodes);
    
                IEnumerable<Tile> neighbouringTile = GetNeighbouringTiles(lowestFScore);
    
                foreach (Tile n in neighbouringTile)
                {
                    if (IgnoreTile(n))
                    {
                        SwitchFromOpenToClosedList(n, openNodes, closedNodes);
                        continue;
                    }
    
                    if (closedNodes.Contains(n)) continue;
    
                    if (!openNodes.Contains(n))
                    {
                        openNodes.Add(n);
                        n.Parent = lowestFScore;
                    }
                    
    
                } 
            }
    
            return RenderToGrid(endNode);
        }
    

    I have done my research and attempted several times to create my version of the infamous A* path-finding algorithm. The algorithm I have made does seem to work though!...(unsurprisingly) If anyone can help me it would be great, I am sure it is just a logic problem in the main part of the method:

    public void PathFind(Tile startNode, Tile endNode)
    {
    List<Tile> openNodes = new List<Tile>() { startNode };
    List<Tile> closedNodes = new List<Tile>();

            Tile currentNode = startNode;
            while (true)
            {
                foreach (Tile n in GetNeighbouringTiles(currentNode))
                {
                    if (closedNodes.Contains(n)) continue;
    
                    if (IgnoreTile(n))
                    {
                        if (!closedNodes.Contains(n))
                        {
                            closedNodes.Add(n);
                            continue;
                        }
                    }
    
    E E 2 Replies Last reply
    0
    • V venomation

      SOLVED For anyone interested here is the solution to my problem:

          public IEnumerable<Tile> PathFind(Tile startNode, Tile endNode)
          {
              List<Tile> openNodes = new List<Tile>() { startNode };
              List<Tile> closedNodes = new List<Tile>();
              Tile lowestFScore = null;
              while (openNodes.Count > 0 && lowestFScore != endNode)
              {
                  lowestFScore = GetLowestScoringTile(openNodes, endNode);
      
                  openNodes.Remove(lowestFScore);
      
                  if (lowestFScore == null)
                      return null;
      
                  SwitchFromOpenToClosedList(lowestFScore, openNodes, closedNodes);
      
                  IEnumerable<Tile> neighbouringTile = GetNeighbouringTiles(lowestFScore);
      
                  foreach (Tile n in neighbouringTile)
                  {
                      if (IgnoreTile(n))
                      {
                          SwitchFromOpenToClosedList(n, openNodes, closedNodes);
                          continue;
                      }
      
                      if (closedNodes.Contains(n)) continue;
      
                      if (!openNodes.Contains(n))
                      {
                          openNodes.Add(n);
                          n.Parent = lowestFScore;
                      }
                      
      
                  } 
              }
      
              return RenderToGrid(endNode);
          }
      

      I have done my research and attempted several times to create my version of the infamous A* path-finding algorithm. The algorithm I have made does seem to work though!...(unsurprisingly) If anyone can help me it would be great, I am sure it is just a logic problem in the main part of the method:

      public void PathFind(Tile startNode, Tile endNode)
      {
      List<Tile> openNodes = new List<Tile>() { startNode };
      List<Tile> closedNodes = new List<Tile>();

              Tile currentNode = startNode;
              while (true)
              {
                  foreach (Tile n in GetNeighbouringTiles(currentNode))
                  {
                      if (closedNodes.Contains(n)) continue;
      
                      if (IgnoreTile(n))
                      {
                          if (!closedNodes.Contains(n))
                          {
                              closedNodes.Add(n);
                              continue;
                          }
                      }
      
      E Offline
      E Offline
      Espen Harlinn
      wrote on last edited by
      #2

      Here is something that works: WPF: A* search[^] Regards Espen Harlinn

      V 1 Reply Last reply
      0
      • E Espen Harlinn

        Here is something that works: WPF: A* search[^] Regards Espen Harlinn

        V Offline
        V Offline
        venomation
        wrote on last edited by
        #3

        Thank Espen, I was trying to do it based on the concept, I didn't want to use other code and instead build from the concept :-D

        E 1 Reply Last reply
        0
        • V venomation

          Thank Espen, I was trying to do it based on the concept, I didn't want to use other code and instead build from the concept :-D

          E Offline
          E Offline
          Espen Harlinn
          wrote on last edited by
          #4

          Good for you!

          1 Reply Last reply
          0
          • V venomation

            SOLVED For anyone interested here is the solution to my problem:

                public IEnumerable<Tile> PathFind(Tile startNode, Tile endNode)
                {
                    List<Tile> openNodes = new List<Tile>() { startNode };
                    List<Tile> closedNodes = new List<Tile>();
                    Tile lowestFScore = null;
                    while (openNodes.Count > 0 && lowestFScore != endNode)
                    {
                        lowestFScore = GetLowestScoringTile(openNodes, endNode);
            
                        openNodes.Remove(lowestFScore);
            
                        if (lowestFScore == null)
                            return null;
            
                        SwitchFromOpenToClosedList(lowestFScore, openNodes, closedNodes);
            
                        IEnumerable<Tile> neighbouringTile = GetNeighbouringTiles(lowestFScore);
            
                        foreach (Tile n in neighbouringTile)
                        {
                            if (IgnoreTile(n))
                            {
                                SwitchFromOpenToClosedList(n, openNodes, closedNodes);
                                continue;
                            }
            
                            if (closedNodes.Contains(n)) continue;
            
                            if (!openNodes.Contains(n))
                            {
                                openNodes.Add(n);
                                n.Parent = lowestFScore;
                            }
                            
            
                        } 
                    }
            
                    return RenderToGrid(endNode);
                }
            

            I have done my research and attempted several times to create my version of the infamous A* path-finding algorithm. The algorithm I have made does seem to work though!...(unsurprisingly) If anyone can help me it would be great, I am sure it is just a logic problem in the main part of the method:

            public void PathFind(Tile startNode, Tile endNode)
            {
            List<Tile> openNodes = new List<Tile>() { startNode };
            List<Tile> closedNodes = new List<Tile>();

                    Tile currentNode = startNode;
                    while (true)
                    {
                        foreach (Tile n in GetNeighbouringTiles(currentNode))
                        {
                            if (closedNodes.Contains(n)) continue;
            
                            if (IgnoreTile(n))
                            {
                                if (!closedNodes.Contains(n))
                                {
                                    closedNodes.Add(n);
                                    continue;
                                }
                            }
            
            E Offline
            E Offline
            ely_bob
            wrote on last edited by
            #5

            .. A few comments on this, if your using XNA and want to use this code on the XBOX, you should get rid of the Foreach loop, it is a performance killer due to GC on the XBOX.... Also you should look into the weighting Heuristics, because this approach albeit closed and complete is not as efficient as it could be.... Also your sucking up memory as you use this algo... have you tested it against a large number of bots representative to the normal in game load...., I'd wadger it won't run inside your game loop propperly for more then 125 or so bots (using a 256x256 tile map).... just trying to give you the heads up...

            I'd blame it on the Brain farts.. But let's be honest, it really is more like a Methane factory between my ears some days then it is anything else...
            -----
            "The conversations he was having with himself were becoming ominous."-.. On the radio...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups