Register
handmade.network»Forums»Running an external board game bot in my app
12 posts
Running an external board game bot in my app
6 days, 21 hours ago Edited by BernFeth on July 31, 2020, 1:58 p.m.
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
2106 posts / 1 project
Running an external board game bot in my app
6 days, 20 hours ago
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).

Alexey
8 posts
Running an external board game bot in my app
6 days, 18 hours ago
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.
12 posts
Running an external board game bot in my app
6 days, 11 hours ago
Thank you guys!

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