Exemple #1
0
{
    $map = array();
    for ($x = 1; $x <= 20; $x++) {
        for ($y = 1; $y <= 20; $y++) {
            $rand = rand(1, 4);
            if ($rand == 1) {
                $map[$x . 'x' . $y] = array('weight' => '3.0');
            } else {
                $map[$x . 'x' . $y] = array('weight' => '1.0');
            }
        }
    }
    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
$map = getMap();
require 'class.pathfinder.php';
$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>';
print_r($result);
echo '</pre>';