I'm going to modify the command parser of my UCI engine.
My engine is not multithreaded and I don't want now to write a thread for the search and a thread for the parser.
I have some problem with the stop command, I poll during the search for a kbhit() and everything is working nicely except I lose strength.
Do you know something faster than kbhit ?? what can I do?
implementing uci stop command
Moderator: Ras
-
Karlo Bala
- Posts: 373
- Joined: Wed Mar 22, 2006 10:17 am
- Location: Novi Sad, Serbia
- Full name: Karlo Balla
Re: implementing uci stop command
Simple solution, skip the check in the last few plays.elcabesa wrote:I'm going to modify the command parser of my UCI engine.
My engine is not multithreaded and I don't want now to write a thread for the search and a thread for the parser.
I have some problem with the stop command, I poll during the search for a kbhit() and everything is working nicely except I lose strength.
Do you know something faster than kbhit ?? what can I do?
Best Regards,
Karlo Balla Jr.
Karlo Balla Jr.
-
elcabesa
- Posts: 858
- Joined: Sun May 23, 2010 1:32 pm
Re: implementing uci stop command
I already check for input every 1000 nodes
-
hgm
- Posts: 28451
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: implementing uci stop command
kbhit() ? Does that work on pipes?
-
elcabesa
- Posts: 858
- Joined: Sun May 23, 2010 1:32 pm
Re: implementing uci stop command
I really don't know, I have tested it with console, and with cutechesscli which has not stop command
-
hgm
- Posts: 28451
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: implementing uci stop command
Well, I don't think it would be any good on pipes. And consequently it is nor very relevant if it is excruciatingly slow or not. My engines use PeekNamedPipe() to check for input on Windows. (But that doesn't work when I run them from the command prompt.) I never tried to measure the slowdown, but I suppose I would have noticed if it was spectacular. (I also check every 1000-4000 nodes. If you knew how long a typical call takes, I suppose you can calculate what the optimum probing rate is, balancing time you lose by probing against time you lose from probing too late.)
-
elcabesa
- Posts: 858
- Joined: Sun May 23, 2010 1:32 pm
Re: implementing uci stop command
could you point me to one of yours engine so i can study peeknamedpipe?
thank you
thank you
-
hgm
- Posts: 28451
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: implementing uci stop command
Well, my engines are not open source, except for micro-Max / Fairy-Max, but that does not ponder and so does not use it. But I can post a typical code excerpt here, as it is very short:
Code: Select all
int unbuffered_input(int init)
{ // returns number of waiting input characters (or 1 if call fails)
static int pipe;
static HANDLE inp = NULL;
DWORD cnt;
if(!inp) inp = GetStdHandle(STD_INPUT_HANDLE);
if(!PeekNamedPipe(inp, NULL, 0, NULL, &cnt, NULL)) return 1;
return cnt;
}
// In Search():
// ABORT
if((++sample & 0xFFF) == 0) {
if(pondering) abortFlag = unbuffered_input(0);
else abortFlag = (GetTickCount() - Ticks > tlim3);
}
-
AlvaroBegue
- Posts: 932
- Joined: Tue Mar 09, 2010 3:46 pm
- Location: New York
- Full name: Álvaro Begué (RuyDos)
Re: implementing uci stop command
For POSIX (read "non-Windows") systems I use this:
Code: Select all
#include <sys/select.h>
bool is_there_input(){
fd_set read,write,except;
FD_ZERO(&read);
FD_ZERO(&write);
FD_ZERO(&except);
FD_SET(0,&read); // stdin
struct timeval timeout;
timeout.tv_sec=0;
timeout.tv_usec=0;
return select(1,&read,&write,&except,&timeout);
}
Last edited by AlvaroBegue on Mon Dec 10, 2012 11:28 pm, edited 1 time in total.
-
elcabesa
- Posts: 858
- Joined: Sun May 23, 2010 1:32 pm
Re: implementing uci stop command
Why do you talk about pondering? my engine doesnt' ponder but i added the stop command anyway, am I wrong?