Computer Chess Club Archives


Search

Terms

Messages

Subject: making code color independant

Author: Georg v. Zimmermann

Date: 09:28:55 12/08/03


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.06 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

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