This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 6: An army of robots

Creating multiple robots

face Josiah Wang

Now that you program can generate random names for your robots, you can now create more robots to accompany your lonely robot!

First, create three robots, giving each of them a random name, initial position and direction.

Then print out a greeting from each robot as you have previously done. The greeting should show their name and ID (it is fine if their IDs are the same - we will fix this on the next page).

Finally, get each robot to navigate to its Ribena drink. You can start by getting all robots to navigate to cell (9, 9) as in the previous lesson (assume that there are three bottles of Ribena drink at (9,9), and each robot will drink only one bottle).

Then extend your program so that each robot will navigate to a different target cell, which can be one of the four corners ((0,0), (0,9), (9,0), (9,9)). You may hard code the target cells, or generate the target cells randomly (subject to the constraints mentioned). You can assume that each bottle of Ribena has been labelled with the robot’s name, and that a robot can and will only drink from its own bottle!

Finally, commit your latest changes to your repo once you are done!

Sample run

Hello. My name is Astro Boy. My ID is 1000.
Hello. My name is K-9. My ID is 1000.
Hello. My name is Daft Punk. My ID is 1000.

Astro Boy is searching for its drink.
I am currently at (4, 9), facing East.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (4, 9), facing South.
Moving one step forward.
I am currently at (5, 9), facing South.
Moving one step forward.
I am currently at (6, 9), facing South.
Moving one step forward.
I am currently at (7, 9), facing South.
Moving one step forward.
I am currently at (8, 9), facing South.
Moving one step forward.
I am currently at (9, 9), facing South.
I am drinking Ribena! I am happy!

K-9 is searching for its drink.
I am currently at (8, 0), facing West.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (8, 0), facing North.
Moving one step forward.
I am currently at (7, 0), facing North.
Moving one step forward.
I am currently at (6, 0), facing North.
Moving one step forward.
I am currently at (5, 0), facing North.
Moving one step forward.
I am currently at (4, 0), facing North.
Moving one step forward.
I am currently at (3, 0), facing North.
Moving one step forward.
I am currently at (2, 0), facing North.
Moving one step forward.
I am currently at (1, 0), facing North.
Moving one step forward.
I am currently at (0, 0), facing North.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (0, 0), facing East.
Moving one step forward.
I am currently at (0, 1), facing East.
Moving one step forward.
I am currently at (0, 2), facing East.
Moving one step forward.
I am currently at (0, 3), facing East.
Moving one step forward.
I am currently at (0, 4), facing East.
Moving one step forward.
I am currently at (0, 5), facing East.
Moving one step forward.
I am currently at (0, 6), facing East.
Moving one step forward.
I am currently at (0, 7), facing East.
Moving one step forward.
I am currently at (0, 8), facing East.
Moving one step forward.
I am currently at (0, 9), facing East.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (0, 9), facing South.
Moving one step forward.
I am currently at (1, 9), facing South.
Moving one step forward.
I am currently at (2, 9), facing South.
Moving one step forward.
I am currently at (3, 9), facing South.
Moving one step forward.
I am currently at (4, 9), facing South.
Moving one step forward.
I am currently at (5, 9), facing South.
Moving one step forward.
I am currently at (6, 9), facing South.
Moving one step forward.
I am currently at (7, 9), facing South.
Moving one step forward.
I am currently at (8, 9), facing South.
Moving one step forward.
I am currently at (9, 9), facing South.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (9, 9), facing West.
Moving one step forward.
I am currently at (9, 8), facing West.
Moving one step forward.
I am currently at (9, 7), facing West.
Moving one step forward.
I am currently at (9, 6), facing West.
Moving one step forward.
I am currently at (9, 5), facing West.
Moving one step forward.
I am currently at (9, 4), facing West.
Moving one step forward.
I am currently at (9, 3), facing West.
Moving one step forward.
I am currently at (9, 2), facing West.
Moving one step forward.
I am currently at (9, 1), facing West.
Moving one step forward.
I am currently at (9, 0), facing West.
I am drinking Ribena! I am happy!

Daft Punk is searching for its drink.
I am currently at (7, 8), facing West.
Moving one step forward.
I am currently at (7, 7), facing West.
Moving one step forward.
I am currently at (7, 6), facing West.
Moving one step forward.
I am currently at (7, 5), facing West.
Moving one step forward.
I am currently at (7, 4), facing West.
Moving one step forward.
I am currently at (7, 3), facing West.
Moving one step forward.
I am currently at (7, 2), facing West.
Moving one step forward.
I am currently at (7, 1), facing West.
Moving one step forward.
I am currently at (7, 0), facing West.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (7, 0), facing North.
Moving one step forward.
I am currently at (6, 0), facing North.
Moving one step forward.
I am currently at (5, 0), facing North.
Moving one step forward.
I am currently at (4, 0), facing North.
Moving one step forward.
I am currently at (3, 0), facing North.
Moving one step forward.
I am currently at (2, 0), facing North.
Moving one step forward.
I am currently at (1, 0), facing North.
Moving one step forward.
I am currently at (0, 0), facing North.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (0, 0), facing East.
Moving one step forward.
I am currently at (0, 1), facing East.
Moving one step forward.
I am currently at (0, 2), facing East.
Moving one step forward.
I am currently at (0, 3), facing East.
Moving one step forward.
I am currently at (0, 4), facing East.
Moving one step forward.
I am currently at (0, 5), facing East.
Moving one step forward.
I am currently at (0, 6), facing East.
Moving one step forward.
I am currently at (0, 7), facing East.
Moving one step forward.
I am currently at (0, 8), facing East.
Moving one step forward.
I am currently at (0, 9), facing East.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (0, 9), facing South.
Moving one step forward.
I am currently at (1, 9), facing South.
Moving one step forward.
I am currently at (2, 9), facing South.
Moving one step forward.
I am currently at (3, 9), facing South.
Moving one step forward.
I am currently at (4, 9), facing South.
Moving one step forward.
I am currently at (5, 9), facing South.
Moving one step forward.
I am currently at (6, 9), facing South.
Moving one step forward.
I am currently at (7, 9), facing South.
Moving one step forward.
I am currently at (8, 9), facing South.
Moving one step forward.
I am currently at (9, 9), facing South.
I am drinking Ribena! I am happy!