Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:04:00+00:00 2026-06-01T21:04:00+00:00

My path-finding works fine when moving with no obstacles or when moving from the

  • 0

My path-finding works fine when moving with no obstacles or when moving from the top to the side of an obstacle but when it needs to find it’s way from the top to the bottom of an obstacle it is too slow.

I’m fairly sure it’s the way I am sorting each loop or looping though the closed set but I’m not sure how to avoid this as SortedLists are not available on windows phone 7

//This Vivid Destination means it doesn't have to find the exact location 
//which is helpful as it is continuous environment  
Rectangle vividDestination = new Rectangle((int)character.destination.X - 10, (int)character.destination.Y - 10, 20, 20);

while (!vividDestination.Contains(Maths.vectorToPoint(OpenNodes[0].position)))
{
    Node Current = OpenNodes[0];
    OpenNodes.RemoveAt(0);
    ClosedNodes.Add(Current);
    Current.calculateNeightbours();

    foreach (Node neighbour in Current.neighbours)
    {
        neighbour.parents = Current.parents + 1;
        //The cost of the node is the amount of parent nodes + the distance to destination
        neighbour.cost = calculateCost(neighbour.position, character.destination, neighbour.parents);

        for (int i = 0; i < OpenNodes.Count; i++)
        {
            //Round Vector rounds the floats in the Vector to the nearest integer
            if (Maths.roundVector(OpenNodes[i].position) == Maths.roundVector(neighbour.position) && OpenNodes[i].parents < neighbour.parents)
            {
                break;
            }
            else
            {
                OpenNodes.RemoveAt(i);
                OpenNodes.Add(neighbour);
                i--;
                break;
            }
        }

        bool closedNode = false;
        for (int i = 0; i < ClosedNodes.Count; i++)
        {
            if (Maths.roundVector(ClosedNodes[i].position) == Maths.roundVector(neighbour.position))
            {
                closedNode = true;
                break;
            }
        }

        if (!closedNode)
        {
            OpenNodes.Add(neighbour);
        }
    }

    OpenNodes = OpenNodes.OrderBy(item => item.cost).ToList();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:04:01+00:00Added an answer on June 1, 2026 at 9:04 pm

    What you are doing is horribly inefficient. The sorting of the list takes n*log(n) time, and you sort the list once for each vertex in the graph. This result in an algorithm that takes V^2*log(V) time, where V is the number of vertices.
    If you simply keep an unsorted list then you can extract the minimum in linear time by looping over all the items and keeping count of the lowest one so far. In this case, the time becomes V^2. This is only a tiny improvement.
    Of course, if you use a proper priority queue (like one based on a Binary Heap) then the algorithm will run much, much faster still since then operations only cost log(n). Coding your own binary heap is not too difficult and it’s something I would strongly recommend you do if the platform doesn’t support one natively. In this case insertion and finding the minimum only take log(n) time, resulting in a E log V time (where E is the number of edges, which in a planar graph is proportional to V).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement Pacman. It works fine, but so far, the ghosts aren't
I have this which is probably a roundabout way of finding the path: <?php
Is there a way I can keep the jars on my build path from
I'm facing a path finding problem in which I have to find every possible
I've been reading about path-finding algorithms and I'm currently looking for one that works
I'm looking at definitions of the A* path-finding algorithm, and it seems to be
So, I understand the problem of finding the longest simple path in a graph
I have been trying to write a shortest path algorithm, dijkstras algorithm, finding the
My python program (Python 2.6) works fine when I run it using the Python
I did a project a while back on path finding with quadtrees and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.