5

I looked at this question

Implement a chess app for Android with Stockfish

but it doesn't seem to be answering what I want to ask. Maybe part of my question is topic for stack overflow forum, but anyway, I try it here first.

I'm doing android app in c# with xamarin and would like to use Stockfish for analysis and play functions. I already have c++ class working with PC version of engine (uci) and I would like to reuse some of the code like uci parsing. What steps should I do to run Stockfish in my c# app? Also I would like to ask if there are some conditions under which stockfish can/can't be used in android chess app.

3

Reusing C++ classes in C# is annoying but straightforward. You'll need to know managed C++.

https://stackoverflow.com/questions/855756/difference-between-native-and-managed-code

gives you what managed C++ is. It is a C++ technology invented by Microsoft, and it works as a layer between C# and unmanaged C++.

There is no reason why you can't do it in C#. You may want two background threads. The first one sends UCI commands to the engine, while the second thread asynchronously wait for engine results.

EDIT

Steps you should follow:

  • Read what managed C++ is and why you would need it
  • Make sure you can compile your unmanaged C++ code (regular C++). How to do it depends on your environment
  • Make sure your can also compile managed C++ code.
  • Make sure your C# code can call into managed C++
  • Make sure your managed C++ code can call into unmanaged C++
  • Now, you should be able to pass a PGN string from C# to your unmanaged C++ UCI parsing code

There is no reason why you can't use the Stockfish engine in Android.

  • Thanks for answer, now I see my question was badly formulated as I wanted to ask on how to conect to stockfish from c# app, not how to reuse my c++ class. Sorry, I edited my question. – hoacin May 8 '17 at 11:28
  • @hoacin I'm not 100% sure what steps you're asking. Maybe my edit would help? – SmallChess May 8 '17 at 13:55
  • If I understand it correctly, I will download source code of Stockfish, put it to my project as you write and then use it? No external Stockfish, no input output redirection like in Windows? – hoacin May 8 '17 at 14:34
  • @hoacin You can do it internally or externally. Either way you'll need to compile the source code. You'll need to make two background threads for UCI communication. – SmallChess May 8 '17 at 14:42
  • I added stockfish 8 binary arm64-v8a to my project with build action AndroidNativeLibrary and it looks it is accepted by the project with no error. Is this the right step? If yes, which functions are there to be called from the binary? I suppose there should be some init, send uci message and get uci message functions, but I don't know their names and didn't find anywhere. – hoacin May 29 '17 at 15:13

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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