Student challenge 2
Present Day II: Obstacles and Artefacts
In the last worksheet, you learned how Kurono works and wrote your first programs to move around the grid world detecting obstacles around you. In this worksheet you are going to build on this: finding the artefacts you inadvertently scattered through time. Avoid the obstacles and pick up artefacts that you find on the map.
1. Avoiding Obstacles
Start with the solution to the last challenge, you can use this example if you like. You don’t need to type in the comments. They are there to explain the code. Notice that we have set action to WaitAction()
if you don’t want to move; that is like missing a turn on a board game.
Change the code so that your avatar tries a different direction if they are unable to move. To avoid repeating code, create a subroutine called get_random_dir()
and use it to return a random direction. Think about where this would be called from and what code it will replace.
Extension Task
You might have noticed that your avatar is wandering around fairly aimlessly. Try to extend your code to favour moving in a particular direction.
2. Pick up an artefact
You might have noticed some objects on the map, other than other pupils’ avatars. These are artefacts, objects you can pick up. There are different types of artefacts, some with a special purpose. For now, your challenge is to pick up any artefact that you find on the map. In order to pick up an artefact, you must be standing on the same cell as that artefact and then you need to call some Kurono code to pick it up.
Remember that you can find out your location using avatar_state.location
which contains the x-y coordinates of your current location:
coordinates = avatar_state.location
print(coordinates)
You can ask the Kurono game to tell you if there is an artefact on that cell using the code below.
If there is an artefact on that cell, you can pick it up using this code:
action = PickupAction()
You then need to return that action at the end of the next_turn
subroutine, instead of a move action.
return action
If you are successful, the artefact will disappear from the map and be moved into your backpack! Try changing your code to pick up any artefacts you encounter.
Start with the code shown below.
Summary
Well done! You have done a lot this session. You have found out how to avoid obstacles and influence which way your avatar moves. You have also learned how to pick up artefacts.
In the next worksheet, you are going to extend these ideas and actively scan the map for artefacts as well as look for specific types of artefacts. The artefacts are all-important, we need to get them back to the museum before someone else takes them!
Last updated