Computer Chess Club Archives


Search

Terms

Messages

Subject: Design choices in Crafty

Author: Russell Reagan

Date: 15:30:57 06/23/04


I am curious about a few design choices in Crafty. Some of the questions are
general questions that anyone who is knowledgable could answer, so I ask this
publicly instead of via email to Dr. Hyatt.

First issue. Crafty is written with a lot of color-specific code, like:

if (wtm) {
    // ...
}
else {
    // ...
}

This is what I think. The downside to this approach is that you double the size
of the code, which is not cache friendly. This should be a bigger problem in a
rotated bitboard engine where there are already cache issues.

Another potential downside is that you introduce an extra branch. However, I
think that this branch would be easily predictable, since the side to move will
alternate back and forth, and so the branch decision will alternate.

So it seems that as long as you don't overuse this method and ruin the cache,
this is a good method as far as speed is concerned. However, I think it is nicer
to have a single function that works for both colors. It is less to maintain,
and less error prone.

Second issue. Crafty uses a lot of switch statements, using special code for
each case, increasing the code size. Same issues. Could be bad on cache, harder
to maintain. Crafty uses a lot of switch statements to determine the type of a
piece and update the appropriate bitboard. What about having an array of
bitboards, indexed by the type of the piece? There are no branches involved, and
the code is much smaller.

I'd like to know what people think about these design choices. Obviously they
work well for Dr. Hyatt, but I wonder if alternatives would be better choices
that would be faster or less error prone.

Thanks,
Russell



This page took 0.02 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.