Skip to main content

A simple pathfinding eazy to use, A*

Project description

# astar_python

using:

- from astar_python.astar import Astar

build your weight map:

```python
mat = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
]
```
Init the Astar object
```python
astar = Astar(mat)
```

Run astar with a start point and a end point like [x, y] (left to right = x, top to bottom = y
```python
result = astar.run([0, 0], [10, 9])
```
result is an array of point:
```python
print(result)
--
[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 9]]

```
If no way to the end, A* return None

give:

```python
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
```

# Weights
A weight on the matrix is the cost to cross the point.

Cost can be:

* positive: more it is positive, more it's difficult to cross the region
* negative: is like a booster, you can custom your way
* 0: a normal point
* None: not crossable

Exemple: The number '1' is the way taken, others are weights



```python
# A simple barrage
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 0, 0, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]


# It decided to cross barrage
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 0, 0, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, None, 0, 1, 1, 1, 1]

astar_python
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, -5, -5, -5, 0, 0, 0, 0, 0]
[0, 0, 1, 0, 0, 5, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 5, 0, 1, 0, 0, 0]
[0, 0, 0, 0, 0, 5, 0, 0, 1, 0, 0]
[0, 0, 0, 0, 0, 5, 0, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]

```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astar_python-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file astar_python-0.1.0.tar.gz.

File metadata

  • Download URL: astar_python-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for astar_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a6b3f149b5b7ecb8db2411f778c4ddf2f1ed65423bf754bf0d4db243aed52506
MD5 8986f67080b65f0883531a54bd7ffc02
BLAKE2b-256 f07aa6b6b8734ce0b661ec4e0676a9a1f9ffc18d454bca8a8c98cf10f4151e41

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page