Location: PHPKode > scripts > Path finder > example.php

//Example of the map-array generating function
//This pathfinder example assumes that a square map is used. To use rectangular map you need to tweak the pathfinder a bit
//Here we assign one tile in four with a heavier weight and it is less favored for finding the path
//Map is an associative array which has a key of the tile's coordinates as the base. Only required array value is 'weight' but
//you can store additional information in the array for, say, public purposes, such as tile graphic data.
function getMap(){
			} else {
	return $map;

//Currently getMap is dynamic and changes with each try, but you can send a pre-generated maps here just as easily
//as long as the weight is set for each map tile element and the array key is in XxY format
$path=new PathFinder(); //Create new pathfinder object
$path->setOrigin(1,1); //Set the start location
$path->setDestination(20,20); //Set the destination
$path->setMap($map); //Assign the map to use for calculations
$result=$path->returnPath(); //Returns an array of all the walked steps
echo '<pre>';
echo '</pre>';

Return current item: Path finder