summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2019-02-15 21:14:28 +0100
committerTom Smeding <tom.smeding@gmail.com>2019-02-15 21:14:28 +0100
commit5c3415af4a2881b3ca7cdb4ef5bbf240b4a8b93b (patch)
tree503b4ae3890aa60a6018fd2f38c13b48d24cfaac
parente5ab9e6723e3f1dfbce6cf4188762421a86b2c87 (diff)
WIP referee for competition
-rw-r--r--Makefile2
-rw-r--r--board.h1
-rw-r--r--referee/.gitignore1
-rw-r--r--referee/Makefile13
-rw-r--r--referee/TODO.txt2
-rw-r--r--referee/referee.cpp88
6 files changed, 106 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index c1a3ee7..f0912ee 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ AI_ALL_LOWER := $(patsubst ai_%.cpp,%,$(wildcard ai_*.cpp))
TARGET_ALL := $(patsubst %,ai%,$(AI_ALL_LOWER))
-.PHONY: all clean debug
+.PHONY: all clean
all: $(TARGET)
diff --git a/board.h b/board.h
index 03f096c..6fad1e1 100644
--- a/board.h
+++ b/board.h
@@ -6,6 +6,7 @@
#include <functional>
#include <cstdint>
#include "params.h"
+#include "util.h"
using namespace std;
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..4b96779
--- /dev/null
+++ b/referee/Makefile
@@ -0,0 +1,13 @@
+CXX := g++
+CXXFLAGS := -Wall -Wextra -std=c++11 -g -O2
+TARGET := referee
+
+.PHONY: all clean
+
+all: $(TARGET)
+
+clean:
+ rm -f $(TARGET)
+
+$(TARGET): referee.cpp ../board.h ../.objs/board.o
+ $(CXX) $(CXXFLAGS) -o $@ $(filter-out %.h,$^)
diff --git a/referee/TODO.txt b/referee/TODO.txt
new file mode 100644
index 0000000..7cfd504
--- /dev/null
+++ b/referee/TODO.txt
@@ -0,0 +1,2 @@
+Should be possible to write placement strings to players BEFORE first move, to indicate colour of first stone.
+Or possibly just make it red.
diff --git a/referee/referee.cpp b/referee/referee.cpp
new file mode 100644
index 0000000..f3a2b5d
--- /dev/null
+++ b/referee/referee.cpp
@@ -0,0 +1,88 @@
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+#include <sys/time.h>
+#include "../board.h"
+
+using namespace std;
+
+
+int main() {
+ struct timeval tv;
+ gettimeofday(&tv, nullptr);
+ srandom(tv.tv_sec * 1000000U + tv.tv_usec);
+
+ string line;
+ getline(cin, line);
+ int nplayers = stoi(line);
+ assert(nplayers == NC);
+
+ vector<string> players(NC);
+ for (int i = 0; i < NC; i++) {
+ getline(cin, players[i]);
+ }
+
+ cout << "feature write_lines" << endl;
+
+ Board bd = Board::makeEmpty();
+ bd.put(BSZ * BMID + BMID, bd.bag.drawRandom());
+
+ uint8_t onturn = 1;
+
+ while (true) {
+ int pidx;
+ cin >> pidx;
+ if (!cin.good()) break;
+
+ assert(cin.get() == ' ');
+ getline(cin, line);
+
+ if ((unsigned)pidx != onturn) {
+ cout << "invalid\nwrite_end" << endl;
+ continue;
+ }
+
+ istringstream ss(line);
+ int x, y;
+ ss >> x >> y;
+ if (ss.fail()) {
+ cout << "invalid\nwrite_end" << endl;
+ continue;
+ }
+
+ x += BMID; y += BMID;
+ int idx = BSZ * y + x;
+ if (x <= 1 || x >= BSZ - 1 || y <= 1 || y >= BSZ - 1 ||
+ bd[idx] != 0 || !bd.checkEdge(idx)) {
+ cout << "invalid\nwrite_end" << endl;
+ continue;
+ }
+
+ uint8_t clr = bd.bag.drawRandom();
+ uint8_t win = bd.putCW(idx, clr);
+
+ if (win != 0 || (win == 0 && bd.bag.totalLeft() == 0)) {
+ cout << "valid end" << endl;
+ for (int i = 1; i <= NC; i++) {
+ if (i != 1) cout << ' ';
+ if ((unsigned)i == win) cout << 3;
+ else cout << 1;
+ }
+ cout << endl;
+ cout << "write_end" << endl;
+ break;
+ }
+
+ for (int i = 1; i <= NC; i++) {
+ int x = idx % BSZ - BMID, y = idx / BSZ - BMID;
+ cout << i << " place " << x << ' ' << y << ' ' << (unsigned)clr << endl;
+ }
+
+ cout << "write_end" << endl;
+
+ onturn = NEXTTURN(onturn);
+ }
+}