1

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 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. – Julian Carrier Apr 22 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 at 17:33
2

For the fastest move generation I suggest the below code.

https://github.com/Mk-Chan/WyldChess/blob/master/src/magicmoves.c

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.

| improve this answer | |
  • 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 – Julian Carrier Apr 22 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 at 11:46
1

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.

| improve this answer | |

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.