Basically, I’m creating a chess AI and I want to focus on the search algorithm rather than the most complete way or fastest move generation portions. So, for now, I was thinking I could use a prebuilt move generator from a tested and well-known source such as Stockfish.

But I'm having trouble understanding how Stockfish represents the current gamestate and how I can read it, how I can get Stockfish to essentially loop through all of the possible nodes, and how I can check if a given node is a leaf. If someone could point me to a resource or knows how Stockfish does this it would be greatly appreciated.

  • Can you be more specific of what you don't understand? Bitboards, translating into a square, source code not commented enough...?
    – Mike Jones
    Apr 21, 2020 at 8:09
  • Essentially what im trying to understand is two things how does stockfish represent the board i.e bitboards or some variation and then secondly what methods or functions it uses to do basic things like check for checkmate. From this information I intend to derive how I can read the current positions of every piece and generate all of the legal moves possible. Apr 22, 2020 at 4:44
  • craftychess.com is well documented, and you should have all your questions answered. I prefer the 64 square board representation as it lends itself to better chess understanding.
    – Mike Jones
    Apr 22, 2020 at 17:33

2 Answers 2


For the fastest move generation I suggest the below code.


It’s not the Stockfish source code, but I was able to use it for my own hobby engine and I can tell you that it’s very fast. If you have a lot of trouble I can write a post about how I did it.

  • Thank you for your response i am already using this movegen for my sliding pieces and I was looking for something that could either cover the move generation for at least the pawns and knights or do the entire move generation Apr 22, 2020 at 4:40
  • I can send you my code if need be (its perft checked). Maybe look into python-chess if you want to prototype an AI engine, then switch over to a faster language.
    – nak3c
    Apr 22, 2020 at 11:46

It's javascript but chess.js https://github.com/jhlywa/chess.js/ will keep track of board state, load & generate pgns and fens, and tell you what moves are legal.

Your Answer

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

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