Session 5
Extension group activity — Explain why the general program does not work for some more complex maps
Note: Depending on your students’ ability and previous experience in programming, this may be suitable for some of the class. This lesson could also be used in Intermediate Key Stage 3.
Objectives
To understand why their general solution for a single route may not work on a complex route with junctions
To understand the if... do… else if… statement
To understand that the order of the if statements in your program makes a difference
Resources | Vocabulary |
---|---|
• Levels 39 to 43 in Rapid Router • Resource sheet • Interactive Whiteboard (IWB) | • If... do... else if... |
Let's get started
Recap on the else if statement discussed at the end of the last session (session 4).
Can we re–create our general solution for any single road, where the van checks through the conditions in order before each move?
Show level 39 on the IWB [fig S5.1].
Create this code together on the IWB:
Would it work here?
Would our general solution program work if we had a route with a fork or a junction in the road?
What would we need if the road reaches a dead end? What would the van have to do?
Introduce the dead end condition for the road, and the turn around instruction.
If we add another else if statement for the dead end, will it work? What would happen if we put the: if road exists left... do turn left first?
Look at the score for these solutions. Can you think of a reason why we did not get the highest score?
The algorithm is neat, but actually the route is not the shortest.
This would score higher:
Independent practical exercise time
Explore levels 39 to 41.
Can you re–sequence your general solution so that it works? Discuss with your partner how the movement is different depending on which if statement comes first.
Note: Levels 40 and 41 can be solved by a general algorithm which will also take the shortest route.
The resource sheet [fig S5.2] could be a helpful template for students to note down their ideas and record what worked.
Share and review
Look at level 42 [fig S5.3] — what is the simple solution?
Would our general solution work? If not, why not?
This is the simple solution:
Further extension
At level 43 [fig S5.4], a solution using repeat until at destination will work, but it is not the shortest route, and will not get the highest score in the game. That will go to the direct solution.
This could be a homework challenge for your gifted and talented pupils. Find the shortest route, but also find a repeat until at destination loop that works.
How much further will the van travel if it follows the repeat until at destination route?
Last updated