RedBedHed wrote: ↑Sun Aug 08, 2021 11:48 am
(I originally posted this in the "general topics" forum by mistake.)
Hi! My name is Ellie. I am an undergrad student at ASU (software engineering). I am currently writing a stockfish and lc0 derived chess engine that I plan to use in a school project. Although my favorite language will always be Java, I decided to use C++ and Python for this project. (I am honestly starting to fall in love with C++. It is such a tsundere lol.)
Anyways, after about three months of reading and pulling my hair out, I finally have a working move generator that produces strictly legal moves! I've tested it on all of the chessprogramming.org positions, and I am so excited to be able to share it with ya'll! I am really hoping to obtain some feedback on how I can improve it. I know that it is a little ugly and still pretty far from optimal in places. (For example, my king moves are currently verified as they are generated.)
Here is the github link:
https://github.com/RedBedHed/Charon
And here are my bulk-counted perft numbers (from the initial position, i5 processor, 1.6 ghz):
perft(1) - 0.000 seconds - 20 nodes visited.
perft(2) - 0.000 seconds - 400 nodes visited.
perft(3) - 0.000 seconds - 8902 nodes visited.
perft(4) - 0.000 seconds - 197281 nodes visited.
perft(5) - 0.031 seconds - 4865609 nodes visited.
perft(6) - 0.656 seconds - 119060324 nodes visited.
I hope everyone is having a great summer!
Hi Ellie, welcome to TalkChess! And congratulations on your hard work so far
It's good that you're starting to test your move generator. However, I recommend testing more than just the 6-7 positions given on the Chess Programming Wiki. While they are good at catching some bugs, there are many other bugs that might be hiding in more unique positions. Look around for some more extensive perft testing suites with a variety of positions (opening, middle, and endgames) that other engines use (to see what I mean, you can take a peek at the suite that I'm using for my own engine:
https://github.com/algerbrex/blunder/bl ... tsuite.txt).
As far as code goes, taking a quick look through your codebase, I didn't see any glaring bugs or other oddities with regards to the bitboard techniques or algorithms you're using, and at the cursory glance I took, you're code was pretty readable.
A word of advice I would give, while your engine is still in the early stages, is to consider using a pseudo-legal move generator instead of a legal one. Of course, a legal or pseudo-legal move generator can provide a strong foundation for a chess engine, but once you reach the search phase, it'll generally be less work to just generate pseudo-legal moves and verify that each one is legal. This is because once you implement decent move ordering in your engine, the first several moves it looks at will hopefully be the bests, and so it won't waste time looking at all the other moves, and won't spend the extra work of calculating if they're legal. But with a fully legal move generator, the time is spent verifying every move is legal regardless of if you actually have to.
Now I'm not saying scrap the work you have so far, because as anyone here can attest to, making a working move generator can be the difficult first step and is nothing to sniff at, but I think it's something you should definitely consider.
One more piece of advice I would give is to be careful not to get too caught up in the perft speed side quest. While having a blazing fast move generator is a very nice perk and, I think, something to be proud of, you'll find as you write the search and evaluation phases of your engine that move generation is such a small part of the general search time that it's really not worth worrying about until at the very least you implement and experiment with some different basic search optimizations (alpha-beta pruning, move ordering, quiescence search, transposition table, killer moves, history heuristic, null-move pruning et al.) Focusing on those kinds of improvements will give you much bigger ELO boosts than trying to squeeze every last drop of performance out of your move generator.