38 for (s = line; *line; ++line) {
39 if (*line ==
'\t') *line =
' ';
40 if (*line ==
'#')
break;
41 if (*line < 32 && *line !=
'\n')
continue;
48static void gtp_send(
const char *s,
int id,
bool has_id)
50 if (has_id) printf(
"= %d ",
id);
53 putchar(
'\n'); fflush(stdout);
58static void gtp_fail(
const char *s,
int id,
bool has_id)
60 if (has_id) printf(
"? %d ",
id);
63 putchar(
'\n'); fflush(stdout);
74 if (strcmp(word,
"black") == 0) {
76 }
else if (strcmp(word,
"b") == 0) {
78 }
else if (strcmp(word,
"white") == 0) {
80 }
else if (strcmp(word,
"w") == 0) {
129 char *cmd = NULL, *param = NULL, *move;
133 int komi, color, size;
134 int byo_yomi_time = 0, byo_yomi_stone = 0, main_time = 315576000;
156 }
else if (strcmp(cmd,
"protocol_version") == 0) {
159 }
else if (strcmp(cmd,
"name") == 0) {
162 }
else if (strcmp(cmd,
"version") == 0) {
165 }
else if (strcmp(cmd,
"known_command") == 0) {
166 if (strcmp(param,
"protocol_version") == 0 ||
167 strcmp(param,
"name") == 0 ||
168 strcmp(param,
"version") == 0 ||
169 strcmp(param,
"known_command") == 0 ||
170 strcmp(param,
"list_commands") == 0 ||
171 strcmp(param,
"quit") == 0 ||
172 strcmp(param,
"boardsize") == 0 ||
173 strcmp(param,
"clear_board") == 0 ||
174 strcmp(param,
"komi") == 0 ||
175 strcmp(param,
"play") == 0 ||
176 strcmp(param,
"genmove") == 0 ||
177 strcmp(param,
"undo") == 0 ||
178 strcmp(param,
"time_settings") == 0 ||
179 strcmp(param,
"time_left") == 0 ||
180 strcmp(param,
"set_game") == 0 ||
181 strcmp(param,
"list_games") == 0 ||
182 strcmp(param,
"loadsgf") == 0 ||
183 strcmp(param,
"reg_genmove") == 0 ||
184 strcmp(param,
"showboard") == 0)
gtp_send(
"true",
id, has_id);
187 }
else if (strcmp(cmd,
"list_commands") == 0) {
188 gtp_send(
"protocol_version\nname\nversion\nknown_command\nlist_commands\n"
189 "quit\nboardsize\nclear_board\nkomi\nplay\ngenmove\nundo\n"
190 "time_settings\ntime_left\nset_game\nlist_games\n"
191 "loadsgf\nreg_genmove\nshowboard",
id, has_id);
193 }
else if (strcmp(cmd,
"quit") == 0 || strcmp(cmd,
"eof") == 0) {
195 free(cmd); free(param);
198 }
else if (strcmp(cmd,
"boardsize") == 0) {
200 if (size != 8)
gtp_fail(
"unacceptable size",
id, has_id);
203 }
else if (strcmp(cmd,
"clear_board") == 0) {
207 }
else if (strcmp(cmd,
"komi") == 0) {
212 }
else if (strcmp(cmd,
"play") == 0) {
214 if (color ==
EMPTY) {
215 gtp_fail(
"syntax error (wrong or missing color)",
id, has_id);
217 }
else if (color != play->
player) {
221 gtp_fail(
"wrong color", has_id,
id);
229 gtp_fail(
"illegal move",
id, has_id);
232 }
else if (strcmp(cmd,
"genmove") == 0) {
235 if (color ==
EMPTY) {
236 gtp_fail(
"syntax error (wrong or missing color)",
id, has_id);
238 }
else if (color != play->
player) {
242 gtp_fail(
"wrong color", has_id,
id);
251 }
else if (strcmp(cmd,
"undo") == 0) {
253 gtp_fail(
"cannot undo", has_id,
id);
259 }
else if (strcmp(cmd,
"time_settings") == 0) {
264 if (byo_yomi_stone > 0) {
272 }
else if (strcmp(cmd,
"time_left") == 0) {
281 if (n == 0) play->
time[color].
left = (t + byo_yomi_time * 1000) / byo_yomi_stone;
282 else play->
time[color].
left = t / n;
288 }
else if (strcmp(cmd,
"set_game") == 0) {
289 if (strcmp(param,
"Othello") == 0)
gtp_send(
"",
id, has_id);
290 else gtp_fail(
"unsupported game",
id, has_id);
292 }
else if (strcmp(cmd,
"list_games") == 0) {
296 }
else if (strcmp(cmd,
"loadsgf") == 0) {
303 }
else if (strcmp(cmd,
"reg_genmove") == 0) {
306 if (color ==
EMPTY) {
307 gtp_fail(
"syntax error (wrong or missing color)",
id, has_id);
309 }
else if (color != play->
player) {
313 gtp_fail(
"wrong color", has_id,
id);
322 }
else if (strcmp(cmd,
"showboard") == 0) {
324 if (has_id) printf(
"%d\n",
id);
326 putchar(
'\n'); fflush(stdout);
330 gtp_fail(
"unknown command",
id, has_id);
void board_print(const Board *board, const int player, FILE *f)
Print out the board.
Definition board.c:1230
void book_free(Book *book)
Free resources used by the opening book.
Definition book.c:1422
void book_save(Book *book, const char *file)
Save an opening book.
Definition book.c:1622
void book_load(Book *book, const char *file)
Load the opening book.
Definition book.c:1471
@ PASS
Definition const.h:37
#define VERSION_STRING
Definition const.h:88
@ WHITE
Definition const.h:43
@ EMPTY
Definition const.h:44
@ BLACK
Definition const.h:42
void gtp_preprocess(char *line)
Definition gtp.c:34
static char * gtp_parse_color(char *s, int *color)
Definition gtp.c:68
void ui_init_gtp(UI *ui)
initialize edax protocol
Definition gtp.c:93
static void gtp_fail(const char *s, int id, bool has_id)
Definition gtp.c:58
static Log gtp_log[1]
Definition gtp.c:19
void ui_loop_gtp(UI *ui)
Loop event.
Definition gtp.c:127
static void gtp_observer(Result *result)
Definition gtp.c:21
static void gtp_send(const char *s, int id, bool has_id)
Definition gtp.c:48
void ui_free_gtp(UI *ui)
free resources used by edax protocol
Definition gtp.c:115
char * move_to_string(const int x, const int player, char *s)
Print out a move.
Definition move.c:76
Options options
Definition options.c:22
@ EDAX_TIME_PER_GAME
Definition options.h:19
@ EDAX_TIME_PER_MOVE
Definition options.h:20
bool play_must_pass(Play *play)
Check if player must pass.
Definition play.c:202
void play_print(Play *play, FILE *f)
Print the game state.
Definition play.c:1225
bool play_move(Play *play, int x)
Play a move.
Definition play.c:889
void play_new(Play *play)
Start a new game.
Definition play.c:62
void play_init(Play *play, Book *book)
Initialization.
Definition play.c:27
bool play_user_move(Play *play, const char *string)
Play a user move.
Definition play.c:909
Move * play_get_last_move(Play *play)
Get the last played move.
Definition play.c:927
bool play_load(Play *play, const char *file)
Load a saved game.
Definition play.c:84
void play_undo(Play *play)
Undo a move.
Definition play.c:779
void play_go(Play *play, const bool update)
Start thinking.
Definition play.c:214
void play_free(Play *play)
Free resources.
Definition play.c:52
Edax play control - header file.
void result_print(Result *result, FILE *f)
Print the current search result.
Definition search.c:1106
void search_set_observer(Search *search, void(*observer)(Result *))
set observer.
Definition search.c:1095
bool need_saving
Definition book.h:47
Search * search
Definition book.h:49
LogFile.
Definition util.h:423
FILE * f
Definition util.h:424
PlayType play_type
Definition options.h:42
int level
Definition options.h:40
char * ui_log_file
Definition options.h:78
long long time
Definition options.h:41
bool info
Definition options.h:36
char * book_file
Definition options.h:59
int verbosity
Definition options.h:32
int player
Definition play.h:32
Board board[1]
Definition play.h:26
long long left
Definition play.h:42
Search search[1]
Definition play.h:28
int type
Definition play.h:31
char error_message[PLAY_MESSAGE_MAX_LENGTH]
Definition play.h:59
int i_game
Definition play.h:35
int id
Definition search.h:101
int type
Definition ui.h:36
Play play[2]
Definition ui.h:32
Book book[1]
Definition ui.h:33
int mode
Definition ui.h:37
void ui_event_wait(UI *ui, char **cmd, char **param)
Wait input.
Definition ui.c:147
char * parse_int(const char *string, int *result)
Parse an integer.
Definition util.c:761
char * parse_real(const char *string, double *result)
Parse a real number (as a double floating point).
Definition util.c:796
int string_to_int(const char *s, const int default_value)
Convert a string into an integer.
Definition util.c:457
char * parse_command(const char *string, char *cmd, char *param, const unsigned int size)
Parse a command.
Definition util.c:867
char * parse_word(const char *string, char *word, unsigned int n)
Parse a word.
Definition util.c:562
Miscellaneous utilities header.
#define log_close(l)
Close an opened log file.
Definition util.h:435
#define log_print(l,...)
Print into the log file.
Definition util.h:442
#define log_open(l, file)
open a log file if allowed.
Definition util.h:429
#define log_is_open(l)
Check if the log stream can be used.
Definition util.h:448