Steve Maughan 26 Posted February 19, 2023 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
KodeZwerg 54 Posted February 19, 2023 Why not put the logic into its own Delphi unit/class ? Share this post Link to post
KodeZwerg 54 Posted February 19, 2023 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
FPiette 383 Posted February 19, 2023 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
Steve Maughan 26 Posted February 19, 2023 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
Steve Maughan 26 Posted February 19, 2023 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
Fr0sT.Brutal 900 Posted February 20, 2023 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
FPiette 383 Posted February 20, 2023 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
Steve Maughan 26 Posted February 20, 2023 @Fr0sT.Brutal This looks ideal. I'll delve in a try to implement this approach @FPiette thanks also, this looks good too! — Steve Share this post Link to post