puzzle8
Introduction
This project focuses on developing a solver for the classic Puzzle8 problem, where tiles numbered from 1 to 8 are arranged on a 3x3 grid with one empty space. The objective is to rearrange the tiles to reach a target configuration by sliding them horizontally or vertically. To achieve this, I implemented the A* search algorithm and built an interactive graphical user interface (GUI) using SvelteKit and TypeScript to visualize the solution process.
Goal of the project
The primary goal of this project is to design and implement an efficient solution for the Puzzle8 problem. This involves creating an algorithm that finds the shortest possible path to solve the puzzle from any given starting state while also providing a user-friendly interface for visualizing the steps to the solution.
My approach
To solve the Puzzle8 problem, I utilized the A* (A-star) search algorithm, a popular and effective pathfinding algorithm in computer science. A* combines the strengths of breadth-first and depth-first search by using a priority queue to explore the most promising states first.
The algorithm evaluates each possible state of the puzzle using the following cost function:
f(n) = g(n) + h(n)
- g(n) is the cost to reach the current state.
- h(n) is the heuristic estimate of the cost to reach the goal state.
I chose the Manhattan distance as the heuristic function, which measures the total number of moves each tile needs to reach its target position. This heuristic is both admissible and consistent, ensuring optimal solutions.
The GUI was built using SvelteKit and TypeScript to provide a responsive and interactive user experience. Users can input puzzle configurations and watch as the A* algorithm solves the puzzle step by step.
Result
The project successfully meets its goal by efficiently solving the Puzzle8 problem and providing a clear visualization of the solution process. The A* algorithm consistently finds the optimal solution, and the SvelteKit-based GUI offers a smooth and intuitive user experience. This project demonstrates the practical application of search algorithms in solving complex problems and highlights the importance of heuristic functions in optimizing search efficiency.
Photos