How to debug Move Generation function? I'm writing a chess engine, and I'm testing that the move generator is working correctly using a perft() function.  In perft position 2 my engine appears to be 90 moves short at ply 2.  How do authors of other engines then debug their engines?  Is there a full list of perft moves available online somewhere?

The obvious issue with using an established engine to enumerate the moves is if there's a bug in the move generation function in the established engine.
The obvious issue with using an established engine to enumerate the moves is if there's a bug in the move generation function in the established engine.


Stockfish is always perfectly correct.

Goto https://github.com/official-stockfish/Stockfish/blob/master/src/search.cpp, add a std::cout in perft(). Recompile, and then run perft. Redirect your results to a text file.

Sort the results with: sort SFMoves.txt &gt; SortedSFMoves.txt.

Similarly, repeat for your generator, sort it and then compare with Stockfish.

Common mistakes:


En-passpant
Underpromotion
Promote with a capture


Please check the special cases in your code.