-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoneMasonKarel.py
More file actions
47 lines (38 loc) · 1.06 KB
/
StoneMasonKarel.py
File metadata and controls
47 lines (38 loc) · 1.06 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
from karel.stanfordkarel import *
"""
Makes Karel repair all the walls in any world
Pre: Karel starts at the 1st row and 1st column, facing east
Post: Karel ends at the last row and the last column, facing east
Fencepost error is solved by repeating "repair wall" command
"""
def main():
for i in range(3):
repair_wall()
move_to_the_wall()
repair_wall()
"""Karel repairs the wall and going back to his initial position"""
def repair_wall():
turn_left()
while front_is_clear():
if beepers_present():
move()
else:
put_beeper()
if front_is_blocked():
if no_beepers_present():
put_beeper()
go_back()
"""Brining Karel back to the ground"""
def go_back():
turn_left()
turn_left()
while front_is_clear():
move()
turn_left()
"""Karel moves to the next wall"""
def move_to_the_wall():
for i in range(4):
move()
# There is no need to edit code beyond this point
if __name__ == "__main__":
run_karel_program()