So I'm not actually making a Chess app, but I am trying to hook up an engine that uses a protocol almost exactly the same as UCI. I can get it working quite easily on a macOS app. Now, the hard part is integrating an engine like Stockfish into an iOS app.

You can't use std input/output nor can you fork a process, so how should one manage the protocol for communicating moves to a UCI interface? I've managed to include the engine C++ library and can communicate via UCI commands in the debug console but I have no idea how to simulate std input into the engine from iOS. Should I look for hooks within the engine to call directly and simulate the game loop in Swift?

I apologize if this is the wrong community for this question, but UCI specific questions go over the head of most SO users so I thought I might try here. There are a plethora of iOS chess apps so I'm genuinely curious how people are integrating their engines into their apps.


Simple. Inter-thread communication. Specific implementations could be:

  • Internal UCI queues
  • Find the UCI loop function then hook it up (e.g. UCI::loop in Stockfish).
  • Redirect the standard input/output into pipes

Few points:

  • It's not a good idea to do your works with Swift, because Swift has poor support for C++. I prefer Objective-C as it works with C++ at the source level.
  • Redirecting is recommended if you're confident. All my iOS apps use that. You just need to send your UCI commands to a redirected pipe, while the engine receives them from the standard inputs (redirected). This is not a place for discussing unix programming, please ask Stackoverflow. It works.
  • do you use GCD to handle thread communication? What do you mean by UCI queues? is that like buffering commands? And lastly, how do you achieve that standard input/output via pipes? do you call some c function to do that? – swigganicks Jan 31 '18 at 4:01
  • I used std::thread for inter-thread. Queue for buffering UCI commands. Standard input/output redirection is possible with the pipe() command. @swigganicks – HelloWorld Jan 31 '18 at 4:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.