From 57a1091dfb2c6403cbe63c7ddca8acc7e3d0f940 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 20 Aug 2018 23:51:16 +0200 Subject: Switch to https://git.tomsmeding.com/competition --- referee/.gitignore | 1 + referee/Makefile | 13 ++++++++++ referee/referee.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 referee/.gitignore create mode 100644 referee/Makefile create mode 100644 referee/referee.cpp (limited to 'referee') 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 +#include +#include +#include +#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 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; + } +} -- cgit v1.2.3-70-g09d2