Author: Dann Corbit
Date: 15:45:21 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? From the C-FAQ: 12.26a: How can I flush pending input so that a user's typeahead isn't read at the next prompt? Will fflush(stdin) work? A: fflush() is defined only for output streams. Since its definition of "flush" is to complete the writing of buffered characters (not to discard them), discarding unread input would not be an analogous meaning for fflush on input streams. See also question 12.26b. References: ISO Sec. 7.9.5.2; H&S Sec. 15.2. 12.26b: If fflush() won't work, what can I use to flush input? A: It depends on what you're trying to do. If you're trying to get rid of an unread newline or other unexpected input after calling scanf() (see questions 12.18a-12.19), you really need to rewrite or replace the call to scanf() (see question 12.20). Alternatively, you can consume the rest of a partially-read line with a simple code fragment like while((c = getchar()) != '\n' && c != EOF) /* discard */ ; (You may also be able to use the curses flushinp() function.) There is no standard way to discard unread characters from a stdio input stream, nor would such a way necessarily be sufficient, since unread characters can also accumulate in other, OS-level input buffers. If you're trying to actively discard typed-ahead input (perhaps in anticipation of issuing a critical prompt), you'll have to use a system-specific technique; see questions 19.1 and 19.2. References: ISO Sec. 7.9.5.2; H&S Sec. 15.2. > >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? The same was is if I abort the search due to time. You don't ponder garbage when you have a time exit, I imagine.
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.