Which turtle can reach the finish line first?

★★★

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

Racing turtle

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.

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:
    • Sets the pen colour using the equivalent silk constant. E.g. turtle 0 is red, turtle 1 is blue etc.
    • Sets the pen size to be 3.
    • Appends the new turtle to the list t.
    • 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

Restricted automated feedback

Automated feedback for this assignment is still under construction. Submitted programs are checked for syntax errors and their source code is checked for potential errors, bugs, stylistic issues, and suspicious constructs. However, no checks are performed yet to see if the program correctly implements the behaviour specified in the assignment.