-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMLp1_py_ang_100dy_day6_function
182 lines (147 loc) · 2.89 KB
/
MLp1_py_ang_100dy_day6_function
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Day - 6
Reeborgs World
Programming game
6.4 Reeborg's World
Reeborg's World is a free "Karel the robot" type of environment used to teach programming, using either Python or Javascript.
Exercise 6.1 Hurdles with constant-height
def turn_right():
turn_left()
turn_left()
turn_left()
while not at_goal():
move()
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
Exercise 6.2 Hurdles with constant-height and variable-distance
def turn_right():
turn_left()
turn_left()
turn_left()
def jump():
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
while not at_goal():
if wall_in_front():
jump()
else:
move()
Exercise 6.3 Hurdles with height
#<mycode>
def turn_right():
turn_left()
turn_left()
turn_left()
def jump():
turn_right()
move()
turn_right()
move()
while not at_goal():
while wall_on_right() and wall_in_front:
if wall_in_front():
turn_left()
elif wall_on_right:
if at_goal():
done()
else:
move()
jump()
#<angela's code>
def turn_right():
turn_left()
turn_left()
turn_left()
def jump():
turn_left()
while wall_on_right():
move()
turn_right()
move()
turn_right()
while front_is_clear():
move()
turn_left()
while not at_goal():
if wall_in_front():
jump()
else:
move()
def turn_right():
turn_left()
turn_left()
turn_left()
def up():
while wall_on_right():
move()
def down():
while front_is_clear():
move()
def jump():
turn_left()
up()
turn_right()
move()
turn_right()
down()
turn_left()
while not at_goal():
if wall_in_front():
jump()
else:
move()
Final Project : Escaping the Maze
Algorithm: following the right edge of the wall.
def turn_right():
turn_left()
turn_left()
turn_left()
#<mycode>
while not at_goal():
if wall_on_right():
if wall_in_front():
turn_left()
elif front_is_clear():
move()
else:
turn_right()
move()
#<angela's code>
def turn_right():
turn_left()
turn_left()
turn_left()
while not at_goal():
if right_is_clear():
turn_right()
move()
elif front_is_clear():
move()
else:
turn_left()
Special case: if frint and right is clear. Middle of space.
def turn_right():
turn_left()
turn_left()
turn_left()
while front_is_clear():
move()
turn_left()
while not at_goal():
if wall_on_right():
if wall_in_front():
turn_left()
else:
move()
else:
turn_right()
move()