Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Just what I needed! Thanks!

Author: Tim Foden

Date: 08:47:17 10/03/01

Go up one level in this thread


On October 01, 2001 at 20:20:25, Gian-Carlo Pascutto wrote:

>I've put my SEE routine below, in case you're interested

<snipped>

I think there may be a bug in your code.  I have for some time thought it may be
a good idea to write a second SEE for GLC, to check that the main one is working
correctly, so I thought I'd try to make yours work inside GLC.

I guess I should ask if this is OK by you...??

Anyway, All was fine until...

>void add_hor_attackers(int tsq, int fsq)
...
>	  for (fsq += 12; fsq == npiece; fsq += 12);

It looks to me that you will only find xray attacks if they are right behind the
previously attacking piece.

The same kind of for loop happens in a number of places, and occurs in
add_diag_attackers too.

I think your for loop should look like this: (??)

	  for (fsq += 12; board[fsq] == npiece; fsq += 12);


Cheers, Tim.

BTW, If you or Steve are interested, here the SEE code from GLC:

/*--------------------------------------------------------------------------*/

void	SortPieces( int n, Square* pPiece )
{
	// insertion sort
	for( int i = 1; i < n; i++ )
	{
		for(	int j = i - 1;
				j >= 0 && CPiece::Value(m_sboard[pPiece[j]]) >
							CPiece::Value(m_sboard[pPiece[j+1]]);
				j-- )
		{
			Square	pos = pPiece[j];
			pPiece[j] = pPiece[j + 1];
			pPiece[j + 1] = pos;
		}
	}
}

/*--------------------------------------------------------------------------*/

int		StaticExchangeEval( CMove move )
{
	return StaticExchangeEval(move.GetFrom(), move.GetTo(), move.GetPromoteTo());
}

/*--------------------------------------------------------------------------*/

int		StaticExchangeEval( Square from, Square to, int promoteTo )
{
#ifdef SEE_INFO
	m_seeCount++;
//	CFileTime	start = CFileTime::GetCurrentTime();
#endif

	// need to build a list of pieces that can move to move.GetTo(),
	// and sort them into colour and value

	UINT64	toBitmap = BitmapFromSq(to);
	UINT64	fromBitmap = BitmapFromSq(from);
	UINT64	board = m_bitBoard.m_bits & ~(fromBitmap | toBitmap);
	UINT64	attackerBoard = board & m_squareAttacks[to];

	Square	sideAttackers[2][16];
	int		nSideAttackers[2];
	nSideAttackers[white] = nSideAttackers[black] = 0;
	Square	xRays[32];
	int		nXRays = 0;

	// look for other pieces
	Square	attackFrom;
	while( attackerBoard )
	{
		attackFrom = BitScanForwardRemove(attackerBoard);

		int		piece = m_sboard[attackFrom];
		DBG_ASSERT( piece != none );

		int		pieceMask = m_possMoveMask[piece + 6];
		int		offset = MOVE_HASH(attackFrom, to);

		int		moveFlag = m_kingAttacks[offset];
		if( (moveFlag & pieceMask) == 0 )
			continue;

		int		pIsW = CPiece::IsW(piece);
		if( pieceMask & (moveKnight | moveKing | moveBlackPawn | moveWhitePawn) )
		{
			sideAttackers[pIsW][nSideAttackers[pIsW]++] = attackFrom;
		}
		else if( (board & m_moveLines[offset]) == 0 )
		{
			sideAttackers[pIsW][nSideAttackers[pIsW]++] = attackFrom;
		}
		else
		{
			xRays[nXRays++] = attackFrom;
		}
	}

	// sort attackers into increasing value order
	SortPieces( nSideAttackers[white], sideAttackers[white] );
	SortPieces( nSideAttackers[black], sideAttackers[black] );

	int		values[32];
	int		nValues = 0;
	int		sign = 1;
	int		total = 0;

	// add the pieces we know are involved
	total = CPiece::Value(m_sboard[to]);
//	if( promoteTo )
//		total += Piece::Value(promoteTo) - Piece::Value(wPawn);
	values[nValues++] = total;

	total -= CPiece::Value(m_sboard[from]);
//	if( promoteTo )
//		total -= Piece::Value(promoteTo) - Piece::Value(wPawn);
	values[nValues++] = total;

	int		next[2];
	next[white] = next[black] = 0;

	bool	wtm = !m_wtm;
	while( next[wtm] < nSideAttackers[wtm] )
	{
		// got one...
		Square	attackerPos = sideAttackers[wtm][next[wtm]++];
		int		attackerPiece = m_sboard[attackerPos];
		total += sign * CPiece::Value(attackerPiece);
		sign = -sign;
		values[nValues++] = total;

		// allowed xray to become attack??
		board &= ~BitmapFromSq(attackerPos);

		for( int i = 0; i < nXRays; i++ )
		{
			Square	xRayPos = xRays[i];
			int		offset = MOVE_HASH(xRayPos, to);
			if( (board & m_moveLines[offset]) == 0 )
			{
				// remove from xray list
				xRays[i] = xRays[--nXRays];

				// add to attacker list
				int		xIsW = CPiece::IsW(m_sboard[xRayPos]);
				sideAttackers[xIsW][nSideAttackers[xIsW]++] = xRayPos;
				SortPieces( nSideAttackers[xIsW] - next[xIsW],
							sideAttackers[xIsW] + next[xIsW] );

				// can only uncover one piece at once, so break from loop now
				break;
			}
		}

		wtm = !wtm;
	}

	// so, now that we have a list of piece values in the order they
	//	would attempt to take exchange, we do a kind of minimax to
	//	find the correct value
	// TODO: figure out whether it would be possible/faster to do
	//	this on the fly in the loop above

	nValues--;
	while( --nValues > 0 )
	{
		if( nValues & 1 )
		{
			if( values[nValues] <= values[nValues - 1] )
				values[nValues - 1] = values[nValues];
		}
		else
		{
			if( values[nValues] >= values[nValues - 1] )
				values[nValues - 1]=values[nValues];
		}
	}

#ifdef SEE_INFO
	CFileTime	end = CFileTime::GetCurrentTime();
//	m_seeTime += (end - start);
#endif

	return values[0];
}




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.