diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-08-20 21:53:38 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-08-20 21:53:38 +0200 |
commit | 1c42efb1b116287949e59370198cad2df465835d (patch) | |
tree | 6c191f0a629b23566763827e73071c523f0d3e2b /referee.h |
Initial
Diffstat (limited to 'referee.h')
-rw-r--r-- | referee.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/referee.h b/referee.h new file mode 100644 index 0000000..5f278c5 --- /dev/null +++ b/referee.h @@ -0,0 +1,45 @@ +#pragma once + +#include <vector> +#include <string> +#include <string_view> +#include <optional> +#include "process.h" + +using namespace std; + + +class Referee { + Process proc; + bool isEnd = false; + vector<int> scores; + + void readScores(); + +public: + Referee(const string_view execname, const vector<string> &players); + ~Referee(); + + // player: 0 = first player, 1 = second player + bool moveValid(int player, const string_view line); + + bool gameEnded(); + optional<vector<int>> getScores(); +}; + +/* +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 '<player> <line>', +where <player> is the index of the player in the game (0 is first, 1 is second, +etc.) and <line> 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. +*/ |