also be to the north but if the north is blocked by wall we must look at the next step of the procedure and try going to the south unfortunately that step to the south brings us right back to our original starting place if we apply the recursive procedure from there we will just go back one step to the north and be in an infinite loop sowe must have strategy to remember where we have been in this case we will assume that we have bag of bread crumbs we can drop along our way if we take step in certain direction and find that there is bread crumb already on that squarewe know that we should immediately back up and try the next direction in our procedure as we will see when we look at the code for this algorithmbacking up is as simple as returning from recursive function call as we do for all recursive algorithms let us review the base cases some of them you may already have guessed based on the description in the previous paragraph in this algorithmthere are four base cases to consider the turtle has run into wall since the square is occupied by wall no further exploration can take place the turtle has found square that has already been explored we do not want to continue exploring from this position or we will get into loop we have found an outside edgenot occupied by wall in other words we have found an exit from the maze we have explored square unsuccessfully in all four directions for our program to work we will need to have way to represent the maze to make this even more interesting we are going to use the turtle module to draw and explore our maze so we can watch this algorithm in action the maze object will provide the following methods for us to use in writing our search algorithm__init__ reads in data file representing mazeinitializes the internal representation of the mazeand finds the starting position for the turtle draw_maze draws the maze in window on the screen update_position updates the internal representation of the maze and changes the position of the turtle in the window is_exit checks to see if the current position is an exit from the maze the maze class also overloads the index operator [so that our algorithm can easily access the status of any particular square let' examine the code for the search function which we call searchfrom the code is shown below notice that this function takes three parametersa maze objectthe starting rowand the starting column this is important because as recursive function the search logically starts again with each recursive call def search_from(mazestart_rowstart_column)maze update_position(start_rowstart_columncheck for base cases we have run into an obstaclereturn false if maze[start_row][start_column=obstacle return false exploring maze