Lesson 6
Dealing with Sequences of Objects
Chapter 6: An army of robots
Generating a unique robot ID
Unless you have implemented otherwise, all your robots will currently have the same identifier. That is no good!
You will need to generate a unique ID for the robot, so that you can identify a robot from the multiple robots you have created.
You are free to generate the ID any way you like (it does not even have to be an integer). For example, you can keep track of the current number of robots that you have created and increment the ID for the next robot accordingly. Alternatively, you can just generate a random number between 0 to N as an ID, where N is a large number. There is a chance you might get the same number, but it should be good enough for our purposes. There are better ways to generate unique IDs, but we will keep it simple.
Update your program so that it automatically generates a (hopefully unique) ID for each robot created.
As usual, add and commit your changes once you are done!
Hello. My name is Bender. My ID is 1001.
Hello. My name is Astro Boy. My ID is 1002.
Hello. My name is The Terminator. My ID is 1003.
Bender is searching for its drink.
I am currently at (2, 0), facing South.
Moving one step forward.
I am currently at (3, 0), facing South.
Moving one step forward.
I am currently at (4, 0), facing South.
Moving one step forward.
I am currently at (5, 0), facing South.
Moving one step forward.
I am currently at (6, 0), facing South.
Moving one step forward.
I am currently at (7, 0), facing South.
Moving one step forward.
I am currently at (8, 0), facing South.
Moving one step forward.
I am currently at (9, 0), facing South.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (9, 0), facing West.
I have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (9, 0), facing North.
Moving one step forward.
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 am drinking Ribena! I am happy!
Astro Boy is searching for its drink.
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!
The Terminator is searching for its drink.
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 have a wall in front of me!
Turning 90 degrees clockwise.
I am currently at (9, 0), facing North.
Moving one step forward.
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 am drinking Ribena! I am happy!