Lab 5 - 8 Puzzle Using A Star
Lab 5 - 8 Puzzle Using A Star
The objective of this lab task is to implement the A* algorithm to solve the 8-puzzle game. The 8-puzzle game consists of a
3x3 grid with 8 numbered tiles and an empty space. The goal is to rearrange the tiles from an initial configuration to a
specified goal configuration using the minimum number of moves.
The algorithm will take the initial and goal states as input from the user.
1. Prompt the user to input the initial configuration of the 8-puzzle game.
2. Prompt the user to input the goal configuration of the 8-puzzle game.
Use the number of misplaced tiles heuristic to guide the search for an optimal solution.
1. Show the possible actions (tile movements) available in each iteration, including moving tiles left, right, up, or
down (no diagonal movement allowed).
Once the optimal solution is found, display the sequence of moves required to transform the initial configuration into
the goal configuration.
1. Show the total number of moves required to reach the goal state.
Ask user if He/she wants to continue or exit the Game.
Example
Initial Configuration:
236
15-
478
Goal Configuration:
123
456
78-
236
15-
478
Misplaced Tiles: 2
...
Solution Found!
123
456
78-
Total Moves: 10
However students must knows how that distance is computed as it will be asked in viva to compute for an iteration
manually.
def actions(state):
def empty_tile(state):
def display_state(state):
def main():