Intermediate Python
API is short for application programming interface. It tells you how your program can interact with another program. In this case, it tells you how you can communicate with Kurono.
The aim of the Kurono game is to move around the map, avoiding obstacles and picking up different types of artefacts to return to a museum. You do this by writing Python code. The map is a 31 x 31 grid of cells and Kurono uses x and y coordinates to identify each cell.
You type your Python code in the code area and press Run Code to send it to Kurono. Assuming there are no syntax errors, Kurono will update the code it uses for your turn. You will notice your avatar on the map. If you are in classroom, there will be lots of others. You can identify yourself by the blue symbol and locate your avatar using the Find Me button. If your code prints anything, it will appear in the console area. This can get quite full of messages, so press the bin symbol to clear it. If you need to get the starter code back, press the Reset Code button.
When you first start in Kurono, you will find some code already there. This starter code is shown below.
Kurono uses a similar idea to a traditional board game. You can only make a move if it is your turn. When it is your turn, Kurono will call the code in your next_turn()
subroutine and run whatever code it finds there. Your code must create an Action
and return
it. Below is a full explanation of the starter code:
The world_state
object tells you things about the map.
The avatar_state
object tells you things about your avatar.
An Action
is the move you can make on a given turn. There are different types of actions:
Instruction
Definition
def next_turn(world_state, avatar_state):
Defines a subroutine called next_turn()
. This subroutine is sent the world_state
and avatar_state
objects which you can use to find out more about the map and your avatar. See below for their API.
direction.NORTH
Gets the NORTH
direction constant
MoveAction()
Turns the compass direction into a Kurono MoveAction
return
Returns your move to Kurono
Instruction
Definition
get_cell(location)
Gets the cell
at a specified location
can_move_to(location)
Returns a Boolean indicating if you can move to the cell in location
scan_nearby()
Returns a list of the 5 artefacts nearest to your avatar's location
Instruction
Definition
location
Gets the cell
of the location of your avatar
backpack
Returns the list of items inside your backpack
Instruction
Definition
direction.NORTH
Moves the avatar in a northerly direction
direction.SOUTH
Moves the avatar in a southerly direction
direction.EAST
Moves the avatar in a easterly direction
direction.WEST
Moves the avatar in a westerly direction
Instruction
Definition
MoveAction()
Asks the game to move your avatar to a new location
WaitAction()
Do not make a move
PickupAction()
Pick up an artefact from the current cell and add it to the avatar's backpack
MoveTowardsAction(artefact)
Move your avatar towards the artefact passed in as a parameter
Instruction
Definition
location
Gets the location object from a specific location
has_artefact()
Returns a Boolean indicating if there is an artefact on the cell