-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythontest24a.py
More file actions
70 lines (49 loc) · 1.07 KB
/
Copy pathpythontest24a.py
File metadata and controls
70 lines (49 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import Image
import operator
import sys
global ii
sys.setrecursionlimit(50000)
im = Image.open("maze.png")
imdata = im.getdata()
x=639
y=0
dir=2
ii=0
def checkspot(x,y,d):
global ii
global im
ii = ii + 1
print ii
if y==640:
return 1
r = operator.mod(d-1,4)
l = operator.mod(d+1,4)
solved = 0
p=im.getpixel((x+mydir(d)[0],y+mydir(d)[1]))
if p[1]==0:
if checkspot(x+mydir(d)[0],y+mydir(d)[1],d)==1:
im.putpixel((x,y),(p[0],p[1],240,p[3]))
solved = 1
if solved == 0:
p=im.getpixel((x+mydir(r)[0],y+mydir(r)[1]))
if p[1]==0:
if checkspot(x+mydir(r)[0],y+mydir(r)[1],r)==1:
im.putpixel((x,y),(p[0],p[1],240,p[3]))
solved = 1
if solved == 0:
p=im.getpixel((x+mydir(l)[0],y+mydir(l)[1]))
if p[1]==0:
if checkspot(x+mydir(l)[0],y+mydir(l)[1],l)==1:
im.putpixel((x,y),(p[0],p[1],240,p[3]))
solved = 1
return 0
def mydir(d):
if d==0:
return (0,-1)
elif d==1:
return (1,0)
elif d==2:
return (0,1)
return (-1,0)
checkspot(x,y,dir)
im.save("maze2.png")