I am trying to make a chess engine for xboard. After the first move made by user, my chess engine replies, and then xboard doesn't send the next move made by the user.
I recorded whatever xboard sends to my engine. Here's a code sample where my engine replies e2e4
with move e7e6
:
#include <iostream>
#include <fstream>
#include <unistd.h>
std::ofstream f("xboardtoeng.txt");
std::ofstream f2("engtoxboard.txt");
int main(int argc, char** argv){
while (true){
std::string s;
std::cin>>s;
f<<s<<std::endl;
if (s=="protover"){
std::cout<<"feature done=1"<<std::endl;
f2<<"feature done=1"<<std::endl;
}else if (s=="e2e4"){
usleep(100000);
std::cout<<"move e7e6"<<std::endl;
f2<<"move e7e6"<<std::endl;
}
}
f.close();
}
After compiling, I ran xboard -fcp $PWD/a.out
. Then, I made e2e4 move as user in the GUI. After my engine gives its reply, I made another move (say, e4e5). Here's what I got in xboardtoeng.txt
:
xboard
protover 2
accepted usermove
accepted myname
accepted done
new
random
level 40 5 0
post
hard
time 30000
otim 30000
usermove e2e4
Here, xboard did send the first move to my engine. However, the next user move isn't sent. Any idea where I did wrong?
I use xboard version 4.8.0
I have the same problem, it is because Xboard send SIGINT and SIGTERM signal. Adding code signal(SIGINT, SIG_IGN)
solve my problem.