Skip to content

Engine API

Theodor Moroianu edited this page May 10, 2021 · 3 revisions

Intro

The engine is written in Python, and uses a jailer written in Rust, available here.

When the engine is started, it starts waiting for socket connections on a given port (currently 0.0.0.0:4242). The software used for connecting the engine to the backend is zerorpc.io.

Code Evaluation

For evaluating one, two or more bots, for each game a grader is required. The grader should include the following header: enginelib.hpp.

The included header has the following function:

/**
 * Receives the id of the player to move.
 * Returns { player_response, error } as a result.
 * If error is "", then the player successfully moved.
 * If error is not "", then player_response" should be "".
 */
std::pair <std::string, std::string> MovePlayer(int id, std::string state, double time_limit_sec = 1.);

The grader should print to stdout a log of the steps taken by the bots (the battle history), and to stderr the id of the winner.

The bots are run once for each move. Each bot should read from standard input the state of the game and print to standard output it's actions.

Calling the Engine

The engine receives a stringified JSON of the following form:

{
    "engine": "C++ code of the engine",
    "bots": [
        "C++ Code of bot #0",
        "C++ Code of bot #1",
        "C++ ..."
    ]
}

Note that any number of bots can be passed as arguments. Even only one!

Engine's Response

The engine will respond with another stringified JSON. If the compilation is unsuccessful, then the following JSON is sent back:

{
    "status": "compilation_error",
    "file": "engine / bot_0 / bot_1 ...",
    "compilation_message": "g++ compilation message"
}

If the compilation is successful, then the following JSON is sent back:

{
    "status": "ok",
    "logs": "Logs of the fight",
    "winner": "id of the winner",
    "engine_compilation_message": "compilation message of the engine",
    "bots_compilation_message": ["compilation message of the bots"],
}

If the compilation is successful, but an error occurs (for instance the engine doesn't work properly, the following JSON is sent back:

{
    "status": "error",
    "reason" "logs of the error"
}

Clone this wiki locally