Here's a blog post I wrote with some tips about debugging your chess move generator and make / unmake routines:
Debugging a Chess Engine's Move Generator
Hopefully it's useful to anyone in the early stages wrestling with their engine's code!
Steve
Debugging a Chess Engine's Move Generator...
Moderator: Ras
-
- Posts: 1297
- Joined: Wed Mar 08, 2006 8:28 pm
- Location: Florida, USA
-
- Posts: 303
- Joined: Sat Apr 28, 2012 6:18 pm
- Location: Austin, TX
Re: Debugging a Chess Engine's Move Generator...
Hello Steve,Steve Maughan wrote:Here's a blog post I wrote with some tips about debugging your chess move generator and make / unmake routines:
Debugging a Chess Engine's Move Generator
Hopefully it's useful to anyone in the early stages wrestling with their engine's code!
Steve
Don't forget, besides flipping the board top-to-bottom you can also flip it side-to-side.
In fact, you have these cases to check:
- initial, perft
flip-tb, perft
flip-lr, perft
flip-tb, perft
regards,
--tom
-
- Posts: 1297
- Joined: Wed Mar 08, 2006 8:28 pm
- Location: Florida, USA
Re: Debugging a Chess Engine's Move Generator...
What about castling rights? They aren't symmetrical?
Best,
Steve
Best,
Steve
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Debugging a Chess Engine's Move Generator...
I would say that positions with any of the four possible castling rights set can't be flipped left-to-right. Even if you would define such a flipLR() operation by clearing all castling rights this would destroy the basic assumption "flipLR(flipLR(pos)) == pos".Steve Maughan wrote:What about castling rights? They aren't symmetrical?
Sven
-
- Posts: 686
- Joined: Thu Mar 03, 2011 4:57 pm
- Location: Germany
Re: Debugging a Chess Engine's Move Generator...
Flipping and Flopping the board is more helpful in testing your evaluation (if it is meant to be symmetrical).
But if I do that I also do not mirror left / right when castling rights are present.
For a move generator a set of positions with known perfts is probably the best method to test.
Thomas...
But if I do that I also do not mirror left / right when castling rights are present.
For a move generator a set of positions with known perfts is probably the best method to test.
Thomas...
-
- Posts: 303
- Joined: Sat Apr 28, 2012 6:18 pm
- Location: Austin, TX
Re: Debugging a Chess Engine's Move Generator...
There are ways to handle it, but the simplest is to check if the initial position has castling rights and if yes only flip it top-to-bottom. If all castling rights are gone then all four flips are possible. I know most people only use this to test the symmetry of their evaluation functions, but it's been my experience that the more you beat on your program to catch bugs the stronger it will ultimately become. There are a lot of dark corners where bugs can lurk and adding novel ways to test things almost always pays off.
Another thing you might think about is how to test your move generation if you segment it, (i.e. if you start to generate moves in phases). A lot of programs, mine included, start out generating everything and then gradually transition to generating only the moves they need for various search phases (winning captures, promotions etc.). You'll also need to verify that each of these individual move generators are OK.
regards,
--tom
Another thing you might think about is how to test your move generation if you segment it, (i.e. if you start to generate moves in phases). A lot of programs, mine included, start out generating everything and then gradually transition to generating only the moves they need for various search phases (winning captures, promotions etc.). You'll also need to verify that each of these individual move generators are OK.
regards,
--tom