This site requires JavaScript, please enable it in your browser!
Greenfoot back
sebaqu
sebaqu wrote ...

2012/4/2

New to Greenfoot

sebaqu sebaqu

2012/4/2

#
Hello I'm new to Greenfoot and need help making a code that makes a robot in a maze cover every ground of the maze (move forward, if obstacle in front, turn right or left then move forward again). I know what I want to have the robot do, but I get a lot of errors all the time. Can somebody help me? Thanks
danpost danpost

2012/4/2

#
The easiest thing to do is on each act cycle: 1) turn left (keep hand on left wall) 2) move(1) 3) if (blocked) move(-1) (wall was still there) 4) turn right 5) move(1) 6) if (blocked) move (-1) (wall in front now also) 7) turn right 8) move(1) 9) if (blocked) move(-1) (Oh no! dead end) 10) turn right 11) move(1) (back from whence I came) After step (1), you could make use of a 'for' loop to repeat 2 through 4 (4 times -- once for each direction). There are a few advanced mazes that this will not work for (they would have a path that goes forth and completes a cycle back to itself (basically: a maze inside of a maze); the robot will never make it to the inner curcuit) (check out my most recent scenario: The Maze Factory.)
You need to login to post a reply.