Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Buffered Input Problem with WinBoard :(

Author: Ulrich Tuerke

Date: 08:59:52 06/15/98

Go up one level in this thread


On June 15, 1998 at 11:32:56, Stanislav Goldovski wrote:

>Hello,
>
>I'm creating a chess engine in C and want it to be compatible with
>WinBoard. One thing I want to implement is recognizing "?" command
>from WinBoard to my engine - that is the "Move Now" feature.
>
>For some reason, this "?" goes not directly to my engine, but to
>the input buffer, so that the engine doesn't "move now".
>I try to resolve this with "setbuf(stdin, NULL);" and also
>I do "fflush(stdin)" just before checking the input with "getch".

If I remember right, then the "getch" is just a macro for "getc". The getc
needs input buffering in order to work correctly, cause there is also the
"ungetc" in order to push back a byte to the input buffer. I guess that your
combination of setbuf(stdin,NULL) and getch can't work.
I am afraid this is also true for the fscanf, scanf family. According to the
man pages of our OSF1 system, these calls need input buffering too in order to
work correctly.

I'd suggest to use

read(0,buffer,1)         instead of   getch

BTW, you should also use the PeekNamedPipe call instead of kbhit a la Crafty
(may be you're already doing so).

Uli

> ...



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.