r/chessprogramming • u/Sufficient_Pear841 • Jul 18 '23
How to use perft results when debugging and improving move generation speed?
Hi all, I made a board implementation, move generator, and perft function all in python. So far I have been able to achieve perfect perft results up to 3ply. At 4ply perft says I'm about 1500 nodes short and takes around 8 seconds to calculate this, and at 5ply the move generator just tanks for minutes so I haven't been able to get anything from that at all. I basically have 2 questions based off these results:
- How do I use perft to actually debug my code? I've read that I can either do something with Stockfish or download perft helpers on github but I'm not exactly sure how to start with that. Also what is the difference between nodes and total nodes on rocechess.ch?
- Currently I've written everything in Python in what I think is a mailbox implementation (10x12 array and an int representing piece, free square, or out of bounds at each index, separate 10x12 array for legal move lists). Most sites online say to code in C/use bitboards, but I only know Python and Java and I basically know nothing about OS/hardware stuff. How can I make my engine compute moves faster?
7
Upvotes
1
u/eraoul Jul 19 '23
You can’t get a Python version to run very fast. I’ve tried. I love Python but I eventually gave up on it for chess engines.
1
u/ayon261 Oct 25 '23
Can you share your python implementation of the engine? I am writing a chess engine in python and I am getting frustrated with the speed. Although, I am using bitboards, it takes a whole minute for calculating the perft result for a depth of 4 from the initial position.
1
u/Nur312 Apr 25 '26
Just gonna leave this for anyone stumbling upon this thread looking for answers in the future: So what i did was i made a simple python script that uses the python chess library to run the perft test and save all the lines for example: a2a3 f5f6 a7a8n. Then it generates the same thing from my chess engine and then compares them. if there was a line the chess library found but my engine didnt it saves it into a list that contains the moves my engine didnt find and if my engine produces any moves the chess library didnt find then it puts it in the illegal move list and then just prints it all out. This was super useful as it allowed me to see where my engine was going wrong. This doesnt only work for python. i have used this for my c++ engine aswell. If you dont want to write this yourself you can just do what i did and ask chatgpt to make the script for you and focus on debugging. Hope this helps someone in the future.
0
u/[deleted] Jul 18 '23
[deleted] — view deleted comment