ClarkeRubber

This Works

Feb 11th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. <?php
  2.  
  3. function moveOrigin($nextID, $targetID, $history, $depth){
  4.     echo "ID = $nextID <br>\n";
  5.     $Systems = $GLOBALS["Systems"];
  6.     //NextID is the key for the next steps to be made off of.
  7.     $potentials = $Systems[$nextID]["JumpsTo"];
  8.     echo "connects to: <br>\n";
  9.     foreach($potentials as $display){
  10.         echo $Systems[$display]['Name']." ($display) <br>\n";
  11.     }
  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.                         echo "Moving To: ". $Systems[$value]['Name'] ." with ID: ".$value."<br><br>\n";
  20.                         $path = moveOrigin($value, $targetID, $history, $depth);
  21.                         if(isset($path)){
  22.                             return $path;
  23.                         }
  24.                     }
  25.                 }
  26.             }else{
  27.                 return;
  28.             }
  29.         }else{
  30.             echo "TARGET LOCATION CAN BE REACHED FROM THIS LOCATION<br><br>\n";
  31.             foreach($history as $path){
  32.                 $output .= $Systems[$path]["Name"]."<br>";
  33.             }
  34.             $output .= $Systems[$targetID]["Name"];
  35.             echo "<br>Path:<br> $output <br><br>\n";
  36.             return $output;
  37.         }
  38.     }
  39. }
  40.  
  41. include("systems/systems2.php");
  42.  
  43. $origin = 30000090; //Get starting point
  44. $target = 30000011; //Get end point
  45. echo "attempting to move from, ".$Systems[$origin]['name']." with ID: ".$origin.", to ".$Systems[$target]['Name']." with ID: ".$target."<br><br>\n";
  46. $path = moveOrigin($origin, $target, null, 0);
  47. echo $path;
  48. /*
  49. array_push($History, $target);
  50.  
  51. $from = $Systems[]["Name"];
  52. $to = $Systems[$History[Count($History) - 1]]["Name"];
  53.  
  54. //echo "From: $from, To: $to -><br>";
  55.  
  56. foreach($History as $SystemID){
  57.     echo "{$Systems[$SystemID]["Name"]} ({$Systems[$SystemID]["Sec"]})<br>";
  58. };
  59. */
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment