Skip to main content

Path finding library for your projects

Project description

pathfinding

Table of content

Installation

You can install the package by running the following command : python3 -m pip install --upgrade PathFinder

Note

Please note that the package is currently in beta version and may encounter bugs or unexpected behaviours for which I am not responsible.

Known issues :

  • No cartesian coordinates for grid display available (only alphabetical coordinates)
  • Grid display is not centered and might not work in every terminal
  • The find_path method is not optimized and might take a long time to find a path

Use

Create an instance

Simply import the pathfinding object from the package into your script and start use it.

from pathfinding import PathFinder as pf

 # From Asynconf 2022 - https://asynconf.fr/
map = """
O___O_OO__OO__VO_O_O
__O___O_OOO_OO_____O
OO___O___OOO_OOOOO_O
__OO__X__OO_O___O__O
_OO___OO______O___OO
""".split("\n")

pathfinder = pf(
                        map,         # map to use (list or str)
                "X",                 # start point (str)
                "V",                 # end point (str)
                walkable="_",        # walkable tiles (str)
                non_walkable="O",    # non walkable tiles (str)
                debug_mode=False     # display processing informations (bool)
)

Steps to find a path

  1. Make a graph from the map
graph = pathfinder.make_graph()
  1. Get the first path found
path = pathfinder.find_path()
  1. Optimize the path
optimized_path = pathfinder.optimize_path(path)
  1. use the path
print(pathfinder.get_path(alphanumeric=True))
print(pathfinder.get_path(alphanumeric=False))

##################################################
['G4', 'H4', 'I4', 'I5', 'J5', 'K5', 'L5', 'M5', 'N5', 'N4', 'O4', 'P4', 'P5', 'Q5', 'R5', 'R4', 'S4', 'S3', 'S2', 'R2', 'Q2', 'P2', 'O2', 'O1']
[(6, 3), (7, 3), (8, 3), (8, 4), (9, 4), (10, 4), (11, 4), (12, 4), (13, 4), (13, 3), (14, 3), (15, 3), (15, 4), (16, 4), (17, 4), (17, 3), (18, 3), (18, 2), (18, 1), (17, 1), (16, 1), (15, 1), (14, 1), (14, 0)]

Display the path

print(pathfinder.show_path(show_grid=True, animate=False))

##################################################
# displays the path on the map. If animate is True, the path will be displayed step by step and the screen will be cleared after each step

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

petchou_pathfinder-0.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

petchou_pathfinder-0.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file petchou_pathfinder-0.0.1.tar.gz.

File metadata

  • Download URL: petchou_pathfinder-0.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Windows/10

File hashes

Hashes for petchou_pathfinder-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3dbfb4c13118c80597eb853909e03fa57c1d25074be7a88ca61bb5ff7f52fd8e
MD5 7110ef84fbe045e8cec5433f64e7313b
BLAKE2b-256 1036ec9f6d261dcfca914d249f2a488f500495b724cbfe060d4917400305bb3e

See more details on using hashes here.

File details

Details for the file petchou_pathfinder-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for petchou_pathfinder-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8a1ff818f43728713800de416ef08d66eefbcdec0d087a3983983127c8fdf7b
MD5 9daab31762e7b379393f65d3545ac37c
BLAKE2b-256 123a39564146a2c528e1418e8edd7a6f9e7d961541bed9b83118ae3907b890af

See more details on using hashes here.

Supported by

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