Advertisement

Pathfinding, need feedback

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

I haven`t run this code a single time it`s still at the pseudo-code level

while(!exit)
{
 PathTile BestNode;

 if(firstrun)
 {
  BestNode.x = Startx;
  BestNode.z = Startz;
  firstrun =false;
 }

 BestNode.weight = 1000;
 for(int i =0; i < TrunkListCount; i ++)
 {
  if(!BestNode.cold)
  {
   if(TrunkList[i].weight < BestNode.weight)
   {
  BestNode.weight = TrunkList[i].weight;
  BestNode.x = TrunkList[i].x;
  BestNode.z = TrunkList[i].z;
  }
  }
 
 }
 
 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)&amp;&amp;(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;  
     
   }
  }
  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)&amp;&amp;(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)//e
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x+1,z).x)&amp;&amp;(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;  
     
   }  
  }
  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)&amp;&amp;(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,z-1).access)//s
  {
   exists = false;
   for(int i =0; i < TrunkListCount; i++)
   {
    if((TrunkList[i].x == NodeCoord(x,z-1).x)&amp;&amp;(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;  
   }    
  }
  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)&amp;&amp;(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)&amp;&amp;(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)&amp;&amp;(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;  
   }   }
 }
 else
 {
  exit = true;
 }
}

My project`s facebook page is “DreamLand Page”

You never update ‘BestNode’, so the code would just loop until it crashes

I updated the while loop head also I will have this at the end

  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[??].cold = true; // set best node to cold
 }
 else
 {
  exit = true;
 }

My project`s facebook page is “DreamLand Page”

Advertisement

I assume what you are missing is this case:

Imagine we expand paths from the source (where the goal is does not matter). So we get a star shaped pattern of paths all originating from the source.

Then, we expand one end to add another segment (red), and from the newly reached cell we also add paths to all adjacent cells (green).

Next, we expand a different end of the given paths (blue):

And we also expand to its neighbors, visiting nodes that have been visited before already from the green step.

Now it could happen the new path to the same node is shorter than the old one (!)

This means we need to update the path pointer to the previous cell. Green made light gray path, but now we replace it with the better one in dark gray.
To know which paths are shortest, we also need to keep track of path length to source per cell, and update this too.

One could explain this better i guess, but i became rusty with pathfinding - have not touched this for a year.

I think i start to understand the awesomeness of the algorithm of Calin.
I start to think it is very genius.
I mean, maybe only two persons in this world could have came up with such a great idea - Elon Musk and Calin. Nobody else.

I am !serious

Manually unrolling the loops and manually inlining the functions in order to gain the best performance - simply !genius
I start to see it now.

NikiTo said:
Manually unrolling the loops and manually inlining the functions in order to gain the best performance - simply !genius I start to see it now.

Too bad the instruction stream is also coming from main memory, increasing memory bandwidth pressure.

@Alberth Seriously?!

Advertisement

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.

My project`s facebook page is “DreamLand Page”

Alberth said:
Too bad the instruction stream is also coming from main memory, increasing memory bandwidth pressure.

OH, pathfinding and pressure. This must be an engine for a steampunk game.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Finding the shortest path between Earth and Mars is a computationally heavy problem many geniuses tried to solve for years.
I dived into the Linux community today and passed through all the colors of hats. Red, white, gray, green hats. Every hat representing a level of hackership one more advanced than the other.
Somewhere near the pink hat, an anonymous hacker wearing the vendetta mask told me that there is something called GPIF. General Programming for IFs. This anonymous hacker-wizard wearing a mask of vendetta, explained me that CPUs have hidden silicon handling IFs and every time we code a piece of code in the way society and corporations brain-washed us to use, the silicon handling the IFs is dormant. But if we reveal against the norms, we could make use of the IFs in a way the code becomes 40 times faster!!!!!

I add some code snipped to show how it works… (not compiled it yet it is only a vendetta-code)

Please, put everything you do aside, take one liter of coffee and read my code very carefully various times in order to understand it. It is worth it!

var realBiasIhaveInMind = 5.5;

var auxiliaryBias = 0.0003;

// if you inline this everywhere in the code, this will purge the hidden general AI of the compiler, the gov doesn't want us to know about

// for now i will use the norm, but later i will remove that forcedly imposed by the corps rule

var valueToCompareAgainstTheRealBias = OS.IO.directRAMAccessOvertheINternet(myLambdaHack.generateLambda("repeatUntilTrue", validatePortValue(generateAnnonymousHiddenUnknownSecretValue()))));

// every turboIf() is a Macro that my personal interpreter will detect before compilation and overwrite with a good stream of nested IF
// the good IF generates "times:" times other IFs under the hood in order to awake the powers of the dormant CPU hardware, only intel and anonymous know about.
turboIf(times:1000 (myForLoopHack("tellPrecompileParserToBreadWhatIsOutsideTheFirstLEvelOfComas", times: 10, emulatedQuantumCompare(valueToCompareAgainstTheRealBias, SIMDrandomize1or0() * auxiliaryBias PrecompileMacro.call(randomizeProgramingStatements("+", "-")) realBiasIhaveInMind, true, true))) {
// NOTE: emulatedQuantumCompare() has the two other conditions of the quarnary comparison always set to true, because the gov doesn't give me aquantum computer yet(try to run the code putting something other than "true" in case you got a rea lwuantum computer instead a normal PC and you don't know it. If you turn off the sound of the speech of Trump and try to read his leaps, you will learn that the gov sometimes accidentally sell quantum computers instead regular computers, but there is no way to tell the difference, because the moment you look at the quantum computer it becomes a normal computer. Only way to know is to play with the "true"s inside this quantum compare, so it worths a try)
if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) { // "<<<<" if a boring "<" sign, but Turbo-ed by 8bit old school ASM magic
 // the cryptographic pre-compile time parser will obfuscate parts of the code with "[TOP SECRET]", in order for me to can show my code to potentional buyers withot them being able to steal it from me
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
 if (valueToCompareAgainstTheRealBias <<<< [TOP SECRET]) {
  injectToASM(!!!!!!!!!!!!!!!!true); // sorry, but i had to obfuscate the return value, because this way a human bruteforce atack will be impossible. It takes too much time for a human to figure out the outcome of "!!!!!!!!!!!!!!!!!!true", so bruteforce atacks by humans are nearly impossible
 })}
 }
 }}}})))})) // another obfuscation against code-readers with bad intentions. The General AI of my pre-macro-s parser will fix this mess. Don't worry, Type anything here. It will never break.
 }
}
}


Notice it could have some minor errors. This is the alpha version of my code. More to come.
If you find some error in my code, please report it to me. You greatly help me. But never forget though, the next version of the code could be completely different. So try to report only the bugs who seem to persist between versions.

Sharing my GPIF hack magic with you is my gratitude for your help with my code.
And remember- “The Mario Princess is Naked!”

(You can find the content of [TOP SECRET] inside the config files, in case you wonder, I did not encrypt them, because every time we use the SIMD AES instructions of the CPU, our passwords are sent to the government, so it is better to have it in plain text. The CPU will read that it is secret and try to decrypt ti, but it is already decrypted so the output will be encryptedly sent to the gov. Another thing Windows users don't know…)

(NOTE: before trying to compile my code snipped, put your computer inside a faraday cage so the gov can not see what you are doing. Any tin foil will do)

\\\\\\\forumEngine.DestroyThisMessageAfter("minutes", 100);

PROOF-

this code

if (variable == true) activateQuantum();

produces

cmp bla, bla
je blablabla

BUT this code

if (variable ? true : false) activateQuantum();

produces

hmcpuact
cmp bla, bla
je blablabla

hmcpuact means hidden mode cpu activated

Gov will never tell you that.

This topic is closed to new replies.

Advertisement