I implemented the UCI protocol to cohabitat with the Xboard protocol
last night.
It seems to work well except for one thing. None of the commands
are received during the search. The code I have to detect input
works fine when using the Xboard protocol. According to log file
data the code reaches the checkpoint to check for input but input
is never detected when running in UCI mode.
Is there something special about detecting input when using UCI?
All other uci commands seem to work as they are before or after the
search.
I am using Arena and MS Windows XP.
UCI protocol experience needed
Moderators: hgm, Rebel, chrisw
-
- Posts: 2056
- Joined: Mon Mar 13, 2006 2:31 am
- Location: North Carolina, USA
Re: UCI protocol experience needed
Indeed if it works with Winboard it should work with UCI too.
-
- Posts: 12541
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: UCI protocol experience needed
CRoberson wrote:I implemented the UCI protocol to cohabitat with the Xboard protocol
last night.
It seems to work well except for one thing. None of the commands
are received during the search. The code I have to detect input
works fine when using the Xboard protocol. According to log file
data the code reaches the checkpoint to check for input but input
is never detected when running in UCI mode.
Is there something special about detecting input when using UCI?
All other uci commands seem to work as they are before or after the
search.
I am using Arena and MS Windows XP.
How are you collecting the UCI input?
IOW, are you using a separate thread or polling or ...?
-
- Posts: 2056
- Joined: Mon Mar 13, 2006 2:31 am
- Location: North Carolina, USA
Re: UCI protocol experience needed
I am polling.
Every so many nodes, I check to see if there is input.
In Unix, I use select.
In MS, I use PeekNamedPipe.
Every so many nodes, I check to see if there is input.
In Unix, I use select.
In MS, I use PeekNamedPipe.
Re: UCI protocol experience needed
I think you can enable protocol debugging in Arena, but I've never used it personally.
Like I said before, if it works with Winboard it must work with UCI so probably the problem is not in the mechanism itself but it is used.
I would say post your code but it's past midnight around here and I'll be dreaming about a 2800 Hamsters very soon!
Like I said before, if it works with Winboard it must work with UCI so probably the problem is not in the mechanism itself but it is used.
I would say post your code but it's past midnight around here and I'll be dreaming about a 2800 Hamsters very soon!
-
- Posts: 12541
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: UCI protocol experience needed
Is buffering turned off for UCI in the same way as you have it turned off for Winboard? IOW, the path that initiates Winboard I/O probably has something like:CRoberson wrote:I am polling.
Every so many nodes, I check to see if there is input.
In Unix, I use select.
In MS, I use PeekNamedPipe.
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
to turn off cache of input and output.
Does the same thing occur in your UCI startup path?
-
- Posts: 2056
- Joined: Mon Mar 13, 2006 2:31 am
- Location: North Carolina, USA
Re: UCI protocol experience needed
Interesting idea. At 4am this morning, I decided it didn't matter
that the UCI execution path didn't include
signal(SIGINT,SIG_IGN).
I just fixed that but it didn't change things.
I've never had the setvbuff commands in it. I'll try those.
that the UCI execution path didn't include
signal(SIGINT,SIG_IGN).
I just fixed that but it didn't change things.
I've never had the setvbuff commands in it. I'll try those.
-
- Posts: 2056
- Joined: Mon Mar 13, 2006 2:31 am
- Location: North Carolina, USA
Re: UCI protocol experience needed
No Change. I wonder if the issue is Arena 1.1?
Nah, other UCI engines work.
Nah, other UCI engines work.
-
- Posts: 12541
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: UCI protocol experience needed
This is rather strange.
Can you trace it and see what happens when an incoming UCI command arrives while it is thinking?
Can you trace it and see what happens when an incoming UCI command arrives while it is thinking?
-
- Posts: 858
- Joined: Wed Mar 08, 2006 9:24 pm
- Location: Germany
- Full name: Daniel Mehrmann
Re: UCI protocol experience needed
Maybe try some sort of logging in your engine while search. I do something like in Homer:CRoberson wrote:No Change. I wonder if the issue is Arena 1.1?
Nah, other UCI engines work.
Code: Select all
BOOL
CheckInPut(void)
{
/* Windows */
#if defined WIN32
static BOOL init = FALSE, pipe;
static HANDLE StdinHandle;
DWORD value, LastError;
/* MS: CRT file handles */
if (init && stdin->_cnt > 0)
return TRUE;
if (!init) {
init = TRUE;
StdinHandle = GetStdHandle(STD_INPUT_HANDLE);
if (StdinHandle == NULL || StdinHandle == INVALID_HANDLE_VALUE) {
#ifdef _WIN32 /* >= Win2000 */
LastError = GetLastError();
MessageHandle("GetStdHandle() failed" , (int)LastError);
#else
MessageHandle("GetStdHandle() failed" , 0);
#endif
}
pipe = !GetConsoleMode(StdinHandle, &value);
if (!pipe) {
SetConsoleMode(StdinHandle,value &~ (ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT));
FlushConsoleInputBuffer(StdinHandle);
}
}
if (pipe) {
if (!PeekNamedPipe(StdinHandle, NULL, 0, NULL, &value, NULL)) {
#ifdef _WIN32 /* >= Win2000 */
LastError = GetLastError();
MessageHandle("PeekNamedPipe stdin failed" , (int)LastError);
#else
MessageHandle("PeekNamedPipe stdin failed" , 0);
#endif
ExitProgram((int)LastError);
}
return value > 0;
} else {
GetNumberOfConsoleInputEvents(StdinHandle, &value);
return value > 1;
}
return FALSE;
/* UNIX */
#else
fd_set rfd;
struct timeval timeval;
timeval.tv_sec = timeval.tv_usec = 0;
FD_ZERO(&rfd);
FD_SET(0, &rfd);
return select(1, &rfd, NULL, NULL, &timeval) > 0;
#endif
}
Code: Select all
if(CheckInPut()) {....read input, do logging }
Code: Select all
BOOL
ReadInPut(char *buffer, int bytes)
{
if (fgets(buffer, bytes, stdin) != NULL)
return TRUE;
else {
if (feof(stdin))
return FALSE;
else
MessageHandle("ReadInput(): Error line not ended", 2);
}
return FALSE;
}
Code: Select all
void
ShowBytes(char *buffer, int counter)
{
while (counter--) {
if (*buffer < 040 || *(uint8 *)buffer > 0177)
fprintf(LOG_FILE, "\\%03o", *buffer & 0xff);
else
putc(*buffer, LOG_FILE);
buffer++;
}
fflush(LOG_FILE);
}
void
LogInPut(char *message)
{
if (gameData.Logging) {
fprintf(LOG_FILE, "--> ");
ShowBytes(message, strlen(message));
fprintf(LOG_FILE, "\n");
fflush(LOG_FILE);
}
}