summaryrefslogtreecommitdiff
path: root/referee
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2018-08-20 23:51:16 +0200
committerTom Smeding <tom.smeding@gmail.com>2018-08-20 23:52:03 +0200
commit57a1091dfb2c6403cbe63c7ddca8acc7e3d0f940 (patch)
treea997ed523a853d9d5fff7d5b90b12a180b00a231 /referee
parentf0b6d1b9c46578183b427bcec4bbe99ab10c7b97 (diff)
Switch to https://git.tomsmeding.com/competitionHEADmaster
Diffstat (limited to 'referee')
-rw-r--r--referee/.gitignore1
-rw-r--r--referee/Makefile13
-rw-r--r--referee/referee.cpp74
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;
+ }
+}