Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: 2 stupid pondering programming questions

Author: Andrew Williams

Date: 18:13:02 09/17/04

Go up one level in this thread


On September 17, 2004 at 18:04:48, martin fierz wrote:

>aloha!
>
>i just spent friday night implementing pondering in my chess program. hmm, make
>that 3 questions, the first being "should i get a life?" :-)
>
>anyway, back to the two questions - they are really rather stupid, but well...
>
>1) i'm using PeekNamedPipe to look whether there is any command for my program,
>and i'm looking for "ponderhit". when i find that, i'd like to flush the
>standard input. however, "fflush(stdin);" doesn't help, the ponderhit command
>stays where it is and is seen by every next call to my standard-input-polling
>function. i now use "gets(input)" where input is a string, and then the
>ponderhit command disappears and is not seen by the next call to PeekNamedPipe.
>
>can somebody tell me why fflush(stdin) won't work?
>

PeekNamedPipe only checks if input is present. Once you know that there is input
to handle, you have to read it from the pipe. My program does this:

  int xbdInterruption = xbd_check_for_interruption();
  if(xbdInterruption) xbd_whaddaya_want();

xbd_check_for_interruption() uses PeekNamedPipe(..) [or select(..) in linux]
xbd_whaddaya_want() calls xbd_read(..), which calls _read() [or read(..) in
linux] to build a buffer, one character at a time:

  do {
#ifdef WINDOWS
      error = _read(0, &buffer[got], 1);
#else
      error = read(0, &buffer[got], 1);
#endif
      got++;
  } while(error != -1 && got < (size-1) && buffer[got-1] != '\n');


I can't remember whether this structure is my idea or if I adapted it from
somewhere else.

Andrew


>2) when i receive a ponderhit command but have used a lot of time, i abort the
>search. so my PV is now reduced to crap (except for the first ply) and my engine
>ponders on a garbage move. is there any more elegant/better way to solve this
>than memorizing the PV of the last ply? for instance, i might have had a
>fail-high for a new root move, and i don't construct PVs in the middle of the
>search, only after every completed ply. but i should construct PVs all the time
>(i.e. on every ply, and on every new best move at root level) if i want to
>ponder, correct?
>
>how are you doing this in your program?
>
>cheers
>  martin



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.