How to connect my engine with winBoard

Discussions about Winboard/Xboard. News about engines or programs to use with these GUIs (e.g. tournament managers or adapters) belong in this sub forum.

Moderator: Andres Valverde

How to connect my engine with winBoard

Postby dehseth » 10 Aug 2009, 14:08

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!
dehseth
 
Posts: 5
Joined: 10 Aug 2009, 10:56

Re: How to connect my engine with winBoard

Postby H.G.Muller » 10 Aug 2009, 14:24

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.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: How to connect my engine with winBoard

Postby dehseth » 10 Aug 2009, 14:36

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!
dehseth
 
Posts: 5
Joined: 10 Aug 2009, 10:56

Re: How to connect my engine with winBoard

Postby H.G.Muller » 10 Aug 2009, 15:02

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.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: How to connect my engine with winBoard

Postby dehseth » 10 Aug 2009, 15:26

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!
dehseth
 
Posts: 5
Joined: 10 Aug 2009, 10:56

Re: How to connect my engine with winBoard

Postby H.G.Muller » 10 Aug 2009, 15:57

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);
}
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: How to connect my engine with winBoard

Postby dehseth » 10 Aug 2009, 16:11

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 ...
dehseth
 
Posts: 5
Joined: 10 Aug 2009, 10:56

Re: How to connect my engine with winBoard

Postby H.G.Muller » 10 Aug 2009, 18:30

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.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: How to connect my engine with winBoard

Postby dehseth » 10 Aug 2009, 18:40

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
dehseth
 
Posts: 5
Joined: 10 Aug 2009, 10:56


Return to Winboard and related Topics

Who is online

Users browsing this forum: No registered users and 32 guests