0% found this document useful (0 votes)
13 views2 pages

Lab 5 - 8 Puzzle Using A Star

This document outlines a lab task to implement the A* algorithm for solving the 8-puzzle game, which involves rearranging tiles on a 3x3 grid. Users will input initial and goal configurations, and the algorithm will utilize the number of misplaced tiles heuristic to find an optimal solution while displaying each iteration and possible tile movements. The task concludes with the display of the solution sequence and total moves required, along with an option for the user to continue or exit the game.

Uploaded by

hamidraza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Lab 5 - 8 Puzzle Using A Star

This document outlines a lab task to implement the A* algorithm for solving the 8-puzzle game, which involves rearranging tiles on a 3x3 grid. Users will input initial and goal configurations, and the algorithm will utilize the number of misplaced tiles heuristic to find an optimal solution while displaying each iteration and possible tile movements. The task concludes with the display of the solution sequence and total moves required, along with an option for the user to continue or exit the game.

Uploaded by

hamidraza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Task 6: Solving 8-Puzzle Game using A* Algorithm

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. Implement the A* algorithm to search for the optimal solution


2. f(n) = g(n) + h(n)
Display each iteration of the A* algorithm, showing the current state of the puzzle grid and the number of misplaced
tiles.

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-

Iteration 1: Current State:

236

15-

478

Misplaced Tiles: 2

Possible Actions: Move tile 6 down, Move tile 5 left

...

Solution Found!
123

456

78-

Total Moves: 10

keyboard_arrow_down Important Note:


You can use Manhattan Distance as well as hecuristic function to solve 3x3 8-puzzle game.

However students must knows how that distance is computed as it will be asked in viva to compute for an iteration
manually.

def misplaced_tiles_heuristic(state, goal_state):

def actions(state):

def empty_tile(state):

def move_tile(state, action):

def a_star_search(initial_state, goal_state):

def display_state(state):

def main():

You might also like