A Tale of Two Bugs

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

A Tale of Two Bugs

Post by sje »

A Tale of Two Bugs

Bug 1:

I had run many thousands of different test positions to verify Symbolic's new deep split, multithreaded perft() code. All seemed well until I ran one of the 100K position work units from the Perft(14) project and the program just stopped for no reason, waiting for something which never arrived.

I spent much time looking at the code with most of my suspicion falling on the most recent optimizations I'd made. It turned out that I should have first looked more closely at the input data; the program failed only when the root position was a mate. There aren't very many of these in the unique(7) 96,400,068 position set; only 15,363 (0.03%) in the 51,400,000+ positions processed so far.

The deep split logic is to first look at the number of moves in a position and then enumerate the sub-paths only if there is at least one move available. This was correctly implemented at all levels -- except at the root. The result was that the thread running the root was waiting for an event -- the report of the grand total -- on its input queue which was never posted.


Bug 2:

In Symbolic's Position class, there are six member variables (good, evil, cabs, epsq, hmvc, and fmvn) which together are called the FEN scalar set. I decided that these would be better organized in their own class (class FSS) and then have an instance of this new class be a member of the Position class. This supposedly innocuous reorganization should have had no effect, but moving the relative offsets triggered false negative results from the program's position validity test routine.

More time than I care to admit was needed to resolve this. It turned out that there were a pair of typographical errors in the CountAttacksToSquare() routine which had been in the program for years. The bugs were activated only because of the rearrangement of the members of a Position instance.