Im trying to create a python program capable of solving a maze. I need it to be able to solve a maze that is any number of rows in height and any number of columns in width. I need the maze itself to be brought in as input from a file and I need it to be validated to ensure it contains a starting point. Once verified I need the maze to be solved iteratively showing each step. The maze will consist of '#' signs for walls the letter 'S' for the start and the letter 'E' for the end. I am having a lot of difficulty with this and any help would be appreciated. Right now I dont even know how to find the starting point of the maze. Heres what I have so far:
def main():
maze=raw_input("Enter the name of the maze file: ")
mazefile = open(maze,"r")
pythonmaze = mazefile.read()
print pythonmaze
mazefile.close
mazestart=start(pythonmaze)
def start(m):
for s in range(0,len(m)): ##Finds the start point.
if m[s] =="S":
x = s
return x
main()
I know what I want to code but cant figure out how to code it. I believe that I need to have a function that looks to find the start of the maze. Then I think I need a function that checks north, east, south, and west to see if there is a space there and moves to the space if there is one. Then I believe I need to have a function that backtracks if it comes to a dead end in order to find the correct path to the end. Ive really been struggling with writing code in order to accomplish this and I hope someone can help me out!