An open API service indexing awesome lists of open source software.

https://github.com/mark7888/path-finding

Basic recursive path finding algorithm for 2D matrix in python
https://github.com/mark7888/path-finding

Last synced: 4 months ago
JSON representation

Basic recursive path finding algorithm for 2D matrix in python

Awesome Lists containing this project

README

        

# Usage

```py
start = (3, 3)
end = (1, 2)

matrix = [
['x', 'x', 'x', 'x', 'x', 'x', 'x'],
['x', '0', '2', '0', '0', '0', 'x'],
['x', '0', 'x', '0', 'x', '0', 'x'],
['x', '0', 'x', '0', 'x', '0', 'x'],
['x', '0', '0', '1', 'x', '0', 'x'],
['x', 'x', 'x', 'x', 'x', 'x', 'x'],
]

matrix, route = find_path(matrix, start, end, barrier_char='x')
```
# Output
```
# path
[(3, 3), (2, 3), (1, 3), (1, 2), (1, 2)]

# matrix
[
["x", "x", "x", "x", "x", "x", "x"],
["x", "x", "#", "#", "x", "x", "x"],
["x", "x", "x", "#", "x", "x", "x"],
["x", "x", "x", "#", "x", "x", "x"],
["x", "x", "x", "x", "x", "x", "x"],
["x", "x", "x", "x", "x", "x", "x"]
]
```