#Name= Leulseged Atlaw
#Id.no=ugr/38341/17
#section =52
#Q1=Write a pseudo and python code that correctly runs the harvest2 world
#Python code
from cs1robots import *
load_world('harvest2')
h = Robot(avenue=6, street=2, orientation='N')
h.set_trace("red")
h.set_pause(0.03)
Y = 5
def right():
for i in range(3):
h.turn_left()
def Collector(Y):
for i in range(Y):
while h.on_beeper():
h.pick_beeper()
h.move()
right()
h.move()
h.turn_left()
for i in range(4):
Collector(Y)
h.turn_left()
for i in range(2):
h.move()
for i in range(4):
Collector (Y-2)
h.turn_left()
for i in range(2):
h.move()
for i in range(4):
Collector(Y-4)
h.turn_left()
h.move()
while h.carries_beepers():
h.drop_beeper()
Pseudo code
1. Set up the world with `harvest2` and place the robot `h` at a starting point,
facing north.
2. Get the robot ready by setting its trace color to red and a short pause between
movements.
3. Define the number 'Y` as 5.
4.Create a function `right` that makes the robot turn right by turning left three
times.
5. Create a function `Collector` that:
-Repeats the following steps `Y` times:
- if the robot is on a beeper, it picks it up.
- Moves forward one step.
- Turns right.
- Moves forward one step.
- Turns left to face the original direction.
6. Repeat the following steps four times:
- Call the `Collector` function with `Y`.
- Turn the robot left.
7. Move the robot forward twice.
8. Repeat the following steps four times:
- Call the `Collector` function with `Y - 2`.
- Turn the robot left.
9. Move the robot forward twice again.
10. Repeat the following steps four times:
- Call the `Collector` function with `Y - 4`.
- Turn the robot left.
11. Move the robot forward once.
12. Drop all beepers the robot is carrying