PHPackages                             blackscorp/astar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. blackscorp/astar

ActiveLibrary

blackscorp/astar
================

AStar path finding implementation in php

v1.2.0(8y ago)542.7k↓17.8%14[1 issues](https://github.com/BlackScorp/astar/issues)MITPHP

Since Mar 10Pushed 3y ago4 watchersCompare

[ Source](https://github.com/BlackScorp/astar)[ Packagist](https://packagist.org/packages/blackscorp/astar)[ RSS](/packages/blackscorp-astar/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (7)Used By (0)

A-Star
------

[](#a-star)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b46e77e95ba14c3422d4efb6bc99153746ea33f1d8a83dda4c88e2818e8fc5a5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426c61636b53636f72702f61737461722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/BlackScorp/astar/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/3044c572efc920ba821b1ea5355040e77364e563d4175ea057d3cd9806db9915/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426c61636b53636f72702f61737461722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/BlackScorp/astar/?branch=master)[![Build Status](https://camo.githubusercontent.com/616340cc3ced45e5b74acfa4e158fa5fdb8361d58fbf92a5f0e095d88cef5739/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426c61636b53636f72702f61737461722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/BlackScorp/astar/build-status/master)

[A-star](https://en.wikipedia.org/wiki/A*_search_algorithm) is a path finding algorithm, written in PHP. It can find the shortest path between two points in a two dimensional array by using different heuristics.

Installation
------------

[](#installation)

```
composer require blackscorp/astar

```

Usage
-----

[](#usage)

first create a two dimensional array for your map

```
  $map = [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1],
            [0, 0, 0, 1, 0],
        ];
```

each key represent the x and y position of the map. each value of the array represents the costs, A-star tries to find a way with lowest costs. you can use negative keys if your map requires it.

next convert the array to a Grid, a Grid is a collection of Nodes.

```
$grid = new BlackScorp\Astar\Grid($map);
```

now you can fetch nodes from the Grid like so

```
$startPosition = $grid->getPoint(3,1);
$endPosition = $grid->getPoint(0,0);
```

at the end pass the grid to the astar and search for the shortests path

```
$astar = new BlackScorp\Astar\Astar($grid);
$nodes = $astar->search($startPosition,$endPosition);
if(count($nodes) === 0){
   echo "Path not found";
}else{
  foreach($nodes as $node){
     echo $node->getY().'/'.$node->getX().'';
  }
}
```

Settings
--------

[](#settings)

by default diagonal directions are disabled, they can be enabled like so

```
$astar->enableDiagonal();
```

as soon as the diagonal option is enabled, the algorithm use the [Manhattan](http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html) heuristic to find the shortest path.

Manhattan is not precise but the caluclation costs are low, however you can use another heuristics like Diagonal or Euclidean with following code.

```
$astar->setHeuristic(new BlackScorp\Astar\Heuristic\Euclidean());
```

you can also create a custom heuristic.

Block locations
---------------

[](#block-locations)

there are cases where you want to block a specific path completly, independant of the costs, you can do so with following code

```
astar->blocked([3,2]);
```

this basicly means that in the initial map

```
  $map = [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 2, 2, 0, 0],
            [0, 3, 0, 1, 1],
            [0, 0, 0, 1, 0],
        ];
```

the values 3 and 2 cannot be passed.

Contribute
----------

[](#contribute)

Please feel free to make pull requests, there is still place for improvement, the Grid contains a two dimensional array which might be replaced by an SplFixedArray or something similar.

Run the tests to be sure nothing break.

License
-------

[](#license)

A-Star is free software distributed under the terms of the MIT license.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~191 days

Total

4

Last Release

3090d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c695b72ad212388273e2cf5b7ce254d2eac880d3b4f737d1bab4c228ea15962?d=identicon)[BlackScorp](/maintainers/BlackScorp)

---

Top Contributors

[![micheleangioni](https://avatars.githubusercontent.com/u/7933034?v=4)](https://github.com/micheleangioni "micheleangioni (3 commits)")[![BlackScorp](https://avatars.githubusercontent.com/u/765140?v=4)](https://github.com/BlackScorp "BlackScorp (2 commits)")[![aigarszuika](https://avatars.githubusercontent.com/u/46318312?v=4)](https://github.com/aigarszuika "aigarszuika (1 commits)")

### Embed Badge

![Health badge](/badges/blackscorp-astar/health.svg)

```
[![Health](https://phpackages.com/badges/blackscorp-astar/health.svg)](https://phpackages.com/packages/blackscorp-astar)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
