i have written some code that i want to convert into something i can import instead of it being used as the main.
floorMap = [[000,000,000,000,000,999,999,999,999,999],
[000,000,999,000,999,000,000,000,999,999],
[000,000,999,000,999,000,000,000,999,999],
[000,000,000,000,999,000,000,000,999,999],
[999,000,000,000,999,000,999,999,999,999],
[999,000,000,000,000,000,999,000,000,999],
[999,000,000,000,999,999,999,000,000,999],
[999,000,999,000,000,000,999,000,000,999],
[999,000,999,999,999,000,000,000,000,999],
[999,999,999,999,999,999,999,999,000,000]]
currentNum=0
wall=999
uncalculated=000
robotX=0
robotY=0
goalX=9
goalY=9
floorMap[goalY][goalX]=1
def changeSurroundings(X, Y):
#left
if(floorMap[X-1][Y]==uncalculated and X > 0):
floorMap[X-1][Y]=currentNum
#right
if(X < len(floorMap[0])-1 and floorMap[X+1][Y]==uncalculated):
floorMap[X+1][Y]=currentNum
#up
if(floorMap[X][Y-1]==uncalculated and Y > 0):
floorMap[X][Y-1]=currentNum
#down
if(Y < len(floorMap)-1 and floorMap[X][Y+1]==uncalculated):
floorMap[X][Y+1]=currentNum
def printMap():
i=0
floorMap[goalY][goalX]='G'
floorMap[robotY][robotX]='R'
while(i<len(floorMap)):
print floorMap[i]
print ""
i+=1
print ""
print ""
#------------------MOST IMPORTANT CHUNK OF CODE--------------
while(floorMap[robotY][robotX]==uncalculated):
x=0
while(x<len(floorMap[0])):
y=0
while(y<len(floorMap)):
if(floorMap[x][y] > uncalculated and floorMap[x][y] < wall):
currentNum=floorMap[x][y]+1
changeSurroundings(x,y)
y+=1
x+=1
printMap()
my problem is that whenever i try to put the most important chunk of code at the bottom into a method like so;
def calcMap():
while(floorMap[robotY][robotX]==uncalculated):
x=0
while(x<len(floorMap[0])):
y=0
while(y<len(floorMap)):
if(floorMap[x][y] > uncalculated and floorMap[x][y] < wall):
currentNum=floorMap[x][y]+1
changeSurroundings(x,y)
y+=1
x+=1
printMap()
it breaks my code. why? I dont seem to get any errors, it just gets stuck on one of the nested loops. i dont see any reason it should be doing this, but you guys probably will ;)
Thanks, Logan