diff options
Diffstat (limited to 'referee')
-rw-r--r-- | referee/.gitignore | 1 | ||||
-rw-r--r-- | referee/Makefile | 13 | ||||
-rw-r--r-- | referee/referee.cpp | 74 |
3 files changed, 88 insertions, 0 deletions
diff --git a/referee/.gitignore b/referee/.gitignore new file mode 100644 index 0000000..1c8d92c --- /dev/null +++ b/referee/.gitignore @@ -0,0 +1 @@ +referee diff --git a/referee/Makefile b/referee/Makefile new file mode 100644 index 0000000..67317b2 --- /dev/null +++ b/referee/Makefile @@ -0,0 +1,13 @@ +CXX = g++ +CXXFLAGS = -Wall -Wextra -std=c++17 -g -O2 + +.PHONY: all clean + +all: referee + +clean: + rm -f referee + + +referee: referee.cpp ../board.h ../board.o + $(CXX) $(CXXFLAGS) -o $@ $< ../board.o diff --git a/referee/referee.cpp b/referee/referee.cpp new file mode 100644 index 0000000..78c4193 --- /dev/null +++ b/referee/referee.cpp @@ -0,0 +1,74 @@ +#include <iostream> +#include <sstream> +#include <string> +#include <cassert> +#include "../board.h" + + +struct MoveLine { + int pindex; + string line; +}; + +MoveLine readMoveLine() { + while (true) { + if (!isspace(cin.peek())) break; + cin.get(); + } + + MoveLine ml; + cin >> ml.pindex; + if (!cin) exit(0); + + assert(cin.get() == ' '); + getline(cin, ml.line); + + return ml; +} + +int8_t playerToClr(int player) { + return 2 * player - 1; +} + +int main() { + Board bd = Board::makeInitial(); + + int nplayers; + cin >> nplayers; + assert(nplayers == 2); + cin.ignore(1000, '\n'); + + string p1, p2; + getline(cin, p1); + getline(cin, p2); + + int onturn = 0; + + while (true) { + MoveLine ml = readMoveLine(); + if (ml.pindex != onturn) { + cout << "invalid" << endl; + continue; + } + + optional<Move> mv = Move::parse(ml.line); + + if (mv && !bd.isValid(*mv, playerToClr(onturn))) { + cout << "invalid" << endl; + continue; + } + + int win = bd.applyCW(*mv); + + if (win != 0) { + cout << "valid end" << endl; + if (win == -1) cout << "3 1" << endl; + else if (win == 1) cout << "1 3" << endl; + break; + } else { + cout << "valid" << endl; + } + + onturn = !onturn; + } +} |