Practical - 6
Practical - 6
Practical - 6
return (m1 >= 0 and m1 <= 3 and c1 >= 0 and c1 <= 3 and
moves = []
boat_moves = [(1, 0), (2, 0), (0, 1), (0, 2), (1, 1)]
for m, c in boat_moves:
moves.append((m, c))
return moves
def bfs_solution():
initial_state = (3, 3, 0, 0)
goal_state = (0, 0, 3, 3)
visited = set()
visited.add(initial_state)
while queue:
(m1, c1, m2, c2), path = queue.pop(0) # Removing the first element
return path
new_state = (m1 - m, c1 - c, m2 + m, c2 + c)
visited.add(new_state)
return None
def print_solution(path):
if path is None:
return
state = (3, 3, 0, 0)
m, c = move
print(f"State: {new_state}")
state = new_state
if __name__ == "__main__":
path = bfs_solution()
print_solution(path)
OUTPUT:-
B- Design an application to simulate number puzzle problem.
CODE-
While queue:
Current, path = queue.popleft()
If current == GOAL_STATE:
Return path + [current]
If current in explored:
Continue
Explored.add(current)
Return None
Def main():
# Initial state of the puzzle
Initial_state = (1, 2, 3, 4, 5, 6, 7, 0, 8)
If solution:
Print(“Solution Path:”)
For step in solution:
Print_puzzle(step)
Else:
Print(“No solution found.”)
If __name__ == “__main__”:
Main()
OUTPUT:-