特别是你的问题来自你的全局变量
currentNum
。这基本上就是你在做的事情:
current = 0
def f():
current = 1
g()
def g():
print(current)
f() # Output: 0
</code>
你需要做的是:
current = 0
def f():
global current
current = 1
g()
def g():
print(current)
f() # Output: 1
</code>
或更好 :
def f():
current = 1
g(current)
def g(current):
print(current)
f() # Output: 1
</code>
此外,你应该考虑使用更pythonic synthax为您的
calcMap
功能,如:
def calc_map():
while floor_map[robot_x][robot_y] == uncalculated :
for x,array in enumerate(floor_map):
for y,element in enumerate(array):
if uncalculated < element < wall:
current_num = element + 1
change_surroundings(x, y, current_num)
</code>