summaryrefslogtreecommitdiffstats
path: root/includes/pathing.php
blob: fc07f0bdf005a4f160fa18cf55800a078576d387 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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 />";
}

?>