Page 1 of 1

UCI engine

Posted: Wed Jul 17, 2013 5:37 pm
by andypandy
I am trying to program an UCI engine, but the setup fails. Below is a part of the function setting up the engine.

Code: Select all

void Proxy::receiveMessage()
{
	while (std::getline (std::cin, input ))
	{
		if(input == "uci")
		{
			cout << input << "\n";
			message << input << endl;
		};

	}
}

What is wrong?

Re: UCI engine

Posted: Wed Jul 17, 2013 5:55 pm
by velmarin
Sorry, I no see well..

Re: UCI engine

Posted: Wed Jul 17, 2013 6:10 pm
by bluefever
andypandy wrote:I am trying to program an UCI engine, but the setup fails. Below is a part of the function setting up the engine.

Code: Select all

void Proxy::receiveMessage()
{
	while (std::getline (std::cin, input ))
	{
		if(input == "uci")
		{
			cout << input << "\n";
			message << input << endl;
		};

	}
}

What is wrong?
What do you mean by fails?

Re: UCI engine

Posted: Wed Jul 17, 2013 6:34 pm
by andypandy
It says it failed to run the engine. The engine does not even get the chance to identify itself. Maybe there are some "standard setup file" avaible or something.

Re: UCI engine

Posted: Thu Jul 18, 2013 12:31 am
by lucasart
andypandy wrote:I am trying to program an UCI engine, but the setup fails. Below is a part of the function setting up the engine.

Code: Select all

void Proxy::receiveMessage()
{
	while (std::getline (std::cin, input ))
	{
		if(input == "uci")
		{
			cout << input << "\n";
			message << input << endl;
		};

	}
}

What is wrong?
This part of code is clearly not relevent in understanding your problem. All it does is read commands, reprints them to stdout and queues them into 'message' (which I suppose is some kind of ostream you defined?).

Run your program without a GUI, otherwise you will never understand the problem. Just run it in command line and type commands in, your problem should be obvious.

Do not use "\n". Use std::endl. A pipe, unlike a terminal, typically uses buffered I/O by default, so you need to flush it everytime you print something, otherwise the GUI won't receive it. The GUI, when it created the pipe may or may not have requested unbuffered (or line buffered) I/O, but you cannot rely on that assumption. Most GUIs don't and your program is considered hanging from the GUI perspective if no flushing is done (GUI receives nothing). To give you an idea, here's what flushing means:

Code: Select all

=> C++
std::cout << "hello" << std::endl;

=> C equivalent
printf("hello\n");
fflush(stdout);
In C++ the std::endl does that for you (it does '\n' and fflush()).

Re: UCI engine

Posted: Thu Jul 18, 2013 6:19 am
by bluefever
andypandy wrote:It says it failed to run the engine. The engine does not even get the chance to identify itself. Maybe there are some "standard setup file" avaible or something.
Well, the protocol says you need to answer with "uciok" otherwise the engine won't run.

Do what lucas says, and read the protocol.