summaryrefslogtreecommitdiff
path: root/referee/referee.cpp
blob: 92af0ec05a86b93464d369b9a4fb42dd483e882a (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#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);

	cout << "feature write_lines" << endl;
	cout << "feature no_last_move" << endl;
	cout << "feature_end" << endl;

	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]);
	}

	Board bd = Board::makeEmpty();
	uint8_t midstoneClr = bd.bag.drawRandom();
	bd.put(BSZ * BMID + BMID, midstoneClr);

	for (int i = 0; i < NC; i++) {
		cout << i << " place 0 0 " << (unsigned)midstoneClr << endl;
	}
	cout << "0 Start" << endl;
	cout << "write_end" << endl;

	uint8_t onturn = 1;

	while (true) {
		int pidx;
		cin >> pidx;
		if (!cin.good()) break;

		assert(cin.get() == ' ');
		getline(cin, line);

		if ((unsigned)pidx + 1 != 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\nwrite_end" << endl;
			for (int i = 1; i <= NC; i++) {
				if (i != 1) cout << ' ';
				if ((unsigned)i == win) cout << '3';
				else cout << '1';
			}
			cout << endl;
			break;
		}

		cout << "valid" << endl;

		for (int i = 0; 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);
	}
}