summaryrefslogtreecommitdiff
path: root/referee.h
blob: 01211969789593f2dd400caf707b14e15f1788ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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();

	// 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 '<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.
*/