Can any one solve this CS1Robots Module problem?

Joined
Dec 1, 2024
Messages
1
Reaction score
0
the code below is supposed to solve the the rain2.wld world from the cs1robots module. But right now the robot is not finishing its path. Instead it is just going straight. Can anyone do it?

from cs1robots import *

load_world("rain2")
h = Robot(avenue=9, street=3, orientation='S', beepers=10)
h.set_trace("blue")
h.set_pause(0.3)


while not h.on_beeper():
if h.right_is_clear():
h.drop_beeper()
h.move()
if h.front_is_clear():
h.move()
elif h.left_is_clear():
h.turn_left()
 
Joined
Sep 21, 2022
Messages
216
Reaction score
32
This could use improvement, but it should keep the bot inside the room.
Code:
while whatever
  (this is the only move that advances the journey)
  move
  (the other moves are reversed)
  if not front is clear
    turn left
  else
    if right is clear
      (should I turn right?)
      move
      if right is clear
        (yes, I should have)
        (I'm off the wall)
        turn left
        turn left
        move
        turn left
      else
        (no, it was a gap, not a corner)
        (reverse the move)
        turn left
        turn left
        move
        turn left
        turn left
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,466
Latest member
DrusillaYa

Latest Threads

Top