1. Go to this page and download the library: Download jmgq/a-star library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jmgq / a-star example snippets
use JMGQ\AStar\DomainLogicInterface;
class DomainLogic implements DomainLogicInterface
{
// ...
public function getAdjacentNodes(mixed $node): iterable
{
// Return a collection of adjacent nodes
}
public function calculateRealCost(mixed $node, mixed $adjacent): float | int
{
// Return the actual cost between two adjacent nodes
}
public function calculateEstimatedCost(mixed $fromNode, mixed $toNode): float | int
{
// Return the heuristic estimated cost between the two given nodes
}
// ...
}
use JMGQ\AStar\AStar;
$domainLogic = new DomainLogic();
$aStar = new AStar($domainLogic);
interface NodeIdentifierInterface
{
public function getUniqueNodeId(): string;
}
use JMGQ\AStar\Node\NodeIdentifierInterface;
class Position implements NodeIdentifierInterface
{
private int $row;
private int $column;
// ...
public function getUniqueNodeId(): string
{
return $this->row . 'x' . $this->column;
}
// ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.