Skip to main content

A simplistic A* path search tool

Project description

python-astar

Yet another A* path search algorithm.

This is one more A star implementation done for fun and I hope someone might find this useful.

You can import this module and use it to find the shortest path in a map given by a matrix.

There also a procedural implementation in the examples/basic.py file that will probably be more easy to read and didactic in case you are learning how A* works.

install:

    pip install python-astar

usage:

    from astar.search import AStar

    # Make a map (any size!)
    world = [
        [0,0,0],
        [1,1,0],
        [0,0,0],
        ]

    # define a start and end goals (x, y) (vertical, horizontal)
    start = (0, 0)
    goal = (2, 0)
    
    # search
    path = AStar(world).search(start, goal)
    
    print(path)
    # should be:
    
    # [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 1), (2, 0)]

path returns a list with (x, y) tuples with each step to reach that goal!

random map with animation!

    from astar.demo import make_a_maze, walk_through


    if __name__ == "__main__":
        # Given a map size
        size_x, size_y = 16, 32
        
        # Build a map
        world = make_a_maze(size_x, size_y, density=0.1)
        
        # Set start and end goal
        start = (0, 0)
        goal = (size_x-1, size_y-1)
        
        # Search for path
        path = AStar(world).search(start, goal)

        # Show the path
        walk_through(world, path)

more examples:

Please take a look in the examples/ dir for some cool examples how to use it.

testing:

    pytest

If you find it useful give it a star :D

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

python-astar-0.1.0.tar.gz (16.7 kB view hashes)

Uploaded Source

Built Distribution

python_astar-0.1.0-py3-none-any.whl (17.6 kB view hashes)

Uploaded Python 3

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