ClarkeRubber

Single Jump Solved

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