Chapter 7: Enhancing your robot

Getting your robot to twist and turn

face Josiah Wang

Great, now your robot can walk all the way to the edge of your world. Luckily it cannot move beyond that!

Now, rather than letting your poor robot stare at a wall, let’s get it to rotate 90 degrees clockwise (i.e. to its right) so that he can see something more interesting (and perhaps move forward even more!)

Extend your program so that when a robot hits a wall, it will update its direction 90 degrees clockwise. So, if the robot is facing East, it will turn to face South. If it is facing South, it will turn to face West. And so on.

Robot rotates 90 degree clockwise after hitting an edge

Sample run #1

What is the name of the robot? Terminator
Hello. My name is Terminator. My ID is 1000.
I am currently at (3, 6), facing East. 
Moving one step forward.
I am currently at (3, 7), facing East. 
Moving one step forward.
I am currently at (3, 8), facing East. 
Moving one step forward.
I am currently at (3, 9), facing East.
I have a wall in front of me! 
Turning 90 degrees clockwise. 
I am currently at (3, 9), facing South.

Sample run #2

A sample run when the robot is already at a boundary:

What is the name of the robot? Terminator
Hello. My name is Terminator. My ID is 1000.
I am currently at (0, 7), facing North. 
I have a wall in front of me!
Turning 90 degrees clockwise. 
I am currently at (0, 7), facing East.

Again, remember to commit your code when you are done! Hopefully this has become second nature by now!