Microsoft Match Game - Programmer's Reference

The calculateMove() function

The calculateMove() 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.

  • Called each time you need to submit a move to the game.
  • Receives information about the game in a Python dictionary that describes the current game state.
  • Must return a game move.

Understanding The Gamestate

Your calculateMove() function will be passed the current state of the game, the 'gameState'.

The gameState is where all of the game information is held. It is a Python dictionary. The following shows an example of the gameState information that you will receive for each move of the game and some examples of how to access data within it.

For Match Game, the most important fields are Board, UpturnedTiles, AnimalList and CategoryList.

Fields that you a very unlikely to need are IsMover, ResponseDeadline, GameStatus, GameId and OpponentId.

{
'Board':[
  0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0
],
'MyPoints':0,
'OppPoints':0,
'UpturnedTiles':[
  {
    'Index':3,
    'Tile':'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/fa9a2691-0974-4378-b4cd-95f20861d52c/677abb2c-c2e7-4355-ae21-390ff31e6c75.jpg'
},
  {
    'Index':14,
    'Tile':'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/fa9a2691-0974-4378-b4cd-95f20861d52c/b2b0e5f3-3102-4e1b-a1cb-a5c6ca1fb7a3.jpg'
  }
],
'OpponentMatches':0,
'CategoryList': ['Animals', 'Landmarks', 'Phrases'], 
'TileBacks':[
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/8c7113ce-63c4-4692-870b-dee23055f900.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/88765569-846b-4dd1-b403-30dec1d748dc.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/18a600b9-e677-4620-bc90-3e5393912220.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/9f90ac83-e7fb-4472-a505-2ea714f25216.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/6e134c47-4448-4de4-a7e0-ed5cb58aa970.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/c21a3da4-5c6c-4ee9-be7b-3bc1e2fdf9cb.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/47c1fb02-d073-4e5f-bd17-891e73e78040.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/2e0408c6-cd4e-4e99-8ad6-fb5ebe1da8bf.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/71a00942-6f42-4303-a9c7-3940e4689d2b.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/d238ba66-ad3e-48b2-8a35-364cd8ee287a.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/b30afc97-07a7-4bce-9523-5ffe1083f47d.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/407926a8-e253-41db-9f9f-5d1c70188f4b.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/0612cde3-8c58-4fa1-a69b-d18c621746c6.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/b45c1e76-d6e7-4920-953b-e64a143b9160.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/888728a6-a7fa-46c1-9db0-8d0594403cc4.png',
  'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/d26e9436-80b7-4856-a352-fca020c8f903/733b74e3-9757-4000-8c04-94ccf288b7bc.png'
],
'IsMover':True,
'ResponseDeadline':1541431021123,
'GameStatus':'RUNNING',
'AnimalList':[
  'cat', 'dog', 'horse', 'lion', 'turtle', 'deer', 'zebra', 'rhinoceros', 'fox', 'cow', 'chicken', 'sheep', 'antelope', 'ape', 'bear', 'cheetah', 'donkey', 'eagle', 'echidna', 'elephant', 'flamingo', 'giraffe', 'goat', 'hawk', 'heron', 'hummingbird', 'kangaroo', 'koala', 'leopard', 'meerkat', 'ostrich', 'owl', 'parrot', 'penguin', 'phasianid', 'rodent', 'salamander', 'seal', 'snake', 'squirrel', 'tiger', 'vulture', 'wolf'
],
'Bonus':'Animals',
'Multiplier':2,
'GameId':210851,
'OpponentId':'housebot-practise'
}

Examples of accessing data in the gameState would be:

gameState["Board"][0]
gameState["UpturnedTiles"][0]["Tile"]

The gameState fields explained

The following list gives a description of what each element in the gameState represents:

  • Board - A list representing each tile in the game and whether that tile has been successfully matched or not. A "1" means the tile has been matched and "0" means the tile has not yet been matched.
    • An example of the Board data could be
      'Board':[0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0]
    • You could use the Board data to determine how many sets need to be matched by calling len(gameState["Board"])
    • You would access a specific item in the list using gameState["Board"][7]. This would give you the 8th item in the list.
  • UpturnedTiles - A list of dictionaries detailing the upturned tiles for this move.
    • The upturned tiles will be the tiles you submitted as your previous move. If your previous move was Tiles: [1,10] then you will receive the image url for tile 1 and for tile 10 in the UpturnedTiles field.
    • Each upturned tile states the Index of the tile, which is its unique location, and a URL to the image that is on the tile. It is this image that you need to analyse and match.
    • An example of accessing an upturned tiles URL would be gameState["UpturnedTiles"][0]["Tile"]
    • An example of the UpturnedTiles data is
'UpturnedTiles':[
  {
    'Index':1,
    'Tile':'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/fa9a2691-0974-4378-b4cd-95f20861d52c/677abb2c-c2e7-4355-ae21-390ff31e6c75.jpg'
  },
  {
    'Index':10,
    'Tile':'https://s3.eu-west-2.amazonaws.com/aigaming/Pairs/Games/fa9a2691-0974-4378-b4cd-95f20861d52c/b2b0e5f3-3102-4e1b-a1cb-a5c6ca1fb7a3.jpg'
  }
]
  • TileBacks - A list of strings containing the images for the backs of the tiles.
  • AnimalList - A list of strings that details all possible animals that will be displayed in the game.
    • To identify that the tile image you have analysed is a picture of an animal, you can search through the tags returned from the Microsoft API to see if any of the tags contain an animal name in the AnimalList.
    • You can check to see if the name of an animal exists in the AnimalList using if "elephant" in gamestate["AnimalList"]:
  • CategoryList - A list of strings that details all possible categories that tiles will belong to in the game.
  • MyPoints - Your current points score for this game.
  • OpponentPoints - Your opponents current points score for this game.
  • OpponentMatches - The number of matched tile sets that your opponent has successfully identified.
  • Bonus - A String containing the name of a category. If your move matches two tiles in this bonus category, the score received will be multiplied by the Multiplier amount.
    • For example, this Bonus field might be set to Landmark. If you match a set of Landmark tiles while the Bonus field is set to Landmarks, your score will be multiplied by the Multiplier field value
  • Multiplier - The current score multiplier that is based on having matched tiles that are in the Bonus Category. Consecutively matching tiles in the bonus category doubles the multiplier. Not matching tiles in the bonus category resets the multiplier.
  • GameId - An integer representing the unique game id for the current game
    • You are unlikely to need the GameId for this game type
  • OpponentId - A string containing the name of your opponent
    • You are unlikely to need the OpponentId for this game type
    • * ResponseDeadline - The epoch time, in milliseconds, that a successful move has to be sent and received by to prevent you from timing out.
      • There is a time limit to how long you have to calculate your move. If you exceed this time limit your game will be terminated and your opponent will be awarded as the winner.
      • It is unlikely that you will need to check this time as timeouts are set generously to allow you time to calculate your move, however, if you see yourself timing out a lot, you may need to limit yourself using this value.
  • GameStatus - A string that will have value "RUNNING" if the game is in progress or a reason the game has ended otherwise.
    • You are unlikely to need the GameStatus for this game type
    • * IsMover - In this turned based game, this will always be true.

MAKING A VALID MOVE

The whole point of the calculateMove() function is for you to return the move you want to make in the game. In Match Game, a move is the set of tiles that you want to turn over to see if they match

You should determine which tile to turn over by remembering the tiles you have already seen and turning over the set of tiles that all have the same subject.

To submit your move, you return a dictionary with the Key Pair of "Move" and then a list of the tiles that you want to turn over. For example:

return {"Tiles": [10, 14]}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License