AI Gaming
Search
⌃K

Word Extraction

Word Extraction is a game about finding the important information from a string of text.
You will be given a piece of text, such as a sentence or phrase, and a list of categories of information to extract from that text.

Strategy

The template code gives you an example of how to find any text from the string which matches a string in the dictionary, case insensitively. What happens if a phrase does not appear contiguously in text? For instance, in the phrase "Increased tyre pressure", the action may be "increased pressure", but the template code would not find this in the text. How could you fix this?
Harder: How could you go about this without a dictionary provided to you?

Programmer's Reference

Making a move

The calculate_move() function is the equivalent of your main function. This is where you need to make your changes and from where you will control the game. The function:
  1. 1.
    Receives information about the game in a Python dictionary called 'gamestate'.
  2. 2.
    Returns a game move.

The gamestate

In order to work out what move you want to make, the calculate_move() function is given as input the gamestate. The gamestate is a Python dictionary where all of the game information is held. Examples of accessing data in the gamestate are:
gamestate["Question"] # the text from which you will extract information
gamestate["MyScore"] # the number of points you have scored
The gamestate contains the following keys:
Key
Description
Mode
A string describing the style of the game. The mode "DICTIONARY" indicates that you will be given a dictionary in the gamestate. Gamestyles 8201 and 8202 both have the mode "DICTIONARY"
Question
A string of text containing information.
Categories
The name of each type of information that you are to find (e.g. "subject", "action") from the text in gamestate["Question"].
Dictionary
Only provided if mode is "DICTIONARY". If so, then it is a dictionary consisting of the categories in gamestate["Categories"] as keys, and a list of possible strings for that category as values.
RoundNumber
The round number you are on, 0-indexed so that the first round is Round 0. (That is, it is the number of answers you have already submitted.)
IsMover
A Boolean value indicating whether it is your turn to move. It will always be true when the calculate_move() function has been called.
EndTime
The epoch time, in milliseconds, that the game will end at, unless both players finish submitting images before this time. (Epoch time is the amount of time that has passed since midnight on 1 January 1970, which can be accessed in Python with time.time().)
GameStatus
A string that will have value "RUNNING" if the game is in progress or a reason the game has ended otherwise.
MyScore
Your current score—the number of correct key-value pairs you have submitted so far in the current game.
OppScore
Your opponent’s score—the number of correct key-value pairs they have submitted so far in the current game.
An example gamestate:
{
'Mode': 1,
'IsMover': True,
'URL': 'https://s3.eu-west-2.amazonaws.com/aigaming/VehicleComponentRecognition/Games/a87e3324-be85-464e-9d8c-c381ac0c6629/image_1.jpg',
'Information': ['numberplate'],
'MaxRounds': 3,
'RoundNumber': 0,
'MyPoints': 0,
'OppPoints': 0,
'EndTime': 1567763780146,
'GameStatus': 'RUNNING',
'InvalidMove': None,
'OpponentId': 'housebot-practise'
}

Processing the form

You need a Microsoft API subscription key to play this game. The template code you are given takes you through how to get a JSON object analysis of the image by making a POST request with your key and the image URL. To understand the format of the object, take a look at the comments in the template code under the header "API return value". To help you process some of its information, helper functions are given in the template code.

Making a valid move

Every time it is your turn, the game engine will run your calculate_move() function, which needs to return a valid move. A valid move is any dictionary. It should contain as keys the elements of gamestate["Categories"], and as values any text which you found that matches those categories.

Helper functions

The following helper function is provided in the template code:
  • extract(category, text, dictionary) – A function which tries to find a substring of the specified type "category" in the string "text". The "dictionary" parameter is optional, to be used where the mode is "DICTIONARY". In the template code, the function is only implemented for this mode.