Microsoft Cognitive Challenge Quick Reference Guide

Understanding The Gamestate

Your calculateMove() function will be passed the current state of the game, the 'gameState'. The gameState is a python dictionary containing the following keys:

  • Images - A list containing http links to the three images you must process.
  • EndTime - The epoch time, in milliseconds at which this game will end.
  • GameLength - The total game length in milliseconds.
  • IsMover - A boolean that represents whether you can submit a route. Always set to True as long as game is running.
  • MyAnswers - A list of your best solutions so far for each of the sentences. If you have not submitted a solution the string will be blank ie ''.
  • OppAnswers - A list of your opponents best answers so far. If they have not submitted a solution the string will be blank ie ''.
  • MyDistances - A list of your current Levenshtein distances from the correct solution. A score of 0 represents you have the correct answer. For more information on how the Levenshtein distance is calculated see the challenge home page.
  • OppDistances - A list of your opponents current Levenshtein distances from the correct solution.
  • GameStatus - A string that will have value "RUNNING" if the game is in progress or a reason the game has ended otherwise.
  • GameId - An integer representing the unique game id for the current game.
  • OpponentId - A string containing the name of your opponent.

Understanding The Images

The images are in Portable Network Graphics format (.png), this is a raster graphics file format that supports lossless data compression and is the most common image format found on the internet. The image is randomly generated but the font and back ground colour will always be the same.

Submitting a sentence

To submit a sentence you need to return a dictionary containing two entries one an integer of the index of the image you want to submit the solution for and the other a string with your guess. For example:

return {'Index': 0, 'Guess': 'The quick brown fox jumps over the lazy dog'}

Would submit a guess of "The quick brown fox jumps over the lazy dog" to the image with the index of 0.

You can only submit one guess for one image at a time. Once your guess has been processed your code will be called again in calculateMove. If you wish to store information between calls to calculateMove you need to use the persistantData dictionary to retain any required information. You can submit guesses in any order that you wish ie you could start with image index 2.

If your submitted solution is worse than the one currently recorded this will be discarded and the contents of "My Answers" will not be updated in the gameState.

Helper Functions

  • imageToText(img) - Uses the Microsoft Cognitive OCR API function to return a string that possibly represents the text contained within the image. The 'img' parameter is a string that is the URL to the image you want the text from. For this function to work you will need to enter your API key at the top of the sample code in the variable "headers_visual". The key can be obtained by signing up for a free trial on the Microsoft Cognitive Services web site.
  • spellCheck(text) - Uses the Microsoft Cognitive Bing Spell Check API function to return a string which has spellings corrected. The 'text' parameter is the string that you want the spellings corrected in. Again you will need to enter a key in the variable "headers_spell" to be able to use this function.

Jargon:

  • Epoch time - The number of seconds (or in our case milliseconds) that have elapsed since January 1 1970 00:00 UTC.
iconMSCognitiveChallengeBlack.png
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License