I have this error when I'm running my code for building a perfect maze. Here is the code:
def walk(self, s, x, y):
neighboor = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
if s.size() == self.size**2: return
else:
while True:
new = choice(neighboor)
if self.is_valid(new[0], new[1]): break
while self.maze[new[0]][new[1]].getVisit():
if len(neighboor) != 0: new = choice(neighboor.remove(new))
else:
temp = s.pop(s)
self.walk(s, temp[0], temp[1])
#print(new)
self.maze[new[0]][new[1]].changeVisit()
if new == neighboor[1]:
self.maze[x][y].changeNorth()
self.maze[new[0]][new[1]].changeSouth()
elif new == neighboor[0]:
self.maze[x][y].changeSouth()
self.maze[new[0]][new[1]].changeNorth()
elif new == neighboor[2]:
self.maze[x][y].changeEast()
self.maze[new[0]][new[1]].changeWest()
elif new == neighboor[3]:
self.maze[x][y].changeWest()
self.maze[new[0]][new[1]].changeEast()
s.push(new)
self.walk(s, new[0], new[1])
Here is the Error I got:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
a.search()
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 93, in search
self.walk(s, startX, startY)
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 76, in walk
self.walk(s, new[0], new[1])
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 76, in walk
self.walk(s, new[0], new[1])
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 76, in walk
self.walk(s, new[0], new[1])
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 76, in walk
self.walk(s, new[0], new[1])
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 76, in walk
self.walk(s, new[0], new[1])
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 76, in walk
self.walk(s, new[0], new[1])
File "C:\Users\Serena\Desktop\XAproject\Stack.py", line 52, in walk
if len(neighboor) != 0: new = choice(neighboor.remove(new))
File "C:\Python34\lib\random.py", line 253, in choice
i = self._randbelow(len(seq))
TypeError: object of type 'NoneType' has no len()
I think 'neighboor' is a list contains four sets of number, it should have len().
I'm new to programming, any help would be appreciate.