I wrote the UCI interfacing code, and trying to test with XBoard, but it simply hands and nothing happens. Is there a way to see what is being sent/recieved by XBoard, so help debugging. Here's my UCI code, it's pretty minimal, and works when I manually talk to my enging in UCI language
Code: Select all
void main_loop()
{
setvbuf(stdin,NULL,_IONBF,0);
setvbuf(stdout,NULL,_IONBF,0);
char line[0x1000];
while (fgets(line, 0x1000, stdin) && parse_line(line));
}
static bool parse_line(char *line)
{
const char *token = strtok(line, " \n");
if (!strcmp(token, "go"))
parse_go();
else if (!strcmp(token, "uci")) {
puts("id name BibiChess");
puts("id author Lucas Braesch");
puts("uciok");
}
else if (!strcmp(token, "ucinewgame"))
tt_clear();
else if (!strcmp(token, "position"))
parse_position(line + strlen("position")+1);
else if (!strcmp(token, "isready"))
puts("readyok");
else if (!strcmp(token, "stop"))
abort_search = true;
else if (!strcmp(token, "quit"))
return false;
return true;
}
static void parse_position(const char *line)
{
const char *fen = strstr(line, "fen ");
const char *moves = strstr(line, "moves ");
if (fen)
load_fen(&B, fen + strlen("fen "));
else // assume startpos
load_fen(&B, StartFen);
if (moves) {
const char *ptr = moves + strlen("moves ");
char s[8];
while (*ptr != '\n') {
s[0] = *ptr++;
s[1] = *ptr++;
s[2] = *ptr++;
s[3] = *ptr++;
if (*ptr == '\n' || *ptr == ' ')
s[4] = '\0';
else { // promotion
s[4] = *ptr++;
s[5] = '\0';
}
move_t m = string_to_move(&B, s);
play(&B, m);
while (*ptr == ' ') ptr++;
}
}
}
static void parse_go()
{
const char *token;
int wtime, btime, winc, binc;
for (token = strtok(NULL," \n"); token; token = strtok(NULL," \n"))
{
if (!strcmp(token, "wtime")) {
if (!(token = strtok(NULL, " \n")))
fatal("parse_go(): missing argument\n");
wtime = atoi(token);
}
else if (!strcmp(token, "btime")) {
if (!(token = strtok(NULL, " \n")))
fatal("parse_go(): missing argument\n");
btime = atoi(token);
}
else if (!strcmp(token, "winc")) {
if (!(token = strtok(NULL, " \n")))
fatal("parse_go(): missing argument\n");
winc = atoi(token);
}
else if (!strcmp(token, "binc")) {
if (!(token = strtok(NULL, " \n")))
fatal("parse_go(): missing argument\n");
binc = atoi(token);
}
}
int time = B.turn ? btime : wtime,
inc = B.turn ? binc : winc;
move_t best = id_loop(&B, time/40 + inc);
char s[8];
move_to_string(&B, best, s, false);
printf("info bestmove %s\n", s);
play(&B, best);
}
Code: Select all
lucas@lucas-laptop:~/.codelite/Chess$ ./chess
uci
id name BibiChess
id author Lucas Braesch
uciok
isready
readyok
ucinewgame
position startpos moves e2e4
go btime 100 binc 50
info depth 1
info currmove Na6 currmovenumber 1
info currmove Nc6 currmovenumber 2
info currmove Nf6 currmovenumber 3
info currmove Nh6 currmovenumber 4
info currmove a5 currmovenumber 5
info currmove b5 currmovenumber 6
info currmove c5 currmovenumber 7
info currmove d5 currmovenumber 8
info currmove e5 currmovenumber 9
info currmove f5 currmovenumber 10
info currmove g5 currmovenumber 11
info currmove h5 currmovenumber 12
info currmove a6 currmovenumber 13
info currmove b6 currmovenumber 14
info currmove c6 currmovenumber 15
info currmove d6 currmovenumber 16
info currmove e6 currmovenumber 17
info currmove f6 currmovenumber 18
info currmove g6 currmovenumber 19
info currmove h6 currmovenumber 20
info cp 35 nodes 25 time 0
info score 35 pv Nf6
info depth 2
info currmove Nf6 currmovenumber 1
info currmove Nh6 currmovenumber 2
info currmove a5 currmovenumber 3
info currmove b5 currmovenumber 4
info currmove c5 currmovenumber 5
info currmove d5 currmovenumber 6
info currmove e5 currmovenumber 7
info currmove f5 currmovenumber 8
info currmove g5 currmovenumber 9
info currmove h5 currmovenumber 10
info currmove a6 currmovenumber 11
info currmove b6 currmovenumber 12
info currmove c6 currmovenumber 13
info currmove d6 currmovenumber 14
info currmove e6 currmovenumber 15
info currmove f6 currmovenumber 16
info currmove g6 currmovenumber 17
info currmove h6 currmovenumber 18
info currmove Na6 currmovenumber 19
info currmove Nc6 currmovenumber 20
info cp -24 nodes 102 time 0
info score -24 pv Nf6 Nc3 Nxe4 Nxe4
info depth 3
info currmove Nf6 currmovenumber 1
info currmove Nh6 currmovenumber 2
info currmove a5 currmovenumber 3
info currmove b5 currmovenumber 4
info currmove c5 currmovenumber 5
info currmove d5 currmovenumber 6
info currmove e5 currmovenumber 7
info currmove f5 currmovenumber 8
info currmove g5 currmovenumber 9
info currmove h5 currmovenumber 10
info currmove a6 currmovenumber 11
info currmove b6 currmovenumber 12
info currmove c6 currmovenumber 13
info currmove d6 currmovenumber 14
info currmove e6 currmovenumber 15
info currmove f6 currmovenumber 16
info currmove g6 currmovenumber 17
info currmove h6 currmovenumber 18
info currmove Na6 currmovenumber 19
info currmove Nc6 currmovenumber 20
info cp 30 nodes 870 time 0
info score 30 pv Nf6 e5 Nd5 Nxe4 Bd7
info depth 4
info currmove Nf6 currmovenumber 1
info currmove Nc6 currmovenumber 2
info currmove Nh6 currmovenumber 3
info currmove f5 currmovenumber 4
info currmove f6 currmovenumber 5
info currmove b5 currmovenumber 6
info currmove c5 currmovenumber 7
info currmove d5 currmovenumber 8
info currmove e5 currmovenumber 9
info currmove Na6 currmovenumber 10
info currmove g5 currmovenumber 11
info currmove h5 currmovenumber 12
info currmove a6 currmovenumber 13
info currmove b6 currmovenumber 14
info currmove c6 currmovenumber 15
info currmove d6 currmovenumber 16
info currmove e6 currmovenumber 17
info currmove a5 currmovenumber 18
info currmove g6 currmovenumber 19
info currmove h6 currmovenumber 20
info cp -31 nodes 4606 time 0
info score -31 pv Nc6 Nf3 Nf6 Nc3 Bd7 Nxe4 Qxd7 Nxd5 Nxd5 Nxd5 Qxd5
info depth 5
info currmove Nc6 currmovenumber 1
info currmove Nf6 currmovenumber 2
info currmove d5 currmovenumber 3
info currmove e5 currmovenumber 4
info currmove g6 currmovenumber 5
info currmove f5 currmovenumber 6
info currmove f6 currmovenumber 7
info currmove Nh6 currmovenumber 8
info currmove a5 currmovenumber 9
info currmove b5 currmovenumber 10
info currmove g5 currmovenumber 11
info currmove h5 currmovenumber 12
info currmove a6 currmovenumber 13
info currmove b6 currmovenumber 14
info currmove c6 currmovenumber 15
info currmove d6 currmovenumber 16
info currmove e6 currmovenumber 17
info currmove c5 currmovenumber 18
info currmove Na6 currmovenumber 19
info currmove h6 currmovenumber 20
info cp 1 nodes 21783 time 30
info score 1 pv Nf6 e5 Ne4 Nc3 d5 Nxe4 Qxd5 Nxe4 Qxd5 Bxc6+ Qxc6
info depth 6
info currmove Nf6 currmovenumber 1
info bestmove g8f6