I want to code a Chinese chess engine, and I want to modify the Stockfish source code to do so, but the Stockfish source code is too hard to understand. There is no document that explains everything. I don't know where to start. For example, today I tried to understand the bitbase.cpp file. This line of code in this file is not well documented:

constexpr unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608

I really don't know where to ask questions about these kinds of things. It's open source but it seems to be understood by only a few people. Please give me suggestions to understand the source code better.

  • Chinese chess is quite different from European chess, is it not? Stockfish is pretty specifically geared towards European chess.
    – Cort Ammon
    May 8, 2020 at 3:42
  • I think stockfish can be adapted to chinese chess. For example, this project is a UCI Chinese Chess (also called Xiangqi) engine derived from Stockfish 7: github.com/EterCyber/Chameleon
    – hdvd2309
    May 8, 2020 at 3:58
  • 1
    One thing you can do is paste the code into chat.openai.com and ask it to explain it to you, it usually does a good job.
    – user17703
    Mar 13 at 0:34

1 Answer 1


I believe the line you quote is about probing KPK tablebase endgame. There are 64 squares for the king, and 24 squares for the pawns (mirrored from file A to D). Nothing special, just how Stockfish indexes the bitbase data structure.

The code is not going to work in Chinese Chess for obvious reason.

This line of code in this file is not well documented

No, the line was fully documented. Please look at the code file again.

Please give me suggestions to understand the source code better

In the open source world, if you don't have sufficient coding experience you just can't do anything. You may ask on the Fishcooking forum, but you will still need decent programming experience.

  • 2
    Nit: in the open source world, people with no/weak programming skills still have important roles. Yes, learning to program will help foster active contributions to the code portion of projects (and here it is paramount), but that is not to say “you just can’t do anything.” May 9, 2020 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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