Jump to content
Steve Maughan

Writing & Reading as a Console App?

Recommended Posts

I'm converting my chess engine to Delphi. It's a console application that uses the UCI protocol. I'm use "writeln" to send text to the console and have a thread that simply uses "readln" to capture the input from the user. Everything works fine when it's run as a terminal application and I type in the commands. However, when I try to run it using a Chess GUI the communication doesn't happen. I've written a short app using DOScommand and it seems the communication isn't happening between the two applications. What am I missing? How do I capture the standard input sent from the other application? How do I write back my commands to the standard output so it can be processed by the other application (i.e., the chess GUI)?

 

Thanks, Steve

Share this post


Link to post

Or put logic into a dll, than you can access it from Delphi GUI or Console the same way.

Share this post


Link to post

I read in UCI specification: "the engine must always be able to process input from stdin, even while thinking.".

Are you sure it is the case with your engine ?

 

Share this post


Link to post
5 hours ago, FPiette said:

I read in UCI specification: "the engine must always be able to process input from stdin, even while thinking.".

Are you sure it is the case with your engine ?

 

@FPiette Yes, that's why I was planning to have a separate thread constantly reading the StdIn.

 

@KodeZwerg Yes, I was planning to create a separate TUCI class to handle the communication

Share this post


Link to post

I've added the "flush(Output)" command after the "WriteLn" statements and it seems to be working. Any advice on getting the ensuring the fastest possible communication via StdIn and StdOut would be appreciated!

 

— Steve

Share this post


Link to post

You can get handles of STDIN/OUT

  hStdin := GetStdHandle(STD_INPUT_HANDLE);
  hStdOut := GetStdHandle(STD_OUTPUT_HANDLE);

and then call usual Read/WriteFile

Share this post


Link to post
10 hours ago, Steve Maughan said:

I've added the "flush(Output)" command after the "WriteLn" statements and it seems to be working. Any advice on getting the ensuring the fastest possible communication via StdIn and StdOut would be appreciated!

Classic Pascal I/O is probably not the most efficient. I would use direct WinAPI call (GetStdHandle, ReadFile, WriteFile). Using  that API, you can easily make it non blocking (using I/O Completion Ports and/or multi threading). To organize your software, you should probably create an abstract class offering the services you need to communicate and then make one or more implementation using various I/O mechanisms.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×