Professional Documents
Culture Documents
Practical 3
Practical 3
Aim :
Write a program to implement DFS (for 8 puzzle problem or Water jug Problem or any AI search
Problem).
8-Puzzle Problem:-
Code:
# Define the 8-puzzle problem state
class PuzzleState:
def __init__(self, state, parent, action, depth):
self.state = state
self.parent = parent
self.action = action
self.depth = depth
def __str__(self):
return str(self.state)
def __hash__(self):
return hash(str(self.state))
# Define the initial and goal states for the 8-puzzle problem
initial_state = [1, 0, 2,
7, 8, 3,
6, 5, 4]
goal_state = [1, 2, 3,
8, 0, 4,
7, 6, 5]