#pragma once #include #include #include #include #include #include "process.h" using namespace std; class Referee { Process proc; bool isEnd = false; vector scores; bool featureWriteLines = false; vector> writeLinesList; optional readLine(); void readScores(); public: Referee(const string_view execname, const vector &players); ~Referee(); // player: 0 = first player, 1 = second player bool moveValid(int player, const string_view line); vector> playerWriteLines(); bool gameEnded(); optional> getScores(); // Kills the referee process void terminate(); }; /* Referee protocol: At startup, the referee receives a line containing the number of players in the game, followed by that number of lines containing the players' names. Then, it repeatedly receives a line on stdin of the form ' ', where is the index of the player in the game (0 is first, 1 is second, etc.) and is the line as written out by the player. The referee should then write a line to stdout that is equal to either 'valid', 'invalid', or 'valid end'. 'valid' and 'invalid' indicate a valid and invalid move, while 'valid end' indicates a valid move that ends the game. After writing the line 'valid end', the referee should write a line containing as many integers (separated by spaces) as there are players, giving their scores at the end of the game. FEATURES At any time the referee may write 'feature ' to stdout, which enables the protocol feature with the given name. The following features are supported: - 'write_lines': After a move validity judgement, the referee should write lines of the form ' ' to stdout, where is the index of the player on whose stdin to write . The referee should signal the end of this list by writing a line 'write_end' to stdout. This allows the referee to write additional data to players' inputs after they have written their moves. */