Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

full problem: https://www.chegg.com/homework-help/questions-and-answers/order-se

ID: 3716458 • Letter: F

Question

full problem: https://www.chegg.com/homework-help/questions-and-answers/order-see-full-solution-e-sequence-moves-initial-state-goal-state-need-add-method-state-cl-q28747560

Convert pseudocode to python. Just simply convert it doesnt have to be exact. I can fix the rest if not exactly correct

def print_moves_to(self):
if self is the initial state: # base case
print('initial state:')
print the board associated with self
else:
make a recursive call to print the moves to the predecessor state
print the move that led to self (see format below)
print the board associated with self?

In order to see the full solution (i.e, the sequence of moves from the initial state to the goal state), we need to add a method to the State class that will follow predecessor references back up the state-space search tree in order to find and print the sequence of moves. Open up your state.py file, and add a method print_moves to(self) that prints the sequence of moves that lead from the initial state to the called State object (i.e., to self) To accomplish this task, you should first review the attributes that each State object has inside it. Consult the guidelines for the State class__init__ method as needed. Next, it's worth noting that this method will be starting at a given State object and following predecessor references back to the initial state. However, we want to print the sequence of moves in the reverse order - from the initial state to the called State object. One way to do this is using recursion, as shown in the following pseudocode: def print_moves to(self): if self is the initial state: # base case print('initial state:') print the board associated with self else: make a recursive call to print the moves to the predecessor state print the move that led to self (see format below) print the board associated with self Because the recursive call on the predecessor state comes before the processing of self, the method will print the sequence of moves in the correct order.

Explanation / Answer

def print_moves_to(self): # the initial state previous state must be None to terminate the program if self.previous_state is None: print('initial state:') print(self.board) else: self.previous_state.print_moves_to() # let's print the move print(self.previous_state.move) # let's print the board print(self.previous_state.board) # let me know if you have any query. from the information, # I was able to do the above. I hope, I helped you.