This is a Python program that solves the 8-puzzle using the A* algorithm with the Manhattan Distance heuristic.
The 8-puzzle is a sliding puzzle that consists of a 3x3 grid with 8 numbered tiles and one empty space. The goal is to arrange the tiles in ascending order, starting from the top-left corner.
This program uses the A* algorithm to find the optimal solution to the 8-puzzle problem. The A* algorithm combines the cost to reach a node (g) and the estimated cost to the goal (h) to determine the best path.
The Manhattan Distance heuristic is used to estimate the cost from each state to the goal state. It calculates the sum of the distances between each tile and its goal position.
To use this program, follow these steps:
- Install Python (version 3.6 or higher) if you haven't already.
- Open the
main.py
file in a Python IDE or text editor. - Modify the
initial_state_1
andinitial_state_2
variables to define your own puzzle problems. - Run the program.
- The program will output the solutions to the puzzle problems, if found.
The program includes two example problems:
-
Problem 1: Initial state
[1, 2, 3], [4, 5, 6], [0, 7, 8]
- Solution:
[1, 2, 3], [4, 5, 6], [7, 8, 0]
- Solution:
-
Problem 2: Initial state
[2, 8, 1], [0, 4, 3], [7, 6, 5]
- Solution:
No solution found for problem 2.
- Solution:
This project is licensed under the MIT License. See the LICENSE file for details.