Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: making code color independant

Author: Dezhi Zhao

Date: 12:56:45 12/08/03

Go up one level in this thread


On December 08, 2003 at 12:28:55, Georg v. Zimmermann wrote:

I think the fastest way of doing it is to avoid using extra memory
and branches.

Suppose your onMove consists only 2 values, 0 for white and -1 for black.

So the code goes like this:

if (to >> 4 == 7 & onMove)
{
   .......
}



>This has been recently discussed, but on a very sophisticated level, while I am
>looking for a simple solution.
>
>Right now I just have 2 makeMove() , 2 genAllMove(), 2 genCaptures() etc etc
>
>In there are statements like
>
>if (to >> 4 == 7) // is it a promotion ?
>{...}
>
>To make the code color independent, my first idea was to have
>
>if (to >> 4 == lastRank[onMove])
>{..}
>
>and have such similar arrays for colorMask[2], fifthRank[2], e1Square[2],
>pawnDirection[2] etc.
>
>First question: how slow is this ? Is it comparable slow as having
>
>if (onMove)
>  if (to >> 4 == 7)
>  {...}
>else
>  if (to >> 4 == 0)
>  {...}
>
>which is horrible ?
>
>
>Then my next idea was to have a structure where I put all the relevant info in.
>struct colorDep
>{
>  int lastRank;
>  [...]
>};
>
>and then fill 2 such structures with the correct info for white and black. And
>have a pointer which always points to the correct one. Then I could do
>
>if (to >> 4 == cD->lastRank)
>{..}
>
>Is this faster as the array solution, as I think it is ?
>
>
>Thanks a lot for any help - and I do accept RTM as answer, if it comes with a
>good link :-).
>
>Georg



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.