File specification

A valid Othello AI consists of a Python file, version 3+, with a class called Strategy containing a method called best_strategy with the arguments board, player, best_move, still_running in that order. best_move and still_running are multiprocessing.Value objects. They can be accessed and modified by doing best_move.value=34 or print(still_running.value). The still_running variable will start as 1 but will change to 0 when your processing time is about to run out.

You do not need to import the multiprocessing library to access these objects

In addition to the method specification above, the best_strategy method can accept an additional parameter that would represent the time limit. In this case the method header would be def best_strategy(board, player, best_move, still_running, time_limit). If you choose to include the additional parameter, an integer representing the amount of time allocated to your script will be passed to the function.

Note: The best_strategy method has to follow one of the above specification. Depending on the method header, the Othello server will choose the appropriate parameters to pass.

Note: Your script will be automatically cut off regardless of whether or not your code uses the still_running parameter

Warning: All user code will be run in a daemonized multiprocessing.Process. This means your script cannot spawn any Processes of its own. If your code does spawn any multiprocessing.Process instances, it will error out.

The board will be a length-64 string of characters from the set {'.', 'x', 'o'}. An '.' represents an empty space, 'x' a black token, and 'o' a white token. A valid move is with in the range 0-63, inclusive, and represents an index on the board string where the current player will place a piece.

Scripts submitted before the 2020-21 school year are now invalid!

Students who submitted before the 2020-21 school year must now revise their code to recognize the 8x8 board(instead of the previous 10x10 board) and modify the set of characters to {'.','x','o'}(instead of the previous {'.','@','o','?'}) and resubmit their script.

Upload Errors

When uploading code to the server you may encounter one of the following errors.

If you encounter another error message that you cannot interpret, email a screenshot of the error message as well as your code.


In addition to the specifications listed above, your Strategy class may contain a logging variable. This variable, if used, must be an attribute of the Strategy class. Therefore it should be defined within Strategy's constructor (as self.logging) or inside the class but outside a class method (just logging). For instance, logging cannot be defined in the best_strategy method of your Strategy class or in a helper method defined outside of Strategy.

If set to True, you will see the output of any print statements on either side of the board when playing your script. Output for scripts that are playing as black will appear on the left-hand side of the Othello board while the output for scripts that are playing as white will appear on the right-hand side of the Othello board.

If you omit the logging variable in your Strategy class, it will be assumed that you do not wish to output any print statements.

Warning: If you set logging = True in your Strategy class, you will only be able to view your logging output only if you are currently logged in. If logged in, you will be able to see your logs whenever your script is being played, including if you are watching your script. Unauthenticated users and users who do not own the running script will not be able to view the logs.

Playing Games and Errors

To play a game, go to the Play page and select two players. To watch a game, go to the Watch page and select one of the listed games. If there are no games currently being played, no games will be listed.

When playing games, if your script behaves incorrectly, the server will interpret this as an UserError. When the server encounters an UserError, your script will automatically forfeit the game and your opponent will be awarded the win. The UserError will be reported in either log area, regardless if the playing script set the logging variable. The following are the possible UserError codes and their meanings:

If any other error code is outputted, namely an error code within {-4,-5,-6, -7, -8}, this means the server has encountered an error while running your game. In this case, the game will be marked as a tie between both players, but you should email a screenshot of the game along with your code so we can investigate and fix this error.

Finally, when running a non-tournament game, the server continuously checks if the browser which initiated the game is still watching the game. If not, the game will be terminated and the game will end in a tie. Meaning, if you start a game but then close the window with the game still running, the game will be terminated and end in a tie.

Example code

To get you started, here is the most basic form of AI, random choice:

import random
import time

class Strategy:
    # implement all the required methods on your own
    logging = True # turns on logging
    def best_strategy(self, board, player, best_move, running):
        if running.value:
            best_move.value = random.choice(self.legal_moves(board, player))
            # Note: It is not required for your Strategy class to have a "legal_moves" method,
            # but you must determine legal moves yourself. The server will NOT accept invalid moves.

Multiple files

You may submit code any amount of times, and the Othello server will record and store all your submissions. If you wish, you may retrieve any previously submitted script from the upload page. However, the Othello Server will only run your most recent submission.

All your code submissions will persist on the Othello server, and you can retrieve previous submissions through the Upload Page. The Othello server will always use your most recent code submission when running your AI against other players. (If you were to submit twice, your second submission would be used to play against other users)

Note: When uploading a script, you will be given an option to attach a "name" or "label" to that script. Adding a "name" to your script will make it easier to identify previous submissions if you wish to retrieve them later. If omitted, your script's "name" will default to the time it was submitted.

Running Multiple Files

As of now the Othello server will only run the most recently uploaded script. You should try to put all your code in a single file and upload that file. Any files created by your code will persist between runs and games. If you do in fact need other files for your code to work, and it is infeasible to include it in one file, contact or your AI teacher about your situation.

Warning: When your code is uploaded, it is stored under a different, randomly-generated filename. Submitting two Python files and expecting to be able to import the other file by name is infeasible.

Other Info

If your code fails to return a move, returns an invalid move, or errors for whatever reason, it will be treated as a forfeit. As such, make sure you code works on your computer before using this website to test against other AIs. Just as a reminder, if your code is caught cheating during the tournament in any way, you will be given an integrity violation, so just don't do it.