|
| 1 | +# Pathfinding Visualizer (Code_Script Module) |
| 2 | + |
| 3 | +A GUI-based C++17 + Qt6 pathfinding animation tool that visually demonstrates |
| 4 | +**BFS**, **Dijkstra**, and **A\*** exploring a 2D grid in real time. |
| 5 | +This module is intended for educational use and integration into the Code_Script project. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 📄 Small Description |
| 10 | + |
| 11 | +The Pathfinding Visualizer is an interactive Qt6 application that displays how classical pathfinding algorithms traverse a grid to find a path between two points. Users can place walls, change algorithms, adjust animation speed, and observe the search progress and final path. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## 🎯 Goals |
| 16 | + |
| 17 | +- Visually demonstrate how BFS, Dijkstra, and A\* explore and find shortest paths. |
| 18 | +- Provide an interactive 2D grid where users can toggle walls and set start/target nodes. |
| 19 | +- Animate algorithm steps in real-time (visited nodes + final path). |
| 20 | +- Maintain a thread-safe architecture using a background worker thread for algorithms. |
| 21 | +- Offer adjustable animation speed and algorithm selection via a toolbar UI. |
| 22 | +- Serve as a self-contained Code_Script module. |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## 📁 File Structure |
| 27 | + |
| 28 | +``` |
| 29 | +pathfinding_visualizer/ |
| 30 | +│ |
| 31 | +├── CMakeLists.txt |
| 32 | +├── README.md |
| 33 | +├── .gitignore |
| 34 | +│ |
| 35 | +├── include/ |
| 36 | +│ ├── MainWindow.hpp |
| 37 | +│ ├── Grid.hpp |
| 38 | +│ ├── Node.hpp |
| 39 | +│ └── Algorithms/ |
| 40 | +│ └── AlgorithmWorker.hpp |
| 41 | +│ |
| 42 | +├── src/ |
| 43 | +│ ├── main.cpp |
| 44 | +│ ├── MainWindow.cpp |
| 45 | +│ ├── Grid.cpp |
| 46 | +│ ├── Node.cpp |
| 47 | +│ └── Algorithms/ |
| 48 | +│ └── AlgorithmWorker.cpp |
| 49 | +│ |
| 50 | +├── ui/ |
| 51 | +│ └── MainWindow.ui |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## 🛠️ Prerequisites |
| 57 | + |
| 58 | +### Software Requirements |
| 59 | +- **Qt 6.9.3** (or later) |
| 60 | + - MinGW 64-bit or MSVC 64-bit build tools installed via Qt Online Installer. |
| 61 | +- **CMake 3.16+** |
| 62 | +- **C++17 compatible compiler** |
| 63 | + - MSYS2 MinGW-w64 (preferred for simplicity) |
| 64 | + - or Microsoft Visual C++ (MSVC) |
| 65 | +- **VS Code** (recommended) with: |
| 66 | + - *CMake Tools* extension |
| 67 | + - *C/C++* extension |
| 68 | + |
| 69 | +### Optional |
| 70 | +- Qt Creator (IDE) |
| 71 | +- Git (if contributing back to Code_Script) |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## ▶️ Usage Instructions |
| 76 | + |
| 77 | +### Running the Application |
| 78 | +After building the project, launch: |
| 79 | + |
| 80 | +./build/pathfinding_visualizer.exe |
| 81 | + |
| 82 | +This opens the main window containing the 2D grid and the control toolbar. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +### Grid Interaction |
| 87 | + |
| 88 | +- **Left Click** on a cell → Toggle Wall (White ↔ Black) |
| 89 | +- **Right Click** on a cell → Set Start Node (Green) |
| 90 | +- **Shift + Left Click** or **Middle Click** → Set Target Node (Red) |
| 91 | + |
| 92 | +The grid updates visually using `Node` objects in a `QGraphicsScene`. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +### Toolbar Controls |
| 97 | + |
| 98 | +- **Run** |
| 99 | + Starts the selected algorithm on a background thread (`AlgorithmWorker`). |
| 100 | + |
| 101 | +- **Reset** |
| 102 | + Clears all walls, visited cells, and path markings. Start/Target nodes return to defaults. |
| 103 | + |
| 104 | +- **Algorithm Selector** |
| 105 | + Choose between **BFS**, **Dijkstra**, or **A\***. |
| 106 | + |
| 107 | +- **Speed Slider** |
| 108 | + Controls animation delay (ms per step). |
| 109 | + Lower value = faster, higher = slower. |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +### Visualization Colors |
| 114 | +- **Start Node** → Green |
| 115 | +- **Target Node** → Red |
| 116 | +- **Walls** → Black |
| 117 | +- **Visited Cells** → Light Blue |
| 118 | +- **Final Path** → Yellow |
| 119 | + |
| 120 | +Updates are triggered by worker-thread signals: |
| 121 | +`visit(row,col)` and `pathNode(row,col)`. |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## 🔧 Build Instructions (Windows — Qt 6.9.3) |
| 126 | + |
| 127 | +### Requirements |
| 128 | +- Qt **6.9.3** |
| 129 | + - Either **MinGW 64-bit** or **MSVC 2022 64-bit** Qt build installed |
| 130 | +- CMake **3.16+** |
| 131 | +- A C++17 compiler |
| 132 | +- Optional: VS Code with **CMake Tools** extension |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +### 1️⃣ Configure (MinGW Example) |
| 137 | + |
| 138 | +cmake -B build -S . -G "MinGW Makefiles" ^ |
| 139 | +-DCMAKE_PREFIX_PATH="C:/Qt/6.9.3/mingw_64/lib/cmake" |
| 140 | + |
| 141 | +### 2️⃣ Build (MinGW) |
| 142 | +cmake --build build |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +### 1️⃣ Configure (MSVC Example) |
| 147 | + |
| 148 | +cmake -B build -S . -G "NMake Makefiles" ` |
| 149 | +-DCMAKE_PREFIX_PATH="C:/Qt/6.9.3/msvc2022_64/lib/cmake" |
| 150 | + |
| 151 | +### 2️⃣ Build (MSVC) |
| 152 | +cmake --build build --config Release |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +### 3️⃣ Run |
| 157 | + |
| 158 | +./build/pathfinding_visualizer.exe |
0 commit comments