Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Attack table

Author: Scott Gasch

Date: 20:38:41 10/18/05

Go up one level in this thread


On October 18, 2005 at 11:10:44, JW de Kort wrote:

>Thank for the reply.
>
>I do the same in my enige but it makes it very slow. Any advice on a speed full
>implementation?
>
>Thnaks

Here's my idea.  I wouldn't say it's fast but it's bearable.  When I added the
jump tables I thought I might recoop some time because of having less
if-statements in the middle of tight loops.  In reality the speed was about the
same as before but I think the code is cleaner.  I included a "bishop" example
and and example of one of the jump table targets below.

Good luck,
Scott


static FLAG FASTCALL
_WMinorToEmpty(POSITION *pos,
               COOR c,
               ULONG *puMobility,
               ULONG *puBit)
{
#ifdef DEBUG
    PIECE pMinor = pos->rgSquare[pos->cPiece].pPiece;
    PIECE p = pos->rgSquare[c].pPiece;

    ASSERT(IS_EMPTY(p));
    ASSERT(!IS_EMPTY(pMinor));
    ASSERT(IS_BISHOP(pMinor) || IS_KNIGHT(pMinor));
    ASSERT(GET_COLOR(pMinor) == WHITE);
#endif
    *puMobility += (!UNSAFE_FOR_MINOR(pos->rgSquare[c|8].bvAttacks[BLACK]));
    ASSERT(*puMobility <= 8);
    return(FALSE);
}

[...]

    static const PMOBILITY_HELPER BMobJumpTable[2][14] =
    {
        {// (black)
            _BMinorToEmpty,                    // EMPTY_SQUARE  (0)
            _InvalidMobilityHelper,            // INVALID_PIECE (1)
            _EBishopToFriendPawn,              // BLACK_PAWN    (2)
            _BMinorToEnemyLess,                // WHITE_PAWN    (3)
            _AnythingToFriendNoXray,           // BLACK_KNIGHT  (4)
            _EMinorToEnemySame,                // WHITE_KNIGHT  (5)
            _EMinorToFriendXray,               // BLACK_BISHOP  (6)
            _EMinorToEnemySame,                // WHITE_BISHOP  (7)
            _AnythingToFriendNoXray,           // BLACK_ROOK    (8)
            _EMinorToEnemyGreater,             // WHITE_ROOK    (9)
            _EMinorToFriendXray,               // BLACK_QUEEN   (10)
            _EMinorToEnemyGreater,             // WHITE_QUEEN   (11)
            _AnythingToFriendNoXray,           // BLACK_KING    (12)
            _EMinorToEnemyGreater,             // WHITE_KING    (13)
        },
        {// (white)
            _WMinorToEmpty,                    // EMPTY_SQUARE  (0)
            _InvalidMobilityHelper,            // INVALID_PIECE (1)
            _WMinorToEnemyLess,                // BLACK_PAWN    (2)
            _EBishopToFriendPawn,              // WHITE_PAWN    (3)
            _EMinorToEnemySame,                // BLACK_KNIGHT  (4)
            _AnythingToFriendNoXray,           // WHITE_KNIGHT  (5)
            _EMinorToEnemySame,                // BLACK_BISHOP  (6)
            _EMinorToFriendXray,               // WHITE_BISHOP  (7)
            _EMinorToEnemyGreater,             // BLACK_ROOK    (8)
            _AnythingToFriendNoXray,           // WHITE_ROOK    (9)
            _EMinorToEnemyGreater,             // BLACK_QUEEN   (10)
            _EMinorToFriendXray,               // WHITE_QUEEN   (11)
            _EMinorToEnemyGreater,             // BLACK_KING    (12)
            _AnythingToFriendNoXray,           // WHITE_KING    (13)
        }
    };

[...]

    do
    {
        uCurrentMobility = 0;
        uBit = MINOR_BIT;
        cSquare = c + g_iBDeltas[u]; // bishop deltas

        while(IS_ON_BOARD(cSquare))
        {
            //
            // Always toggle attack table bits.
            //
            pos->rgSquare[cSquare|8].bvAttacks[uColor].uWholeThing |= uBit;

            //
            // What did we hit?
            //
            p = pos->rgSquare[cSquare].pPiece;
            pFun = BMobJumpTable[uColor][p];
            ASSERT(pFun);
            if (TRUE == (*pFun)(pos,
                                cSquare,
                                &uCurrentMobility,
                                &uBit))
            {
                break;
            }
            cSquare += g_iBDeltas[u];
        }
        uTotalMobility += uCurrentMobility;
        ASSERT((uMaxMobility & 0x80000000) == 0);
        ASSERT((uCurrentMobility & 0x80000000) == 0);
        uMaxMobility = MAXU(uMaxMobility, uCurrentMobility);
        ASSERT(uMaxMobility <= 7);
        u++;
    }
    while(g_iBDeltas[u] != 0);
    ASSERT(uTotalMobility <= 13);




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.