-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.cpp
47 lines (39 loc) · 1.34 KB
/
wrapper.cpp
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
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "player.h"
using namespace std;
int main(int argc, char *argv[]) {
// Read in side the player is on.
if (argc != 2) {
cerr << "usage: " << argv[0] << " side" << endl;
exit(-1);
}
Side side = (!strcmp(argv[1], "Black")) ? BLACK : WHITE;
// Initialize player.
Player *player = new Player(side);
// Tell java wrapper that we are done initializing.
cout << "Init done" << endl;
cout.flush();
int moveX, moveY, msLeft;
// Get opponent's move and time left for player each turn.
while (cin >> moveX >> moveY >> msLeft) {
Move *opponentsMove = NULL;
if (moveX >= 0 && moveY >= 0) {
opponentsMove = new Move(moveX, moveY);
}
// Get player's move and output to java wrapper.
Move *playersMove = player->doMove(opponentsMove, msLeft);
if (playersMove != NULL) {
cout << playersMove->x << " " << playersMove->y << endl;
} else {
cout << "-1 -1" << endl;
}
cout.flush();
cerr.flush();
// Delete move objects.
if (opponentsMove != NULL) delete opponentsMove;
if (playersMove != NULL) delete playersMove;
}
return 0;
}