Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
"""
Created on Sat Sep 9 08:49:29 2017
@author: Pinkman
"""
import numpy as np
import matplotlib.pyplot as mat
maze = mat.imread('challenge.png')
size=np.shape(maze)
def deadend():
x,y,c,d=1,1,0,1
while d!=0:
d=0
x=1
while x<=size[0]-2:
y=1
while y<=size[1]-2:
if maze[x,y]==0:
y+=1
continue
if maze[x+1,y]==0:
c+=1
if maze[x+1,y-1]==0:
c+=1
if maze[x,y-1]==0:
c+=1
if maze[x-1,y-1]==0:
c+=1
if maze[x-1,y]==0:
c+=1
if maze[x-1,y+1]==0:
c+=1
if maze[x,y+1]==0:
c+=1
if maze[x+1,y+1]==0:
c+=1
if c==7:
maze[x,y]=0
d+=1
if maze[x+1,y]==1:
maze[x+1,y]=0
elif maze[x,y+1]==1:
maze[x,y+1]=0
elif maze[x-1,y]==1:
maze[x-1,y]=0
elif maze[x,y-1]==1:
maze[x,y-1]=0
y+=1
c=0
x+=1
def nadaananNa():
c=0
if maze[x+1,y]==3:
c+=1
if maze[x,y-1]==3:
c+=1
if maze[x-1,y]==3:
c+=1
if maze[x,y+1]==3:
c+=1
return c
def intersection():
c=0
if maze[x+1,y]==1:
c+=1
if maze[x,y-1]==1:
c+=1
if maze[x-1,y]==1:
c+=1
if maze[x,y+1]==1:
c+=1
return c
def choice(x,y,d,inte):
if maze[x+1,y] == 1:
maze[x+1,y]=3
x,y=x+1,y
d+=1
elif maze[x,y+1]==1:
maze[x,y+1]=3
x,y=x,y+1
d+=1
elif maze[x-1,y] == 1:
maze[x-1,y]=3
x,y=x-1,y
d+=1
elif maze[x,y-1]==1:
maze[x,y-1]=3
x,y=x,y-1
d+=1
return x,y,d,inte
def left(x,y,d,inte):
if maze[x,y-1] == 1:
maze[x,y-1]=3
x,y=x,y-1
d+=1
return x,y,d,inte
def right(x,y,d,inte):
if maze[x,y+1]==1:
maze[x,y+1]=3
x,y=x,y+1
d+=1
return x,y,d,inte
def down(x,y,d,inte):
if maze[x+1,y] == 1:
maze[x+1,y]=3
x,y=x+1,y
d+=1
return x,y,d,inte
def up(x,y,d,inte):
if maze[x-1,y]==1:
maze[x-1,y]=3
x,y=x-1,y
d+=1
return x,y,d,inte
bigperm=0
lengths, coordinates=[],[]
print ("Mej matagal lang but it works!")
while bigperm<24:
maze = mat.imread('challenge.png')
size=np.shape(maze)
inte=[]
gr=0
p,save, Iperm=[],[],[]
perm=0
bgn=1
x,d,z,v,ct, n=0,1,0,0,0, 0
fin=1
deadend()
while x<=size[0]-2:
y=0
while y<=size[1]-2:
if maze[x,y]==1:
z=1
break
y+=1
if z==1:
break
x+=1
if dont==1:break
lengths.append(len(p))
coordinates.append(p)
bigperm+=1
lengths=np.unique(lengths).tolist()
coordinates=np.unique(coordinates).tolist()
minIndex = [i for i, q in enumerate(lengths) if q == min(lengths)]
counter=0
while counter<3:
count=0
data=coordinates[counter]
maze = mat.imread('challenge.png')
while count<len(data):
maze[data[count]]=3
count+=1
if counter==0:
print ("Shortest: " +str(coordinates[minIndex[0]])+ "\nLength: "
+str(lengths[minIndex[0]]))
mat.figure()
mat.title("Shortest")
mat.imshow(maze, cmap='binary_r')
if counter==1:
print ("1: " +str(coordinates[counter])+ "\nLength: "
+str(lengths[counter]))
mat.figure()
mat.title("1")
mat.imshow(maze, cmap='binary_r')
if counter==2:
print ("2: " +str(coordinates[counter])+ "\nLength: "
+str(lengths[counter]))
mat.figure()
mat.title("2")
mat.imshow(maze, cmap='binary_r')
counter+=1