Handmade Network»Forums
40 posts
Running an external board game bot in my app
Edited by BernFeth on
Hey guys, I have been working on this client for a board game called Go (or Baduk, or Weiqi) and I decided it's finally time to get a bot in there to play against it. There is a fairly strong bot called pachi (https://pachi.or.cz/) which has a linux binary that worked for me which is great.

Apparently these bots use a protocol called GTP (Go Text Protocol) which I found information on it at http://www.lysator.liu.se/~gunnar/gtp/gtp2-spec-draft2/gtp2-spec.html

So my question is, how can I run the executable from my app so that I can issue commands to it and retrieve it's output?

Note: The client I'm working on is written in C. Pachi (the bot) is a binary which waits for commands and outputs a bunch of information after each command issued by the user input.
Mārtiņš Možeiko
2575 posts / 2 projects
Running an external board game bot in my app
Standard C does not have functions for this.
You need to look at platform specific API - something like posix_spawn on Linux or CreateProcess on Windows to redirect stdin/stdout of child process to something you can read. These function will create child process and provide stdin/stdout for regular read/write (on Linux) or ReadFile/WriteFile calls (on Windows).

16 posts
Running an external board game bot in my app
I haven't heard of posix_spawn before (although a quick look at the man page makes me think it's what you need), but what I've always done is use fork to create a child process, then exec to switch to the desired command, and a combination of pipe and dup2 calls to redirect child process' stdin and stdout to the pipe. Then you just write and read to/from the pipe to communicate with the child.
40 posts
Running an external board game bot in my app
Thank you guys!

I will do some reading on those and see if I can implement it.