Question: I need help implementing this. Please implement using the code below. '''Solve the modified 8-puzzle, where duplicates are allowed. We compare depth-first, breadth-first and A*
I need help implementing this. Please implement using the code below.

'''Solve the modified 8-puzzle, where duplicates are allowed. We compare depth-first, breadth-first and A* approaches.''' import copy import random # Print the current state def prt(cells, N, header): print(header) topLine = " +" for col in range(0, N): topLine += "----+" print(topLine) for row in range(0, N): line = " |" for col in range(0, N): if cells[row][col] == 0: line += " |" else: line += " %2d |" % cells[row][col] print(line) print(topLine) print("") # Where is the empty cell? Sure, we could keep track of it directly. def findEmpty(cells, N): for col in range(0, N): for row in range(0, N): if cells[row][col] == 0: return (row, col) raise Exception("No empty cell") # Find a random legal move def randomMove(cells, N, emptyRow, emptyCol): while True: fromRow = emptyRow fromCol = emptyCol direction = random.randint(1, 4) if direction == 1: fromRow -= 1 elif direction == 2: fromRow += 1 elif direction == 3: fromCol -= 1 elif direction == 4: fromCol += 1 if fromRow >= 0 and fromRow = 0 and fromCol TODO: Put some logic here # prt(cells, N, "Depth-first Final State, moves=%d" % moves) # Solve using breadth-first search def breadthFirst(cells, goal, N): moves = 0 # # TODO: Put some logic here # prt(cells, N, "Breadth-first Final State, moves=%d" % moves) # Solve using A* search def aStar(cells, goal, N): moves = 0 # # TODO: Put some logic here # prt(cells, N, "A* Final State, moves=%d" % moves) # Solve the puzzle def tryit(goal): N = len(goal) prt(goal, N, "Goal State:") init = copy.deepcopy(goal) randomize(init, N, 1000) prt(init, N, "Initial State:") cells = copy.deepcopy(init) depthFirst(cells, goal, N) cells = copy.deepcopy(init) breadthFirst(cells, goal, N) cells = copy.deepcopy(init) aStar(cells, goal, N) # Main program, "0" means empty tryit([[2, 8, 7], [2, 0, 6], [3, 4, 5]]) In this assignment, we will compare depth-first, breadth-first and A* search strategies. We will implement the 8 puzzle, with one variation. Instead of having tiles numbered 1-8 we will have one duplicate tile. 2-2-3-4-5-6-7-8 for example. Example: The 8-puzzle 6) 4 56 3 Start State Goal State Page 103 Grading Rubric (50 points): .5 points for a depth-first solution o !.poinis fir, a brc%acti h iirsi: salurilt in 15 points for an A* solution 20 points for a summary of results, including . o Total number of steps required to find each solution (10 pts) o Elapsed clock time needed to solve each puzzle (5 pts) o Maximum number of concurrent states for each (5 pts) 5 points for comments in your submitted code In this assignment, we will compare depth-first, breadth-first and A* search strategies. We will implement the 8 puzzle, with one variation. Instead of having tiles numbered 1-8 we will have one duplicate tile. 2-2-3-4-5-6-7-8 for example. Example: The 8-puzzle 6) 4 56 3 Start State Goal State Page 103 Grading Rubric (50 points): .5 points for a depth-first solution o !.poinis fir, a brc%acti h iirsi: salurilt in 15 points for an A* solution 20 points for a summary of results, including . o Total number of steps required to find each solution (10 pts) o Elapsed clock time needed to solve each puzzle (5 pts) o Maximum number of concurrent states for each (5 pts) 5 points for comments in your submitted code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
