Skip to content

A* might find a suboptimal path if the borders are passable #62

@andreyd41

Description

@andreyd41

Describe the bug
A* might find a suboptimal path if the borders are passable

To Reproduce

from pathfinding.core.grid import Grid

grid = Grid(width=5, height=5)
grid.set_passable_left_right_border()

start = grid.node(3, 2)
end = grid.node(0, 0)

from pathfinding.finder.a_star import AStarFinder

path, _ = AStarFinder().find_path(start, end, grid)

print(len(path))
print(grid.grid_str(path=path, start=start, end=end))
6
+-----+
|exxx |
|   x |
|   s |
|     |
|     |
+-----+

Expected behavior

A* finds the optimal path

from pathfinding.finder.breadth_first import BreadthFirstFinder

path, _ = BreadthFirstFinder().find_path(start, end, grid)

print(len(path))
print(grid.grid_str(path=path, start=start, end=end))
5
+-----+
|e  xx|
|   x |
|   s |
|     |
|     |
+-----+

Screenshots / Map / Log
_

Environment (please complete the following information):

  • Environment: Ubuntu 24.04
  • Python version: 3.11
  • Pathfinding Version: 1.0.11

Additional context
_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions