ClarkeRubber

idc

Feb 10th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2. include("systems.php");
  3.  
  4.  
  5. $History = array();
  6.  
  7. function moveOrigin($nextID, $targetID, $history, $depth){
  8.     global $Systems;
  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.             array_push($history, $nextID);
  15.             $depth++;
  16.             if($depth < 9){
  17.                 foreach($potentials as $value){
  18.                     if(!in_array($value, $history)){
  19.                         if(isset(moveOrigin($value, $targetID, $history, $depth) = $output)){
  20.                             return $output;
  21.                         }
  22.                     }
  23.                 }
  24.             }else{
  25.                 return;
  26.             }
  27.         }
  28.         foreach($history as $systemID){
  29.             $output .= "{$Systems[$SystemID]["Name"]} ({$Systems[$SystemID]["Sec"]})<br>\n";
  30.         }
  31.         $output .= "{$Systems[$targetID]["Name"]} ({$Systems[$targetID]["Sec"]})<br>\n";
  32.         return $output;
  33.     }
  34. }
  35.  
  36. $origin = 30000142; //Get starting point
  37. $target = 30000001; //Get end point
  38.  
  39. moveOrigin($origin, $target, array(), 0);
  40. array_push($History, $target);
  41.  
  42. $from = $Systems[$History[0]]["Name"];
  43. $to = $Systems[$History[Count($History) - 1]]["Name"];
  44.  
  45. echo "From: $from, To: $to -><br>";
  46.  
  47. foreach($History as $SystemID){
  48.     echo "{$Systems[$SystemID]["Name"]} ({$Systems[$SystemID]["Sec"]})<br>";
  49. };
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment