Student challenge 3
Ancient
In the last challenge, you found out how to avoid obstacles on the map and how to pick up any artefacts you encountered. You are now familiar with your equipment and have managed to unlock the gateway to the first time checkpoint.
Task 1: Direction Control
Your avatar has been wandering the map aimlessly up to now. In this challenge, you are going to try to pick up five artefacts scattered across the sand and examine what type of artefact you have found.
Now you have got this far, you can use some more built-in code to help you move around and navigate.
The new subroutine world_state.scan_nearby()
returns a list of nearby artefacts (shown below). 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.
Start with this code and watch to see what is going on.
Once you are satisfied that it is working, add code so that you pick up any artefacts you find and then head off to look for more.
Remember that you can use this code to check for artefacts and pick them up.
Your code must return an action. It can be a MoveAction, PickupAction
or a MoveTowardsAction
.
Task 2: Pick up Five Artefacts
Now you have more control over your avatar’s direction, can you pick up five artefacts? my_backpack
is a list of artefacts. Try it using this command:
This code lets you look inside your backpack:
Think of your backpack as a list of items. Writing len(my_backpack)
gets the length of your backpack, i.e. how many items are in it.
Final Task
Add some code that outputs how many items you have in your backpack and prints out "I have five artefacts, I win!" when you have picked up five.
Kurono uses subroutines. If you create a variable inside a subroutine, it is local so other subroutines cannot access it directly. Its value is also reset every time you call the subroutine. The code below will not work! It will always print "There are 1 things in my backpack", no matter how many artefacts you have picked up.
Task 3: Types of artefact
You might have noticed that there are different types of artefacts. Later on, you will need to check their type before picking them. For now, just make sure you know what you have. In this challenge, there are only key and chest artefacts. You can find out what you have in your backpack by looking at the artefact.type
for an item in your backpack. This code outputs the artefact type of the first artefact in your backpack.
NB: This code will crash if your backpack is empty!
Challenge part 1
Expand your program so that it outputs the types of all artefacts in your backpack when you have picked up five.
Challenge part 2
The artefacts on this level are key or chest only. Expand your program so that it outputs a summary of what you have in your backpack. E.g. I have 3 keys and 2 chests
Summary
Well done! You are really getting to grips with controlling your avatar now. You have found out how to control direction, how to examine your backpack and how to find out about the artefacts you are holding. You have also managed to find two different types of valuable artefacts to return to the museum with your class.
To be continued...
Last updated