Lexico Quick Reference Guide

Your Main Function: calculateMove(gameState)

The calculateMove(gameState) function is the equivalent of your main function. This is where you need to make your changes and where you will control the game.
The calculateMove(gameState) function receives information about the game in a Python dictionary called gameState() and returns a game move.

Understanding the Gamestate

The gameState is where all of the game information is held. It is a Python dictionary. Examples of accessing data in the gameState would be:
#This will return the current state of the board
gameState["Board"]
Your calculateMove(gameState) function will be passed the current state of the game, in the form of the gameState.
The gameState contains the following keys:

  • Board - A list of rows, where each row is a list of strings. This represents the state of the board. (See Understanding The Board)
  • IsMover - A Boolean value indicating whether it is your turn to move. It will always be true when in the calculate_move() function.
  • ResponseDeadline - The epoch time, in milliseconds, that a successful move has to be sent and received by to prevent you from timing out.
  • MyHand - Your current hand of tiles. These are the tiles you can play on the board, or exchange with tiles in the bag.
  • NumberOfTilesInBag - The number of tiles left in the bag.
  • MoveTime - The time you get to make a move, in milliseconds.
  • Dictionary - The link to the dictionary used in the game.
  • BlanksList - A list of the positions of blank tiles that have been played on the board.
  • DoubleWordList - A list of the positions of double word spaces on the board.
  • DoubelLetterList - A list of the positions of double letter spaces on the board.
  • TripleWordList - A list of the positions of triple word spaces on the board.
  • TripleLetterList - A list of the positions of triple letter spaces on the board.
  • FirstGo - A Boolean value indicating whether it is the first turn of the game.
  • TileScores - A dictionary of points you get when you place a letter to create a word.
  • MyScore - Your current score in this game, which increases whenever you place tiles to create a word. The player with the largest score at the end wins.
  • OppScore - Your opponent's current score in this game, which increased whenever they place tiles to create a word. The player with the largest score at the end wins.
  • 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 strings on the board contain either " " if the position is blank or a capital letter, for example "A", if a tile has been placed there.
The indices of the board are as follows:
board[y][x] denotes the position or square (x+1,y+1) on the board, or the intersection of the y-th row with the x-th column. For example, the middle of the board (in the 15x15 version) is board[7][7], and the bottom right-hand corner is board[0][14].

Making a Valid Move

The value you have to return from the calculate_move() function is a list.
The first entry in that list is a list of the tiles in your hand you are either playing or exchanging, e.g. ["A","B","C"].
The second entry in that list is a list of the corresponding positions (which are lists of length 2) of each of those tiles, e.g. [[6,7],[7,7],[8,7]]. The first value in each coordinate is the x-value, and the second is the y-value.
If you choose to pass your turn rather than play tiles, this second entry must be ["Pass"].
If you are playing the Multipliers Game Style with Blank Tiles, the value of these blanks must be added to a third entry of the output, e.g. ["X"].
Here are three examples of valid moves:
1) [["C", "A", "R"], [[6,7], [7,7], [8,7]]]
2) [["C", "A", "R"], ["Pass"]]
3) [["C", "A", "Blank"], [[6,7], [7,7], [8,7]],["R"]]

Helper Functions

1) dictionary_retrieval(gameState)- Given the current gamestate, returns a list of the words that can be used in this game.

Jargon

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