Noughts And Crosses Quick Reference Guide

Understanding The Gamestate

Your calculate_move() 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 strings representing 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.
  • Role - A string of value either "O", indicating you are playing as noughts, or "X", indicating you are playing as crosses.
  • ResponseDeadline - The epoch time, in milliseconds, that a successful move has to be sent and received by to prevent you from timing out.
  • DealNumber - Which deal you are up to in the match, this key only appears when the value of DealsTotal is greater than 1.
  • DealsTotal - The total number of times you are going to play a whole game of battleships in this match, this key only appears when the value is greater than 1.
  • MyScore - Your current score in this game, increases by one for every deal you win. The player with the largest score at the end wins.
  • OppScore - Your opponent's current score in this game, increases by one for every deal they win. 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 Boards

The strings in your board can contain the following values:

  • " " - A position that is blank.
  • "O" - A position that contains a nought.
  • "X" - A position that contains a cross.

The indices of the board represent the following positions on the noughts and crosses grid:

blankNacBoard.png

Making A Valid Move

The value you have to return from the calculate_move() function is a key value pair, 'Position', which has value equal to the index of the position on the board you wish to make your move:

Here is an example of a valid noughts and crosses move:

{
    "Position": 4
}

And its result on a blank board when playing with role "X":

centerNacBoard.png

Helper Functions

  • random_guesser(gamestate) - Given the current gamestate, returns a valid move that randomly guesses a free position on the board.
  • opp_two_in_row(gamestate) - Given the current gamestate, returns the (first) location that will block your opponent from winning, returns -1 otherwise.
  • two_in_row(gamestate) - Given the current gamestate, returns the (first) location that will give you three in a row.

Jargon:

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