I've written a few event-driven iOS apps, but this has not fully prepared me for what I am working on now and I need some advice.
I have a simple strategy game design that I have prototyped using views, animation blocks and gesture recognizers. With board, moves and basic UI in place, I am just starting to create AI players and have realized that I'm not at all clear on the best way to proceed. I need to generate the AI move events and resulting animations without blocking the main thread. Years ago I might have used a classic gameloop pattern, but I'd like to avoid doing it that way in iOS as it doesn't strike me as a technique I can use in non-game apps, and one of my goals is to extend my understanding of how to structure iOS apps.
I've read about GCD and my sense is that it would be possible to do a lot of my work off the main thread with GCD, but it is not clear how I would coordinate the various parts. For example, an AI needs to evaluate the board, but every time an actor changes the board the current evaluation becomes invalid. Do I set up a queue to manage the board state? Do I put each AI player in one queue? What is the best way to interrupt an AI when it is choosing the best move?
Does anyone have a sketch of the kind of architecture my app need to support this? I'm looking for patterns that I can use in general, not just in games. Some working sample code that I could experiment with would be perfect, if anyone knows of such a thing. Thanks!