hey yall

I've been working on this python program for a while and I need some help please. This program consists of classes and functions to make a basic maze. I'm not using Tkinter or any gui's. Just a printout where python does all the calculating. I have three files, main.py, maze.py, and path.py. User inputs dimensions...then follow the menu. I can print the maze, when I try to solve it, the program prints an endless loop of errors. Can you help fix it because I can't find it.

This is the code where I can't 'solve' the maze, bc python would be reading these functions. (i think)

def findPath(self): # start the recursion
                    return self.rfindPath(self.start[0],self.start[1])
        
          def rfindPath(self,i,j):
                    if(i < 0 or i > self.m or j < 0 or j > self.n):
                              return False
                    elif(self.theMaze[i][j] == ' X' or self.theMaze[i][j] ==' v' or self.theMaze[i][j] == ' *'):
                              if(self.theMaze[i][j] == ' *'):
                                        self.theMaze[i][j] == ' v'
                                        self.thePath.pop()       
                              return False

          def removeVs(self):
                    for i in range(0, self.m):
                              for j in range(0, self.n):
                                        if self.theMaze[i][j] == ' v':
                                                  self.theMaze[i][j] = ' O'
                    return

the attachments are .txt. rename them to .py, save them in the same folder together, and run main.py to try it out.

THANK YOU FOR YOUR HELP! :)

Recommended Answers

All 5 Replies

This code doesn't really do anything for me... can you explain the concept a little bit? When none of the menu choices do anything except for the 'new maze' bit.

Printing shows the maze but neither solve nor "Remove v's" does anything whatsoever. I'm not getting errors though...

hi, the point of these three files is to make a maze. when you start you get a menu. 0 quits, 1 makes the maze, and 2 prints it. I want to solve the maze by hitting three. @ this point, nothing will print. Python will 'solve' the maze. I want to print what python came up with, so I hit option 2. I should see the steps python took to solve the maze. This involves a recursion formula and a stack trace by keeping track of where I've visited. I should see v's for where I've visted and numbers that lead to the finish of the maze. The v's mean visited but those down count in the steps to solve the maze. When I hit 4, I should see only the numbers in the spaces python took to get to 'finish'. The v's should change back to their original spaces, which would be O's because those are 'open' spaces.

Is that a better explanation? I keep getting a loop in the maze.py file for line 58 and line 62.

I can't get any numbers to print or any v's to show. I can't get menu function three to print.

Thanks.

First things first, self.theMaze[i][j] == ' v' is a comparative statement. Double '=' compare two values while a single '=' assigns variables. So change that to self.theMaze[i][j] = ' v' I would suggest putting some tracing print statements throughout your maze class to verify that things are working the way you expect... I noticed that you mix up a single space and double spaces in your maze class which will definitely always fail, ie: ' v' is not equal to ' v' ... This comparison will always fail.

Hi:

When I change the == to =, I get 'syntax error'. Do I change all the variables x, o, s, f... I don't know what I did but when I hit 3, and try to print the maze, the original maze prints (and i don't get errors...wierd). How do I get the v's to print? Anyone have any clues? I don't see what I'm doing wrong. I can't test the path class either, I'm not sure how to do it.

Thank you for all of your help!

Well I notice in your maze class under the rfindPath function you have the following comparison: if(self.theMaze[i][j] == ' *') ; hoewver none of the entries in the maze EVER have an asterisk in them. Did you mean this to be a wildcard?

In your maze class under the main function you should also test this "solve" method and just work on that until you get it working. That should get you on your way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.