Question: please use python and shoe screenshots of output ( need assistance, I have my code below but not getting the right results in the auto

please use python and shoe screenshots of output ( need assistance, I have my code below but not getting the right results in the auto grader ) the problem goes like this: you'll implement an agent that can solve Block World problems for an arbitrary initial arrangement of blocks. You will be given an initial arrangement of blocks and a goal arrangement of blocks, and return a list of moves that will transform the initial state into the goal state.For us, blocks will be identified as single letters from A to Z. Blocks may be moved one at a time. A block may not be moved if there is another block on top of it. Blocks may be placed either on the table or on top of another block. Your goal is to generate a list of moves that will turn the initial state into the goal state. In the example above, that could be: Move D to the table, move B to A, move C to D, move B to C, and move A to B. There may be more than one sequence of moves that can accomplish the goal. If so, your goal is to generate the smallest number of moves that will turn the initial state into the goal state. Your solve() method will have two parameters: the initial configuration of blocks, and the goal configuration of blocks. Configurations will be represented by lists of lists of characters, where each character represents a different block (e.g. "A" would be Block A). Within each list, each subsequent block is on top of the previous block in the list; the first block in the list is on the table. For example, this list would represent the configuration shown above: two stacks, one with D on B and B on C, and the other with just A: [["C", "B", "D"], ["A"]] There may be up to 26 blocks in a puzzle and you may have as many stacks as there are blocks. You may assume that the goal configuration contains all the blocks and only the blocks present in the initial configuration. Yoursolve()method should return a list of moves that will convert the initial state into the goal state. Each move should be a 2-tuple. The first item in each 2-tuple should be what block is being moved, and the second item should be where it is being moved toeither the name of another block or "Table" if it is to be put into a new pile. For example, imagine the following initial and target state: Initial:[["A", "B", "C"], ["D", "E"]]Goal:[["A", "C"], ["D", "E", "B"]] Put in simple terms, the goal here is to move Block B from the middle of the pile on the left and onto the top of the pile on the right. Given that, this sequence of moves would be an acceptable solution: ("C", "Table")("B", "E")("C", "A") How You Will Be Graded Your agent will be run against 20 pairs of initial and goal configurations. 8 of these will be the same every time your agent is tested; these are present in the original BlockWorldAgent.py file. The remaining 12 will be randomly generated, with up to 26 blocks each. You can earn up to 40 points. You will earn 1 point for each of the 20 pairs of configurations you solve correctly (meaning that your solution does in fact transform the initial state into the goal state), and an additional point for each of the 20 configurations you solveoptimally(in the minimum number of moves). My code is this: from collections import deque class BlockWorldAgent: def __init__(self): #If you want any initial processing, add it here. pass def solve(self, initial_arrangement, initial_goal): #Add your code here! Your solve method should receive #as input two arrangements of blocks. The arrangements #will be given as lists of lists. The first item in each #list will be the bottom block on a stack, proceeding #upward. For example, this arrangement: # #[["A", "B", "C"], ["D", "E"]] # #...represents two stacks of blocks: one with B on top #of A and C on top of B, and one with E on top of D. # #Your goal is to return a list of moves that will convert #the initial arrangement into the goal arrangement. #Moves should be represented as 2-tuples where the first #item in the 2-tuple is what block to move, and the #second item is where to put it: either on top of another #block or on the table (represented by the string "Table"). # #For example, these moves would represent moving block B #from the first stack to the second stack in the example #above: # #("C", "Table") #("B", "E") #("C", "A") moves = [] def find_block(block, configuration): for stack_index, stack in enumerate(configuration): if block in stack: return stack_index, stack.index(block) return None, None def move_block(block, source_stack_index, destination): if destination == "Table": block = initial_arrangement[source_stack_index].pop() initial_arrangement.append([block]) else: dest_stack_index, _ = find_block(destination, initial_arrangement) block = initial_arrangement[source_stack_index].pop() initial_arrangement[dest_stack_index].append(block) moves.append((block, destination)) def clear_above(block): stack_index, block_index = find_block(block, initial_arrangement) while len(initial_arrangement[stack_index]) > block_index + 1: top_block = initial_arrangement[stack_index][-1] move_block(top_block, stack_index, "Table") for goal_stack in initial_goal: for i, block in enumerate(goal_stack): clear_above(block) current_stack_index, current_index = find_block(block, initial_arrangement) if i == 0: if current_index != len(initial_arrangement[current_stack_index]) - 1: move_block(block, current_stack_index, "Table") else: target_below = goal_stack[i - 1] target_stack_index, _ = find_block(target_below, initial_arrangement) if current_stack_index != target_stack_index or current_index != len(initial_arrangement[current_stack_index]) - 1: move_block(block, current_stack_index, target_below) return moves

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!