Advertisement

Pathfinding, need feedback

Started by April 30, 2020 05:52 PM
109 comments, last by Calin 4 years, 6 months ago

started debugging

void FindPath(int Startx, int Startz, int Endx, int Endz)
{
 
for(int i =0; i < 50; i++)
{

 TrunkList[i].cold = false;
 TrunkList[i].weight = 10;
}
 
 
bool exists = false;
bool exit = false;
bool firstrun = true;
PathTile BestNode;

while(!exit)
{
 

 if(firstrun)
 {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  Startx;
    TrunkList[TrunkListCount].z =  Startz;
    TrunkList[TrunkListCount].index = TrunkListCount;
  firstrun = false;
 }
 
 
 int bestweight = 1000;
 int indexofbw = -1;
 for(int i =0; i < TrunkListCount; i ++)
 {
  if(!TrunkList[i].cold)
  {
   if(TrunkList[i].weight < bestweight)
    {
     bestweight = TrunkList[i].weight;
     indexofbw = i;
    }
  }
 
 }
   
  BestNode.x = TrunkList[indexofbw].x;
  BestNode.z = TrunkList[indexofbw].z;
  BestNode.index = TrunkList[indexofbw].index;
 
 if((BestNode.x != Endx)||(BestNode.z != Endz))
 {
  int x = BestNode.x;
  int z = BestNode.z;
   
   
  if(NodeCoord(x,z+1).access)//n
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x,z+1).x)&&(TrunkList[i].z == NodeCoord(x,z+1).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x,z+1).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x,z+1).z;
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x,z+1,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;  
     
    StringCchPrintfA(IGmessage,1024,"x %d",TrunkList[TrunkListCount].x);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"z %d",TrunkList[TrunkListCount].z);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"i %d",TrunkList[TrunkListCount].index);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
     
   }
  }
  if(NodeCoord(x+1,z+1).access)//ne
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x+1,z+1).x)&&(TrunkList[i].z == NodeCoord(x+1,z+1).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x+1,z+1).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x+1,z+1).z;
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x+1,z+1,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
     

    StringCchPrintfA(IGmessage,1024,"x %d",TrunkList[TrunkListCount].x);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"z %d",TrunkList[TrunkListCount].z);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"i %d",TrunkList[TrunkListCount].index);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
     
   }    
  }
  if(NodeCoord(x+1,z).access)//e
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x+1,z).x)&&(TrunkList[i].z == NodeCoord(x+1,z).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x+1,z).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x+1,z).z;
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x+1,z,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
    StringCchPrintfA(IGmessage,1024,"x %d",TrunkList[TrunkListCount].x);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"z %d",TrunkList[TrunkListCount].z);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"i %d",TrunkList[TrunkListCount].index);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
     
   }  
  }
  if(NodeCoord(x+1,z-1).access)//se
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x+1,z-1).x)&&(TrunkList[i].z == NodeCoord(x+1,z-1).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x+1,z-1).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x+1,z-1).z;
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x+1,z-1,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;  
    StringCchPrintfA(IGmessage,1024,"x %d",TrunkList[TrunkListCount].x);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"z %d",TrunkList[TrunkListCount].z);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
    StringCchPrintfA(IGmessage,1024,"i %d",TrunkList[TrunkListCount].index);
    MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);
   }   }
  if(NodeCoord(x,z-1).access)//s
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x,z-1).x)&&(TrunkList[i].z == NodeCoord(x,z-1).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x,z-1).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x,z-1).z;  
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x,z-1,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
    StringCchPrintfA(IGmessage,1024,"x %d",TrunkList[TrunkListCount].x);
     
   }    
  }
  if(NodeCoord(x-1,z-1).access)//sw
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x-1,z-1).x)&&(TrunkList[i].z == NodeCoord(x-1,z-1).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x-1,z-1).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x-1,z-1).z;
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x-1,z-1,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;  
   } }
  if(NodeCoord(x-1,z).access)//w
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x+1,z-1).x)&&(TrunkList[i].z == NodeCoord(x+1,z-1).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x+1,z-1).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x+1,z-1).z;
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x+1,z-1,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;  
   }}
  if(NodeCoord(x-1,z+1).access)//nw
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x-1,z+1).x)&&(TrunkList[i].z == NodeCoord(x-1,z+1).z))
    {
     exists = true;
    }
     
   }
   if(!exists)
   {
    TrunkListCount++;
    TrunkList[TrunkListCount].x =  NodeCoord(x-1,z+1).x;
    TrunkList[TrunkListCount].z =  NodeCoord(x-1,z+1).z;
    TrunkList[TrunkListCount].index = TrunkListCount;
    NodeCoord(x-1,z+1,TrunkListCount);
    TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;  
     
   }   }
  TrunkList[BestNode.index].cold = true;
 }
 else
 {
  exit = true;
 }
}

 /*StringCchPrintfA(IGmessage,1024,"Closest %d",Closest);
 MessageBox(NULL, IGmessage, "Textures.exe", MB_OK);*/
 
 


}

My project`s facebook page is “DreamLand Page”

Calin said:

as long as I have (tacit) approval from a senior I`m happy. Alberth doesn`t seem to be objecting (except the refractoring bit) so I take it I`m doing it more or less right. JoeJ and NikiTo I`m not leaving you aside I`m just giving to Caesar his share.

Another metaphoric one liner… what could it mean? What does it tell us about your progress? Was my time spend on posting a short working solution, and explaining how it works totally wasted?
What's your question about how a path finding algorithm works? IDK, so i could just make another guess on what it might be, post more code, paint more images, etc., only to waist more of my time.

All our time is wasted here. All your response only shows you bend our message so it suits what you want to hear. Alberth did not confirm you're on the right track just because he's the good cop here. No, just like me he said he can not know, because you do not tell us what you want or what you ask for.

I'm tired about your ignorance and your trolling. Intended or not it is just that.

Calin said:
started debugging

So it runs, works, job done. Thread closed.

Advertisement

Was my time spend on posting a short working solution, and explaining how it works totally wasted

No. it only means that when a senior doesn`t step in what everything else is saying (JoeJ included) is accurate. Silence from a moderator/hi ranking member means tacit approval. Since I am a beginner I can not know if what you`re saying is true or not, however if a moderator doesn`t it in a resonable amount time question what you said, your claims aquire power of truth.

My project`s facebook page is “DreamLand Page”

Calin said:
(JoeJ included)

No. Like everyone i made my point on your terrible code structure, but i accepted this and continued with what really matters: How path finding works. So my behavior is not like: 'Either refactor your mess or i won't help any further.'

Now i appreciate you respond at all. This confirms are are able to communicate.
But you use this ability mainly for self defense, and that's not enough. Use communication to describe what you try to do, what works what not. Tell us what's the remaining problem, ask how to address it.
Tell us what you think, and respond to our thoughts as well. It is a constant loop of input, processing, output, await new input. And it should never stop.

I admit i behave like an ass, which forces you more on self defense than on path finding topic. But it is a way to get started on at least something. Now we talk - and that's progress.

Keeping communication alive requires effort. For some people it is very easy and they talk all the time - for some it's harder because they never know what to talk (like me) - for some it is super hard (probably you).
So you need to work on this. Invest effort, keep trying, learn from failures and success, evolve.

And in this thread here it is obvious how your effort should look like:
We all complain about code structure, and how hard it is to read.
When i read your code, i can hardly focus on function, because my brain gets stuck in the desire to first make less code out of it, so i can better focus on function after that has been resolved. Likely it's the same for everyone.
And this is where you behave like an ass: You know we have a hard time, you want our help, but you treat us bad by resisting to refactor - if only for us.
You do not invest any effort. Why? You say you'll refactor anyways, later. So why not now? For us? To get better help?

You treat us bad by ignoring our advise. And you troll us by posting the same repetive code structure again and again.
This is not how it works. Interaction between humans is giving and taking. Trade some fish against an axe of stone. Team up, make a deal, trust each other, join forces… if only to raid some other folks.

So it's not about refactoring code, which we all assume you are able to do. The real problem is your resistance to do us a favor, while still expecting to get senior advise for free.
At this point i do no longer try to read your code, and i'm surely not the only one.

The exact same issue is: I ask the same questions multiple times, e.g. does your code work? What's the failure case? etc,. But you do not respond. ‘IDK yet’ would be enough already, but you do not invest any effort in me.
So why should i help you then?

Please think of it. It's hard to master, but it's a simple game.

Don`t worry JoeJ we are different and act differently to the same triggers. We can`t be all the same it would be boring if we were. I try to steer at tricky incoming darts.

My project`s facebook page is “DreamLand Page”

Calin said:
Silence from a moderator/hi ranking member means tacit approval.

I said lots of stuff in at least 2 posts, but you completely ignore them. No point in trying to write any more posts without proper feedback.

Advertisement

I said lots of stuff in at least 2 posts, but you completely ignore them. No point in trying to write any more posts without proper feedback.

Admitted. I will try to be more careful and will offer feedback as soon as I get some free time.

My project`s facebook page is “DreamLand Page”

Alberth said:
That depends on the algorithm you are implementing

I`m not set for any particular algorithm. I`m looking for a straightforward method i.e I`m not looking for something that`s unjustified complex.

Perhaps you should do some reading how others have solved this problem?

I can not relate to an article/paper if I don`t know the author personally. I should know the author or at least the article reference should be made by someone that I know/familiar with to some degree.

My project`s facebook page is “DreamLand Page”

Calin said:

Alberth said:
That depends on the algorithm you are implementing

I`m not set for any particular algorithm. I`m looking for a straightforward method i.e I`m not looking for something that`s unjustified complex.

Perhaps you should do some reading how others have solved this problem?

I can not relate to an article/paper if I don`t know the author personally. I should know the author or at least the article reference should be made by someone that I know/familiar with to some degree.

2nd point first:

DFS is the simplest path-finding algorithm to code. It is not very efficient, but it is the easiest to code. You will not find a “paper” because it is in every beginner's textbook. After you understand DFS, try BFS. BFS is slightly more complicated. After that learn “Dijkstra's” algorithm, which is an expansion on BFS.

Those are the basics (the inefficient basics). After you are familiar with them choose either “A Star” or “Navmesh”. “A*” if you are navigating a gird/graph (RPG, real time strategy, casual, etc… ) or Navmesh if you are navigating a full geometry (mostly for first person shooters).

Now regarding your 1st point:

Your code is unjustifiably complex. Because it lacks the most fundamental design patterns. It embarrasses me to call “functions” and “for-loops” design patterns, but they are… In a metaphor you are asking: “How do I build a house on this swampland?”. All the experienced people are face-palming and telling you not to build it on a swamp (bad coding). Your code is not regular messy code. It is a testamonial to missing basic coding knowledge. Please fix it. Please don't try to build your first house on a swamp. You might succeed through sheer determination, but it would not be an easier job than building it on rocks!

My Oculus Rift Game: RaiderV

My Android VR games: Time-Rider& Dozer Driver

My browser game: Vitrage - A game of stained glass

My android games : Enemies of the Crown & Killer Bees

Calin said:
I should know the author or at least the article reference should be made by someone that I know/familiar with to some degree.

Because gov lies to us. Knowledge must be handed from hand to hand, personally in person. OOP is an evil corp.

This topic is closed to new replies.

Advertisement