SZ=[[0,0,0,0,0,0,0,0,0,0,0,0], #0 ist Mauer,1 ist Weg.
[0,2,0,1,1,1,0,1,1,1,1,0], #2 ist Start,9 ist Ende.
[0,1,1,1,0,0,0,0,0,1,0,0],
[0,1,0,1,1,1,0,1,1,1,0,0],
[0,1,0,0,0,1,0,1,0,1,0,0],
[0,1,1,1,0,1,1,1,0,1,0,0],
[0,0,0,0,0,1,0,1,0,1,1,0],
[0,1,0,1,0,1,0,0,0,0,1,0],
[0,1,0,1,1,1,0,1,1,1,1,0],
[0,1,0,1,0,0,0,1,0,0,0,0],
[0,1,1,1,1,1,0,1,1,1,9,0],
[0,0,0,0,0,0,0,0,0,0,0,0]]
#for i in range(1,len(SZ)-1):
# for j in range(1,len(SZ[i])-1):
# print ("SZ["),i,("]["),j,("] ist:"),SZ[i][j]
aStaple=[[],[]]
def Backtracking(ii,jj):
mittel=SZ[ii][jj]
if mittel==9:
aStaple[0].append(ii) #aStaple zurueckgeben
aStaple[1].append(jj)
return ii,jj
elif mittel==1 or mittel==2: #wenn diese Position 1 ist.
aStaple[0].append(ii) #Push in aStaple
aStaple[1].append(jj)
SZ[ii][jj]=5
Backtracking(hulr(ii,jj)[0],hulr(ii,jj)[1])
return ii,jj
elif mittel==5:
SZ[ii][jj]=6
Backtracking(hulr(ii,jj)[0],hulr(ii,jj)[1])
else:
if len(aStaple[0])!=0 and len(aStaple[1])!=0:
aStaple[0].pop()
aStaple[1].pop()
print ("Jetzt ist Point:"),aStaple[0][-1],aStaple[1][-1]
Backtracking(aStaple[0][-1],aStaple[1][-1])
def hulr(mi,mj):
if SZ[hoch(mi,mj)[0]][hoch(mi,mj)[1]]==1 or SZ[hoch(mi,mj)[0]][hoch(mi,mj)[1]]==9:
return hoch(mi,mj)[0],hoch(mi,mj)[1]
elif SZ[unten(mi,mj)[0]][unten(mi,mj)[1]]==1 or SZ[unten(mi,mj)[0]][unten(mi,mj)[1]]==9:
return unten(mi,mj)[0],unten(mi,mj)[1]
elif SZ[links(mi,mj)[0]][links(mi,mj)[1]]==1 or SZ[links(mi,mj)[0]][links(mi,mj)[1]]==9:
return links(mi,mj)[0],links(mi,mj)[1]
elif SZ[rechts(mi,mj)[0]][rechts(mi,mj)[1]]==1 or SZ[rechts(mi,mj)[0]][rechts(mi,mj)[1]]==9:
return rechts(mi,mj)[0],rechts(mi,mj)[1]
else:
return mi,mj
def hoch(hi,hj):
hi=hi
hj=hj-1
return hi,hj
def unten(ui,uj):
ui=ui+1
uj=uj
return ui,uj
def links(li,lj):
li=li-1
lj=lj
return li,lj
def rechts(ri,rj):
ri=ri
rj=rj+1
return ri,rj
print ("Weg ist:"),aStaple
Backtracking(1,1)
print SZ