Skip to content

abhijithshetty12/MazeSolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

MazeSolver: BFS Pathfinding Visualization

Java Algorithm Logic Status

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.


🚀 Features

  • BFS Implementation: Uses a queue-based Breadth-First Search to guarantee the shortest path in an unweighted grid.
  • JavaFX Rendering: Utilizes a high-performance Canvas and GraphicsContext for 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.

📸 Screenshots

Initial State Solved Maze
Initial Maze Solved Maze

🧠 How It Works

  1. Grid System: The maze is defined by a 2D integer array where 1 represents a path and 0 represents a wall.
  2. Exploration: The algorithm explores neighbors in four directions (Up, Down, Left, Right) using direction vectors.
  3. 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.

🛠️ Tech Stack

  • Language: Java.
  • Library: JavaFX.
  • Algorithm: Breadth-First Search (BFS).

🕹️ Usage

  • 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.

UI Controls logic

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.

🚦 Getting Started

Prerequisites

  • JDK 11+
  • JavaFX SDK configured in your IDE or environment path.

Execution

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

About

BFS-based Java Maze Solver.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages