Communicate godot with another process (chess engine).

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By estebanmolca

I want to test chess engines in my game using the UCI protocol but I can’t find a way to implement it.
In c ++ (windows) what you do for this is create an input and output tunnel to read and write to the standard input and output of a child process. Creating a Child Process with Redirected Input and Output - Win32 apps | Microsoft Learn.
Try the OS.execute option in godot but it doesn’t work.
Also try to create a native plugin in godot:
(downloads godot headers, using the cl command in visual studio console according to the documentation but it’s too complicated … I got so many errors that they made me give up, but the last error was that the wchar.h file was not found.)
I also thought about reading and writing a file between godot and the engine process, but I don’t know if this would be correct, apart from the fact that I would continually be reading and writing to the disk. Any ideas? Any godot options that I’m missing?

:bust_in_silhouette: Reply From: adabru

There was a similar question on reddit termed “Read from stdin?” asked 4 months earlier. It seems there is no other possibility than to write a GDNative class to read from stdin.
But you could, as workaround, use another program in between to communicate via tcp with your child process. Maybe socat could solve it. Then from godot you would have to open a tcp connection to socat and socat would pipe its tcp input/output to/from your child process.

Thank you very much for the answer, I will investigate this better!

estebanmolca | 2020-04-14 06:43

:bust_in_silhouette: Reply From: odedstr

Have you made any progress with this?
I’m interested in exactly the same thing. I’m thinking of trying to do it as a custom module in C++. Maybe a general purpose module for std IO, and later possibly a module for communicating with a chess engine via UCI.

I ended up creating a module and that you can use to talk to a UCI engine via standard I/O. Made a post about it on reddit.
Link to the module source code.

odedstr | 2020-09-04 07:31