Teacher Challenge 3 Guide
Introduction
Objectives
To apply algorithmic thinking to tasks to work out appropriate solutions
To expand pupils’ use of selections statements to allow for multiple routes through their code
To consolidate knowledge of local variables in subroutines
To explore standard solutions such as counting different elements in a list
Preparing for the Lesson
Timing and Prior Experience
Timing | Pupils’ prior experience |
One lesson of approximately 50 mins | Pupils should be familiar with Python programming, including the use of: |
|
Teacher Preparation
Read over the pupil worksheet.
Delivering the lesson
This lesson builds on the previous lessons and allows your pupils to further investigate the use of selection, loops, arrays and subroutines. There are opportunities for discussing efficiency, local and global variables.
Task 1 - Direction control
Pupils might have commented that they cannot easily control the direction their avatar takes. This has a great deal to do with the turn-based approach: the avatar is not designed to remember a fixed list of directions to take but rather to react to what is going on at each turn.
The new subroutine, world_state.scan_nearby()
returns a list of nearby artefacts. You need to pass in the avatar location to scan within the avatar radius. The first artefact in the list is the closest.
There is also a new action, MoveTowardsAction()
. You need to send this action an artefact to head towards.
The students will need to add the below as their starter code:
They will notice that their avatar is moving towards the artefact. It will not pick anything up though, since that code is not there yet.
Therefore, they now need to change this code to incorporate the pick-up action. The reminder given to pupils is:
Their code must return an action, in this case, it will be a PickupAction
or a MoveTowardsAction
. Here is a suggested solution:
Task 2 - Pick up five artefacts
When pupils pick up an artefact, it will disappear from the map and be moved to their backpack. They can check the number of items in their backpack using this code:
This challenge asks pupils to find five artefacts and output a message when they have achieved this. my_backpack
is a list of artefact objects so pupils can iterate (loop) over the list and examine each artefact in turn.
Potential pitfalls
Any variables defined in a subroutine are local to that subroutine and are reset when the subroutine is next called. This means that pupils cannot keep a value in a variable between turns. They don’t need to use a local variable to remember the number of items in their backpack because they can check the length at any time. However, some might try this and be confused. They can use global variables if they wish. See below.
Example solution
Task 3 - Types of artefact
Important note
The code on the pupils’ worksheets will crash if they haven’t picked up any artefacts. It is important that pupils consider how lists work if they are confused by this.
Part 1
In this part of the challenge, pupils only need to output what is in their backpack.
Part 2
The second part of the challenge asks pupils to count up the different types of artefacts found. This selection in a loop is an important standard counting algorithm.
Summary
These tasks have allowed pupils to further explore the use of selection and subroutines, as well as interacting with the Kurono API.
In the next worksheet, pupils will be able to scan areas of the map to look for artefacts and start to discover different types of artefacts.
Last updated