Travelling Salesdrone Quick Reference

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:

  • CityCoords - A list of the city co-ordinates as positioned on a 100 by 100 grid. No two cities will share the same spot.
  • IsLeading - A Boolean value indicating whether you are winning.
  • MyBestDistance - A floating point value of the total distance of your best route submitted so far.
  • OppBestDistance - A floating point value of the total distance of your opponents best route submitted so far.
  • MyBestSolution - The list of city indexes for your current best route eg [2, 6, 3, 8, 9, 5, 4, 7, 1, 0]
  • OppBestSolution - The list of city indexes for your opponents best route eg [2, 6, 3, 8, 9, 5, 4, 7, 1, 0]
  • EndTime - The epoch time, in milliseconds at which this game will end.
  • GameLength - The total game length in milliseconds
  • DealsTotal - Not used in this game. So will always be set to 1.
  • MyScore - Not used in this game. So will always be set to 0.
  • OppScore - Not used in this game. So will always be set to 0.
  • GameStatus - A string that will have value "RUNNING" if the game is in progress or a reason the game has ended otherwise.
  • IsMover - A boolean that represents whether you can submit a route. Always set to True as long as game is running.
  • GameId - An integer representing the unique game id for the current game.
  • OpponentId - A string containing the name of your opponent.

Understanding The Map

The list contained in CityCoords are the x and y co-ordinates of all the cities in the game.
For example ([84, 87], [58, 97], [69, 17], [69, 83], [71, 36], [19, 76], [19, 22], [15, 51], [10, 64], [7, 2]) would represent a 10 city game. The top left of the board is position [0, 0].
When the game is in play these will be plotted onto a green map with each city represented as a black dot.

Submitting a route

To submit a route you need to return a list of city indexes in calculateMove. For example

return {"Path":[3,1,2,0,4,5,8,7,6,9]}

would submit a route around the cities that would suggest cities with the index of 3 and 1 are close together etc.
When the game is in play your route will be plotted onto the map. If your route is coloured yellow you are currently winning the game otherwise it will be shown in red. Your home city will be shown as a white dot with all others coloured in black.

Helper Functions

  • get_distance(origin, destination) - Given two city coordinates of the form [x, y] returns the distance between them
  • find_closest_city(coords, cur_city, available_cities) - Given the list of city coordinates, the current city index, and a list of available cities indexes to choose from calculates the closest city (from the list of available cities) to the current city and returns it. For example, find_closest_city(gamestate["CityCoords"],0,[1,2,3,4,5,6,7,8,9]) would return a number between 1 and 9 that is the closest city to city 0.

Jargon:

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