diff options
Diffstat (limited to 'includes/pathing.php')
-rw-r--r-- | includes/pathing.php | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/includes/pathing.php b/includes/pathing.php new file mode 100644 index 0000000..fc07f0b --- /dev/null +++ b/includes/pathing.php @@ -0,0 +1,108 @@ +<?PHP
+//
+function FindPath($mapMatrix)
+{
+ //FindPath will generate a string consisting of the moves made by the
+ // puppy to reach each checkpoint and then the finish.
+
+ $status = array(); //This stores the search status of each tile
+ // in the grid.
+ //-2 - Unprocessed; -1 - Queued; [x] - Processed/Previous tile
+
+ $queue = array(); //This is the order to check tiles in, to
+ // prevent overcommitting. Stores TileID.
+
+ $targets = array(); //This is the queue of targets the path must connect. Flags.
+
+ $finish = array(); //This is the set of finish tiles. Stores TileID.
+
+ $path = ""; //This is a string of the moves taken by the
+ // puppy!
+ //1 - Up; 2 - Right; 3 - Down; 4 - Left
+
+ //Initialize $status
+ for( $i = 0; $i < count($mapMatrix); $i++)
+ {
+ $status[i] = array();
+ for( $j = 0; $j < count($mapMatrix[$i]); $j++)
+ {
+ $status[i][j] = -1;
+ }
+ }
+
+ //Initialize $queue with tiles adjacent to Starts
+ //Assuming the LEFT column is entirely composed of Start tiles...
+ // NOTE: This is what we would change should the Start tiles become different.
+ for( $i = 1; $i <= $mapMatrix[0][1]; $i++)
+ {
+ $status[1][$i] = 0;
+ $nextTile = GetTileID($mapMatrix, 2, $i);
+ $queue[($i-1)] = $nextTile;
+ }
+
+ //Initialize $finish queue with Finish tiles.
+ //Assuming the RIGHT column is entirely composed of Finish tiles...
+ // NOTE: This is what we would change should the Finish tiles become different.
+ for( $i = 1; $i <= $mapMatrix[0][1]; $i++)
+ {
+ echo "Tile #".GetTileID($mapMatrix, $mapMatrix[0][0] - 1, $i)." has been marked as a Finish tile.<br />";
+ $nextTile = GetTileID($mapMatrix, $mapMatrix[0][0] - 1, $i);
+ $finish[($i-1)] = $nextTile;
+ }
+
+ //Initialize $targets with Checkpoints and Finish.
+ switch($mapMatrix[0][2])
+ {
+ case 3: array_push($targets, 'C');
+ case 2: array_push($targets, 'B');
+ case 1: array_push($targets, 'A');
+ }
+ array_reverse($targets);
+ array_push($targets, 'Finish');
+
+ print_r($queue);
+ echo "<br />";
+
+ while(count($queue) > 0)
+ {
+ $nextSearch = array_shift($queue);
+ $idFinish = array_shift($targets);
+ }
+
+ /*
+ echo "Pre-PrintArray. <br />";
+ print_r($queue);
+ echo "Post-PrintArray. <br />";
+ */
+
+ //Search($mapMatrix, $loc, $path);
+
+ return $path;
+}
+
+function Search($mapMatrix, $idStart, $idFinish, $path)
+{
+
+}
+
+function GetTileID($mapMatrix, $x, $y)
+{
+ //echo "Request for TileID of (".$x.",".$y."): ";
+ if($mapMatrix[0][0] >= $x && $mapMatrix[0][1] >= $y)
+ return $mapMatrix[0][0] * ($y-1) + $x;
+ else return -1;
+}
+
+//WOULD be a function if not for overhead of calling a function and
+// inconvenience of returning an array. Here to display formula.
+
+function GetTileCoordinates($mapMatrix, $tileID)
+{
+ $x = $tileID % $mapMatrix[0][0];
+ $y = (int)($tileID / $mapMatrix[0][0]) + 1;
+
+ echo "(".$x.",".$y.")";
+ echo "<br />";
+}
+
+?>
\ No newline at end of file |