Search code examples
iphoneintegrationartificial-intelligencechess

How do you port a chess AI to iPhone


I would like to port a chess AI to iPhone, but I can't figure out how to do it. Apparently iPhone doesn't support multi threading so you can't just seperately compile the AI, but have to somehow merge it into the code.

I have a GPL copy of a implementation of the sjeng engine, but I can't figure out how they did it because it's written in c and c++ and all I know is apple objc.

Does anyone have any recommendations on how to do this? I need to make a wrapper of some kind for what is a standalone program.

file with code which I will leave up for as long as I can.


Solution

  • Your question is actually more complicated than it needs to be, because I think the basic problem you have is unrelated to compiling specifically for the iPhone.

    If you say you already have some chess AI code, then somewhere in there is a call to an evaluation function that takes a game state (board position and player to move) and will give back a move. That's what you need to drill down and find, because that essentially is the "engine" that will drive your app, regardless of what platform you're compiling for.

    Now, my guess is that this chess AI assumes that move search is run in its own thread, likely a design decision to make it easy to "interrupt" the search at any time and have it play its own move. You can certainly run code in separate threads on the iPhone, so the problem for you is to figure out how to tease out that code from to free it from whatever existing platform dependencies it has.

    It may help you to first approach this problem as if you were writing a command-line utility, in C, to run on Mac OS X. That will free you from a lot of dependencies and simplify the situation for you. My guess is once you've done that, you'll immediately have a good idea of how to make it work within a (Cocoa) iPhone environment.