UCI engine

Code, algorithms, languages, construction...
Post Reply
andypandy
Posts: 3
Joined: Wed Jul 17, 2013 5:25 pm
Real Name: Anders Kleimark

UCI engine

Post by andypandy » Wed Jul 17, 2013 5:37 pm

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?

velmarin
Posts: 39
Joined: Thu Mar 17, 2011 11:31 am
Real Name: Jose Mº Velasco

Re: UCI engine

Post by velmarin » Wed Jul 17, 2013 5:55 pm

Sorry, I no see well..

bluefever
Posts: 22
Joined: Wed Jul 10, 2013 8:23 am

Re: UCI engine

Post by bluefever » Wed Jul 17, 2013 6:10 pm

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?

andypandy
Posts: 3
Joined: Wed Jul 17, 2013 5:25 pm
Real Name: Anders Kleimark

Re: UCI engine

Post by andypandy » Wed Jul 17, 2013 6:34 pm

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.

lucasart
Posts: 201
Joined: Mon Dec 17, 2012 1:09 pm
Contact:

Re: UCI engine

Post by lucasart » Thu Jul 18, 2013 12:31 am

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()).
"Talk is cheap. Show me the code." -- Linus Torvalds.

bluefever
Posts: 22
Joined: Wed Jul 10, 2013 8:23 am

Re: UCI engine

Post by bluefever » Thu Jul 18, 2013 6:19 am

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.

Post Reply