Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Colourspecific code (C++ and templates/traits)

Author: Russell Reagan

Date: 16:05:06 11/27/03

Go up one level in this thread


On November 27, 2003 at 12:47:21, Daniel Clausen wrote:

>and the if-statement there would be optimized away anyway since 'c' is constant
>in a specific instance. But I try to avoid this if-statement. Maybe that doesn't
>work though?

But how are you going to get c to be constant? If you do:

bb = PawnAttacks<c>(someSquare);

that is not particularly useful. You still need to know which one to call
somehow, which means another if statement. It seems like you're trying to save
an if statement or some small computation like a table lookup, and I don't think
you can do it with templates.

My best guess at how you might solve this efficiently is to create two structs
that contain the color specific information for each side. Then set a pointer to
each struct for the side to move and the side not to move and swap them during
make move and undo move. Then you could do:

sideToMove->forwardPawnDirection;
sideToMove->pawnAttacks[someSquare];
// and so on...



This page took 0 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.