Package tdl :: Module map :: Class AStar |
[frames] | no frames]

# Class AStar

source code

    object --+
             |
            AStar

A* pathfinder

Using this class requires a callback detailed in AStar.__init__

Instance Methods
__init__(self, width, height, callback, diagnalCost=1.41421356237, advanced=False) Create an A* pathfinder using a callback. | source code
__del__(self) | source code
[(x, y), ...] |
get_path(self, origX, origY, destX, destY) Get the shortest path from origXY to destXY. | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
| _as_parameter_
Inherited from `object`: `__class__`

Method Details

### __init__(self, width, height, callback, diagnalCost=1.41421356237, advanced=False) (Constructor) | source code
Create an A* pathfinder using a callback. Before crating this instance you should make one of two types of callbacks: A function that returns the cost to move to (x, y) or A function that returns the cost to move between (destX, destY, sourceX, sourceY) If path is blocked the function should return zero or None. When using the second type of callback be sure to set advanced=True Parameters: `width` (int) - width of the pathfinding area in tiles `height` (int) - height of the pathfinding area in tiles `callback` (function) - A callback taking parameters depending on the setting of 'advanced' and returning the cost of movement for an open tile or zero for a blocked tile. `diagnalCost` (float) - Multiplier for diagonal movement. Can be set to zero to disable diagonal movement entirely. `advanced` (boolean) - A simple callback with 2 positional parameters may not provide enough information. Setting this to True will call the callback with 2 additional parameters giving you both the destination and the source of movement. When True the callback will need to accept (destX, destY, sourceX, sourceY) as parameters. Instead of just (destX, destY). Overrides: object.__init__

### get_path(self, origX, origY, destX, destY) | source code
Get the shortest path from origXY to destXY. Returns: [(x, y), ...] Returns a list walking the path from origXY to destXY. This excludes the starting point and includes the destination. If no path is found then an empty list is returned.