ClarkeRubber

Good

Feb 11th, 2012
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2. include("systems/systems.php");
  3.  
  4. $PossiblePaths = array();
  5. $PathCount = 0;
  6.  
  7. function PlanRoute($nextID, $targetID, $history = null, $depth = 0){
  8.     global $Systems, $PossiblePaths, $PathCount;
  9.    
  10.     //NextID is the key for the next steps to be made off of.
  11.     $potentials = $Systems[$nextID]["JumpsTo"];
  12.     if(!empty($potentials)){
  13.         if(!in_array($targetID, $potentials)){ //Not at end location, therefore try next location
  14.             $history[] = $nextID;
  15.             $depth++;
  16.             if($depth < 9){
  17.                 foreach($potentials as $value){
  18.                     if(!in_array($value, $history)){
  19.                         $path = PlanRoute($value, $targetID, $history, $depth);
  20.                         if(isset($path)){
  21.                             $PathCount++;
  22.                             $PossiblePaths[$PathCount] = $path;
  23.                         }
  24.                     }
  25.                 }
  26.             }else{
  27.                 return;
  28.             }
  29.         }else{
  30.             foreach($history as $SystemID){
  31.                 $Trip[] = $SystemID;
  32.             }
  33.             $Trip[] = $targetID;
  34.             return $Trip;
  35.         }
  36.     }
  37. }
  38.  
  39. $origin = 30000090; //Get starting point
  40. $target = 30000011; //Get end point
  41.  
  42. echo "Planning jump route from ".$Systems[$origin]['Name']." to ".$Systems[$target]['Name']."<br><br>\n";
  43. PlanRoute($origin, $target);
  44.  
  45. var_dump($PossiblePaths);
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment