Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: smart compiler

Author: Volker Böhm

Date: 14:56:22 06/03/04

Go up one level in this thread


Hi Gerd,

perhaps you can take a look at another piece of code I use to implement
incremental attack tables. I have not any idears to improve it any more.

The function is called after I remove a piece to add attacks blocked by the now
removed piece.

I have a 0x88 board representation with 3 lines border above and below. thus A1
== 0x30. I am able to loop out of the board.

void AdjustRemove(int aPos)
{
int i;
int aDir;
int aCur;
int aDiff;
int aDirBit;
int aFld;
int aBitPos;

// the mAFld is the attack table
// it has 8 bits for 8 directions indicating from witch direction the field
// is attacked. The following line seperates the bits from others and shifts
// them to position 0..7
// This line could be changed to (mAFld[aPos] >> cQueenShift) but that didn´t
// increase speed and does only work if the direction bits are the most
// significant bits (they are now).
aFld = (mAFld[aPos] & cRangeMask) >> cQueenShift;

// as long as the field is attacked from any direction ..
for (i = 0; aFld != 0; i++, aFld >>= 1)
{
        // Looks for the next bit that is set (array-lookup 8 bit)
	aBitPos = cLastBitPos[aFld];
        // i is holding the number of the direction
	i += aBitPos;
        // shift away all "0"´s
	aFld >>= aBitPos;

        // gets the direction from a table with 8 entries
	aDir = cAttackDirs[i];

        // looks for the piece attacking. Don´t know what kind it
        // is. Maybe queen or bishop for diagonals and rook or queen
        // for horizontals. There is not enough space for 8 "is-queen"
        // bits in the attack table field.
	for (aCur = aPos + aDir; IsEmpty(aCur); aCur += aDir);

        // Gets the shape of the piece from the board and
        // converts it to a "kind-of-piece-bit"
	aDiff = cBitLookup[GetP(aCur)];
        // Get the direction bit
	aDirBit = cQueenBit << i;
        // loops through every field now attacked
        // IsEmpty(aCur) compares the board field to 0. The same
        // as GetP(aCur) == 0
	for (aCur = aPos - aDir; IsEmpty(aCur); aCur -= aDir)
	{
                // sets the king-of-piece-bit to the attack signature
                // and the attacked from direction bit
		mAFld[aCur] += aDiff + aDirBit;
	}
        // sets the not empty field. Either a piece or a border field
        // doesn´t matter that a border field could be attacked.
	mAFld[aCur] += aDiff + aDirBit;
}
}



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.