Sliding Puzzle 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:

  • Board - A list of tile numbers which represents the starting position of the board. The 0 (Zero) is the blank tile which will always be in the bottom right corner. The board will not change throughout the game as you can only submit solutions that solve the puzzle. For more details see "Understanding the Board" in the section below.
  • ResponseDeadline - The epoch time, in milliseconds at which this game will end.
  • IsMover - A boolean that represents whether you can submit a solution. Always set to True as long as game is running.
  • MyBestSolution - Your current best solution to the puzzle. Each entry in the list is the tile number that you need to move into the blank space in sequence to complete the puzzle. If you have no solution this will be set to "None".
  • OppBestSolution - Your opponent's best solution to the puzzle. Each entry in the list is the tile number that you need to move into the blank space in sequence to complete the puzzle. If your opponent has no solution this will be set to "None".
  • IsLeader - A Boolean value indicating whether you are winning.
  • 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 Board

The board is a list of the tiles as they appear on the board. For example [[5, 1, 6], [7, 8, 2], [4, 3, 0]] would result in the board as displayed below:

spg_example_random2.png

Submitting a solution

To submit a solution you need to return a list of steps in calculateMove. Each entry in the list is the tile number that you need to move into the blank space in sequence to complete the puzzle. For example:

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

Would submit a solution where tile number 3 is the first move into the empty space etc.

When the game is in play the best solution length for each player will be shown and updated on screen. Only at the end of the game will you be shown the animated sequence of the best solution each bot has submitted.

Helper Functions

  • getValidMoves(board) - Find the potential moves that can be made from the given board configuration.
  • isValidSolution(cur_board) - Returns a boolean to say whether the given board is solved or not.
  • updateBoard(cur_board, move) - Given a board and a move, returns an updated board with the move applied to it.

Jargon:

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