Page 1 of 1

How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 14:08
by dehseth
Hey guys,

I have written a chess engine and found an article on internet about how to communicate with WinBoard. I have set up all the things.

My problem is how can I setup winboard to make it use my engine?

Thank you all!

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 14:24
by H.G.Muller
Just startup WinBoard through the startup dialog, and type the name of your engine executable, followed by /fd="PATH" where PATH is the folder where that executable is. (The latter is not needed if your engine.exe is sitting in the WinBoard folder.) That's all.

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 14:36
by dehseth
Thank you Muller for your reply...

I have another question. I have copied exe file to winboard directory and as you've said I write engine's name to textbox but it gives me this messagebox: first chess program (ChessAITest) exited unexpectedly..

Actually when I start engine from console it does not exit it just waits for input..
I have used this article to program communication: http://www.tim-mann.org/xboard/engine-intf.html#2

Thank you vrery much!

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 15:02
by H.G.Muller
then write /debug behind your engine name in the box (separated from it by a space).

WinBoard will then make a file winboard.debug, that shows all communication that went on between your engine and WinBoard. If you post the contents of that file here (it cannot be very long if your engine crashes immediately) we might be able to figure out where it goes wrong.

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 15:26
by dehseth
Here is the debug file content:

recognized 'normal' (-1) as variant normal
WinBoard 4.2.7 + ChessAITest.exe
Reset(1, 0) from gameMode 0
recognized 'normal' (-1) as variant normal
GameEnds(0, (null), 2)
StartChildProcess (dir="") ChessAITest.exe
610 >first : xboard
protover 2
Fatal Error: Error writing to first chess program:
Closing pipe.

Fatal Error: Error: first chess program (ChessAITest.exe) exited unexpectedly
GameEnds(0, (null), 2)
1641 >first : force
1641 >first : quit


Seems like it cannot write to pipe. I have these lines in code to make input and output unbuffered:

Code: Select all
setbuf(stdout, NULL);
setbuf(stdin, NULL);


Engines starts to read immediately after start. So any idea what is wrong with it?

Thank you!

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 15:57
by H.G.Muller
Hmm, hard to say. It really goes wrong very early. It seems the pipe is defective from creation, as if the engine has closed its stdin (or is already exiting). Do you close any file descriptors in the engine?

What happens if just for testing purposes you add at the very beginning of your engine's main():

Code: Select all
char buf[80];
while(1) {
    scanf("%s", buf);
    printf("%s", buf);
    fflush(stdout);
}

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 16:11
by dehseth
This is how I read line:

Code: Select all
void ReadLine(char* buff)
{
   int c = 0;
   int cnt = 0;

   while (c != '\n')
   {
      c = getch();

      buff[cnt++] = (char)c;
   }

   buff[--cnt] = NULL;
}


Is smt wrong with it? Using cmd does not cause any problem.

Here is my main loop looks like:

Code: Select all
void winBoardLoop()
{
   setbuf(stdout, NULL);
   setbuf(stdin, NULL);
   
   char cmd[256];
   memset(cmd, 0, 256);

   while (true)
   {
      ReadLine(cmd);

      if (!strcmp(cmd, "new"))
      {
// and so on ...

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 18:30
by H.G.Muller
I proposed this test to see if the setbuf calls possibly cause any problems. What you write seems OK, although I always use getchar() rather than getch(), and I am not sure how these two differ.

Re: How to connect my engine with winBoard

PostPosted: 10 Aug 2009, 18:40
by dehseth
Thank you H.G.Muller I have solved the problem. 8-)

First I have used this code:

Code: Select all
scanf("%s\n", cmd);


And I see from debug file that engine receives and sends string. Unfortunately I couldn't get move instruction it may have to do with reading white spaces with scanf. Any way I changed getch() function to getchar() function and it work out!

Now I can test it visually yeey! :D