To gain familiarity with the Kurono environment and the turn-based approach
To recap on:
selection logic
random number generation
the basic use of subroutines
Find out how to access Kurono
Create a new game for your class by assigning a worksheet
Read over the pupil worksheet
Terminology
Avatar – digital player representing the pupil
Artefact – a special object that can be collected
Console log – the area at the bottom left of Kurono, used for output (print) messages
Introduce the environment: the aim of the game, how to run your code, concepts of the map, other avatars and artefacts (see Teacher User Guide)
Explain the turn-based model. A board game is a good analogy — you're only able to make a move when it's your turn
Explain the default code as necessary
Demo changing the code — make avatar walk in one direction only
Pupils start Kurono and change the code as the teacher did to ensure that they understand
NORTH, EAST, SOUTH
and WEST
are constants in the Kurono direction
object. The code MoveAction(new_dir)
converts the direction into a MoveAction
so that Kurono can carry it out.
The return
keyword returns this move to Kurono’s turn handler.
All pupils need to do here is move in any direction other than North simply so they can try out the interface.
Ask pupils or recap on what random.randint(start, stop)
does. E.g. print(random.randint(1,6))
Pupils may need some hints to work out that they can use a randomly generated number between 1 and 4 to help them choose a random direction to go in.
Then they'll need to use an if…elif…else
statement to choose the appropriate direction constant.
Potential pitfalls:
Poor structure of if…elif…else
statement
Forgetting to put direction.
before NORTH
, EAST
, SOUTH
or WEST
Forgetting to turn the direction constant new_dir
into an action with action = MoveAction(new_dir)
Pupils will probably have noticed that their avatar bumps into obstacles and can get stuck. This next task starts to look at how to avoid this by checking if they can move onto a cell before making their move. Pupils need to start with a working solution to task 2. Give them some code and explain how it works, if necessary.
avatar_state
is an object in Kurono that knows about the avatar, including its current location. The Kurono map is arranged in a 31x31 grid using x-y coordinates. The centre of the map has coordinates of 0,0.
Cross-curricular note: pupils will know about x,y coordinates from Maths. (What is the name for cell where x is 0 and y is 0? Answer: it's the origin)
Pupils can print out the coordinates of their avatar using this code:
print(avatar_state.location)
Pupils can also find out the x and y values separately.
print("x is", avatar_state.location.x)
print("y is", avatar_state.location.y)
Having got the avatar’s location, pupils can find out if they can move onto an adjacent cell by adding a direction constant and calling worldstate.can_move_to()
.
As you can see, world_state.can_move_to
returns a Boolean value.
Pupils can use this to decide what to do next.
Worksheet 2 picks up from this point.
Notice that there is no harm done if pupils try to move onto a cell that is occupied. They simply miss their turn.
Timing
Pupils’ prior experience
One lesson of approximately 50 mins
Pupils should be familiar with Python programming, including the use of:
Variables
Assignment
Selection (if statements)
Functions and procedures (subroutines)
Parameters