A modern JavaFX application that visualizes the Breadth-First Search (BFS) algorithm as it navigates a 2D grid-based maze. This tool provides a clear visual representation of how pathfinding algorithms find the shortest path while avoiding obstacles.
- BFS Implementation: Uses a queue-based Breadth-First Search to guarantee the shortest path in an unweighted grid.
- JavaFX Rendering: Utilizes a high-performance
CanvasandGraphicsContextfor smooth UI rendering. - Interactive Interface: Includes dedicated buttons to trigger the solver or reset the grid state.
- Visual Color Coding:
- White: Traversable paths.
- Dark Gray: Solid walls/obstacles.
- Light Blue: Starting position.
- Light Green: Goal/End position.
- Gold: The calculated shortest path.
| Initial State | Solved Maze |
|---|---|
![]() |
![]() |
- Grid System: The maze is defined by a 2D integer array where
1represents a path and0represents a wall. - Exploration: The algorithm explores neighbors in four directions (Up, Down, Left, Right) using direction vectors.
- Path Reconstruction: Each visited cell stores a reference to its
parent. Once the target is reached, the application backtracks through these parents to highlight the route.
- Language: Java.
- Library: JavaFX.
- Algorithm: Breadth-First Search (BFS).
- Solve Maze: Click the "Solve Maze" button to execute the BFS algorithm and identify the shortest route.
- Reset: Use the "Reset" button to clear the gold path visualization and return the maze to its initial state.
The interface is managed via a BorderPane layout with a bottom-aligned HBox containing the control buttons:
| Action | Method Called | Visual Result |
|---|---|---|
| Solve | bfsSolve() |
Draws gold path over the grid. |
| Reset | drawMaze(Collections.emptyList()) |
Clears all path highlights. |
- JDK 11+
- JavaFX SDK configured in your IDE or environment path.
To run the application, compile the MazeSolver.java file ensuring JavaFX modules are included.
javac --module-path /path/to/javafx/lib --add-modules javafx.controls MazeSolver.java
java --module-path /path/to/javafx/lib --add-modules javafx.controls MazeSolver
