-
Notifications
You must be signed in to change notification settings - Fork 0
/
pentagod.cpp
66 lines (58 loc) · 1.71 KB
/
pentagod.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "pentagogtp.h"
#include "time.h"
#include <unistd.h>
#include <string>
using namespace std;
void die(int code, const string & str){
printf("%s\n", str.c_str());
exit(code);
}
int main(int argc, char **argv){
Board::test();
Move::test();
srand(Time().in_msec());
PentagoGTP gtp;
gtp.colorboard = isatty(fileno(stdout));
for(int i = 1; i < argc; i++) {
string arg = argv[i];
if(arg == "-h" || arg == "--help"){
die(255, "Usage:\n"
"\t-h --help Show this help\n"
"\t-v --verbose Give more output over gtp\n"
"\t-n --nocolor Don't output the board in color\n"
"\t-c --cmd Pass a gtp command from the command line\n"
"\t-f --file Run this gtp file before reading from stdin\n"
"\t-l --logfile Log the gtp commands in standard format to this file\n"
);
}else if(arg == "-v" || arg == "--verbose"){
gtp.verbose = true;
}else if(arg == "-n" || arg == "--nocolor"){
gtp.colorboard = false;
}else if(arg == "-c" || arg == "--cmd"){
char * ptr = argv[++i];
if(ptr == NULL) die(255, "Missing a command");
gtp.cmd(ptr);
}else if(arg == "-f" || arg == "--file"){
char * ptr = argv[++i];
if(ptr == NULL) die(255, "Missing a file to run");
FILE * fd = fopen(ptr, "r");
gtp.setinfile(fd);
gtp.setoutfile(NULL);
if(!gtp.run())
return 0;
fclose(fd);
}else if(arg == "-l" || arg == "--logfile"){
char * ptr = argv[++i];
if(ptr == NULL) die(255, "Missing a filename to log to");
FILE * fd = fopen(ptr, "w");
if(!fd) die(255, string("Failed to open file: ") + ptr);
gtp.setlogfile(fd);
}else{
die(255, "Unknown argument: " + arg + ", try --help");
}
}
gtp.setinfile(stdin);
gtp.setoutfile(stdout);
gtp.run();
return 0;
}