Basic questions regarding Winboard/Xboard communication

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Basic questions regarding Winboard/Xboard communication

Postby Anonymous » 14 Mar 2006, 23:09

I'd like to work on my own chess engine, and I'm having a little bit of trouble communicating with winboard. I've been using C++, and Xboard gets commands I send it through cout, but I can't seem to pick up input through cin. The program just skips right over any cin statements and goes on. I'm familiar with Tim Mann's guide and the other basic resources on the web..

So, my questions are:
1. What is the preferred way to turn off stdin and stdout buffering in C++?
2. How do I read commands that Xboard sends to my engine in C++?
Anonymous
 

Re: Basic questions regarding Winboard/Xboard communication

Postby Volker Pittlik » 14 Mar 2006, 23:27

bsmalb wrote:... I'm familiar with Tim Mann's guide and the other basic resources on the web..

So, my questions are:
1. What is the preferred way to turn off stdin and stdout buffering in C++?


... In C++, you can try cout.setf(ios::unitbuf), which is documented in current editions of "The C++ Programming Language," but not older ones. Another C++ method that might work is cout.rdbuf()->setbuf(NULL, 0). Alternatively, you can carefully call cout.flush() after every line you output; again, I don't recommend this.


From http://www.tim-mann.org/xboard/engine-intf.html#9

How
...familiar with Tim Mann's guide...
are you?


2. How do I read commands that Xboard sends to my engine in C++?[/quote]

From the same source:

...A second way to fix the problem might be to ask your I/O library not to buffer on input. It should then be safe to poll the underlying file descriptor as described above. With C, you can try calling setbuf(stdin, NULL). However, I have never tried this. Also, there could be problems if you use scanf(), at least with certain patterns, because scanf() sometimes needs to read one extra character and "push it back" into the buffer; hence, there is a one-character pushback buffer even if you asked for stdio to be unbuffered. With C++, you can try cin.rdbuf()->setbuf(NULL, 0), but again, I have never tried this.

A third way to fix the problem is to check whether there are characters in the buffer whenever you poll. C I/O libraries generally do not provide any portable way to do this. Under C++, you can use cin.rdbuf()->in_avail(). This method has been reported to work with EXchess. Remember that if there are no characters in the buffer, you still have to poll the underlying file descriptor too, using the method described above.


What did you try?

And a last note:

...May I use a pseudonym?

To use your real name (that one written in your passport) is required. If you wish to use a pseudonym please email me an explanation otherwise your account may be deleted without warning. Duplicate or fake accounts or accounts used for trolling will also be deleted. ...


http://wbforum.volker-pittlik.name/viewtopic.php?t=210

vp
User avatar
Volker Pittlik
 
Posts: 1031
Joined: 24 Sep 2004, 10:14
Location: Murten / Morat, Switzerland

Re: Basic questions regarding Winboard/Xboard communication

Postby Dann Corbit » 14 Mar 2006, 23:43

...

About C++ and unbuffered I/O...

Code: Select all

// Here's the OO answer with chewy, carmelly goodness in the center:

   cout.rdbuf()->pubsetbuf(NULL,0);
   cin.rdbuf()->pubsetbuf(NULL,0);
Dann Corbit
 


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 39 guests

cron