Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("systems/systems.php");
- $PossiblePaths = array();
- $PathCount = 0;
- function PlanRoute($nextID, $targetID, $history = null, $depth = 0){
- global $Systems, $PossiblePaths, $PathCount;
- //NextID is the key for the next steps to be made off of.
- $potentials = $Systems[$nextID]["JumpsTo"];
- if(!empty($potentials)){
- if(!in_array($targetID, $potentials)){ //Not at end location, therefore try next location
- $history[] = $nextID;
- $depth++;
- if($depth < 9){
- foreach($potentials as $value){
- if(!in_array($value, $history)){
- $path = PlanRoute($value, $targetID, $history, $depth);
- if(isset($path)){
- $PathCount++;
- $PossiblePaths[$PathCount] = $path;
- }
- }
- }
- }else{
- return;
- }
- }else{
- foreach($history as $SystemID){
- $Trip[] = $SystemID;
- }
- $Trip[] = $targetID;
- return $Trip;
- }
- }
- }
- function SortByElementCount($a, $b){
- if(count($a) == count($b)){
- return 0;
- }
- return (count($a) < count($b)) ? -1 : 1;
- }
- $origin = 30000070; //Get starting point
- $target = 30000001; //Get end point
- echo "Planning jump route from ".$Systems[$origin]['Name']." to ".$Systems[$target]['Name']."<br><br>\n";
- PlanRoute($origin, $target);
- usort($PossiblePaths, "SortByElementCount");
- var_dump($PossiblePaths);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment