Making a left turn.

As we have mentioned before, Reeborg can turn in any direction ... provided it is to his left, and by 90 degrees at that. This is because his creators were too cheap to implement a better steering mechanism. To ask Reeborg to turn left you write ... turn_left()!

For example, if Reeborg is starting from his usual initial position, this simple program

move()
turn_left()
move()
turn_off()
will give rise to the following display.

simple left turn

Your turn

Have Reeborg trace a simple square, using the following program:

move()
turn_left()
move()
turn_left()
move()
turn_left()
move()
turn_left()
turn_off()
Remember that you must save your program before you can use it. Try it!

Note that, if English is not your favourite language, you can always create a synonym in your language, as long as you define it first, before using it. However, the synonym you introduce must use the English alphabet (letters without any accents). For example, in French, one might define vire_a_gauche = turn_left and use vire_a_gauche() to instruct the robot to turn left.

Your turn again!

Write a program that will make Reeborg turn counterclockwise around a square, taking 2 steps forward then turning left and repeating until he is back at his starting point facing east, his original direction, as illustrated below.

left square

Experiment!

Feel free to try to write other programs to make Reeborg move along various paths in his world.


Going home

When you enter Reeborg's world, Reeborg is usually standing on the corner of the first avenue and the first street, facing East. Click on the "Show/Hide world file" button Show/Hide world file, which is at the extreme right. You will see the display below change, with some text appearing on the right hand side. In particular, note the line that says robot = (1, 1, 'E', 0). This indicates the position of Reeborg in his world. The first number is the avenue on which Reeborg is standing, the second is the street, and the letter between the quotes indicates the direction that Reeborg is facing (E = East, N = North, W = West, S = South), East being facing right, North facing up, etc.. The fourth number (0) is the number of beepers that Reeborg carries; we will learn about beepers a bit later.

As you have seen before, you can make Reeborg move by using the up and left arrow keys on your computer keyboard. When you so move Reeborg, he doesn't leave any trace of his movements. You should notice however that the text between the parentheses in robot = (...) changes as Reeborg moves, to reflect his new position in his world.

Your turn

Using the keyboard, move Reeborg until he is standing at the corner of the third avenue and the fourth street, facing South, as indicated below. Then, write a program that will make Reeborg start from this new position and go back to the corner of the first avenue and the first street, facing East as indicated below. Try to have Reeborg take fewer steps and turns to do this than we have shown below.

back home start lead to back home end

previous Any comments? Avez-vous des commentaires? - home - Beepers next
../images/SourceForge.net Logo