#pragma once #include #include #include #include #include #include #include #include "process.h" using namespace std; class Referee { const bool verbose; Process proc; string refereeExecname; int numPlayers; string reftag; struct Features { // Referee supports current version of the protocol. bool version2; }; Features features; void queryFeatures(); public: struct ReadEvent { int player; // call with the line read (no newline) function callback; }; struct WriteEvent { int player; bool allowBrokenPipe; string line; }; struct GamelogEvent { int player; string line; }; struct EndEvent { vector scores; }; struct ErrorEvent { int player; string message; }; using Event = variant; Referee(bool verbose, const string_view execname, const vector &players); ~Referee(); Event nextEvent(); // Kills the referee process void terminate(); }; /* Referee protocol: At startup, the referee should write a number of lines to stdout of the form 'feature ', indicating that the referee supports the feature given by . The list of features should be ended with a line containing 'feature_end'. To use the version of the protocol described here, it is mandatory to request 'feature version_2'. For supported features and their effect, see below. The referee then receives a line containing the number of players in the game, followed by that number of lines containing the players' names. Then, the referee has the following commands available: - 'read ': read a line from the player with index ; this line is written directly to the referee afterwards. The first player is 0, the second player is 1, etc. - 'write ': write a line to the player with index . - 'writemaybe ': write a line to the player with index , without considering a broken pipe error to be fatal. This is useful for Quit messages because codecup players tend to exit before getting a formal Quit sometimes. - 'gamelog ': write a line in the game log indicating that the player with index made the move given by . - 'end ...': signify that the game has ended. The final scores of the players are given after 'end'. These scores should be given as a space-separated list of integers, as many as there are players. - 'error ': indicate that the player with index has produced erroneous output. This ends the game. The will be presented to the user and written to the gamelog. FEATURES Currently, the following features are supported: - 'version_2': must be used by all referees. */