-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythontest24c.py
More file actions
73 lines (58 loc) · 1.17 KB
/
Copy pathpythontest24c.py
File metadata and controls
73 lines (58 loc) · 1.17 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
71
72
73
import Image
import operator
def mydir(d):
if d==0:
return (0,-1)
elif d==1:
return (1,0)
elif d==2:
return (0,1)
return (-1,0)
im = Image.open("maze3.png")
myFile=file('mazedump2.txt','wb')
imdata = im.getdata()
print im.getpixel((640,0))
print im.getpixel((639,0))
print im.getpixel((637,3))
x=639
y=0
fw=2
ii=0
cnt=0
p = im.getpixel((x,y))
while (y < 640):
rt = operator.mod(fw-1,4)
lt = operator.mod(fw+1,4)
if operator.mod(ii,2)==0:
p = im.getpixel((x,y))
myFile.write(chr(p[0]))
d = mydir(rt)
p = im.getpixel((x+d[0],y+d[1]))
if p[2] > 0:
x = x + d[0]
y = y + d[1]
fw = rt
ii = ii + 1
else:
d = mydir(fw)
p = im.getpixel((x+d[0],y+d[1]))
if p[2] > 0:
x = x + d[0]
y = y + d[1]
#fw = fw
ii = ii + 1
else:
d = mydir(lt)
p = im.getpixel((x+d[0],y+d[1]))
if p[2] > 0:
x = x + d[0]
y = y + d[1]
fw = lt
ii = ii + 1
else:
print "ACK I got lost at " + str(x) + "," + str(y) + " after " + str(ii) + " steps"
y = 640
if operator.mod(ii,10000) == 0:
print str(x) + "," + str(y) + " " + str(fw)
print ii
myFile.close()