Racing turtles

Racing turtle

Which turtle can reach the finish line first?

With multiple turtles and a random forward movement, a race can be simulated.

Make


Write a program that runs a race of up to 8 turtles moving up the screen 240 pixels from a starting position. Each turtle can move between 0-10 pixels in each turn. All the turtles will finish the race, but once a turtle has reached the finish line it will stop moving. The results of the race should be output.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, condition or iteration to explain its purpose.

Extend the `main program` so that:

  1. A number of turtles equal to the constant `racing_turtles` are created. For each turtle it:
  2. Sets the pen colour using the equivalent `silk` constant. E.g. turtle 0 is red, turtle 1 is blue etc.
  3. Sets the pen size to be 3.
  4. Appends the new turtle to the list `t`.
  5. Appends the value 0 to the list `position`.

Complete the subprogram called `draw_finish_line` that:

  1. Creates a new turtle `referee` that moves up the screen to the `finish_line`.
  2. Draws a black horizontal line equal to the number of racing turtles multiplied by 50.
  3. Moves back to where it started drawing the line plus an additional 50 pixels. (This moves the referee to the left of the first racing turtle).

Complete the `main program` so that:

  1. The `draw_finish_line` subprogram is called.
  2. The `starters_orders` subprogram is called.
  3. The `race` subprogram is called.

Complete the subprogram called `starters_orders` that:

  1. Places each racing turtle 50 pixels apart (at the starting position).
  2. Each racing turtle is facing upwards.

Complete the subprogram called `race` that:

  1. Outputs the word, "Results:".
  2. Repeats until all the turtles have met or crossed the finish line.
  3. Moves each turtle forward a random number of pixels between 0 and the constant `speed` if it has not already finished the race.
  4. When a turtle reaches the finish line it's finishing position and colour are output. E.g. if green crossed the finish line first it would output, "1 : green".

Typical outputs from the program would be:

Results:

1 : salmon

2 : purple

3 : blue

4 : green

5 : red

6 : orange

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


Check that your program outputs the expected result and has met the success criteria.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.