Skip to content

husain34/BFS-Pathfinding-Cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Breadth-First Search (BFS) Pathfinding in C++ ๐Ÿš€ A C++ implementation of the Breadth-First Search (BFS) algorithm for pathfinding in a grid-based environment. This program finds the shortest path from a start to an end position while avoiding obstacles. It visualizes the path using a simple console grid.

๐Ÿ“Œ Features โœ… Grid Representation using std::map<pair<int, int>, Node> โœ… Obstacle Handling to block certain paths โœ… Shortest Path Finding using BFS (Optimal for Unweighted Graphs) โœ… Backtracking to reconstruct the path โœ… Console Grid Visualization with obstacles and path markers

๐Ÿ”ง How It Works The user defines the grid size (rows & columns). Obstacles (||||||) can be placed at specific coordinates. The program takes start and end coordinates. BFS Algorithm finds the shortest path. The grid is printed with the path (.) from start to end, while obstacles are shown as ||||||.

Example Output Enter the number of rows in the grid: 5 Enter the number of columns in the grid: 5

Enter obstacle coordinates as 'x1 y1 x2 y2 ...' (type 'done' to finish): 1 1 2 2 done

Enter Start Coordinate: Enter X coordinate: 0 Enter Y coordinate: 0

Enter End Coordinate: Enter X coordinate: 4 Enter Y coordinate: 4

Grid with Path: 0, 0| 0, 1| 0, 2| 0, 3| 0, 4| . ||||||| 1, 2| 1, 3| 1, 4| . | 2, 1||||||| 2, 3| 2, 4| . | 3, 1| 3, 2| 3, 3| 3, 4| . | . | . | . | 4, 4| ๐Ÿ”น "." represents the shortest path. ๐Ÿ”น "||||||" represents obstacles.

๐Ÿ— Future Improvements ๐Ÿ† Add support for diagonal movement ๐Ÿ“Œ Implement Dijkstraโ€™s Algorithm for weighted graphs ๐ŸŽจ GUI version using SFML or SDL ๐Ÿค Contributing Feel free to fork, improve, or optimize the project. Contributions are welcome!

About

A C++ implementation of the Breadth-First Search (BFS) algorithm for grid-based pathfinding, handling obstacles and visualizing the shortest path.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages