diff options
Diffstat (limited to 'src/data.c')
| -rwxr-xr-x | src/data.c | 73 |
1 files changed, 73 insertions, 0 deletions
@@ -578,6 +578,15 @@ BITBOARD g_RookRayToEdge[4][128]; const int g_RookRayDeltas[4] = { 16, -16, 1, -1 }; // N, S, E, W (0x88) const FLAG g_RookRayPositiveDir[4] = { TRUE, FALSE, TRUE, FALSE }; +// Per-square OR of all 4 g_RookRayToEdge directions -- "every square a +// rook on c could reach on an empty board, regardless of direction." +// One lookup (+ AND against a slider bitboard) to answer "is uSide's +// rook/queen bitboard aligned with c *at all*", vs. 4 separate +// g_RookRayToEdge lookups to discover the same "no" -- see +// _WhoAttacksSquareBB (see.c) for the consumer and +// board_representation/MIGRATION.md section 3 for the writeup. +BITBOARD g_RookRayAll[128]; + void InitializeRookRayTables(void) /** @@ -600,6 +609,7 @@ Return value: COOR c, cSquare; memset(g_RookRayToEdge, 0, sizeof(g_RookRayToEdge)); + memset(g_RookRayAll, 0, sizeof(g_RookRayAll)); for (uRank = 0; uRank < 8; uRank++) { for (uFile = 0; uFile < 8; uFile++) @@ -612,6 +622,7 @@ Return value: cSquare += g_RookRayDeltas[uDir]) { g_RookRayToEdge[uDir][c] |= COOR_TO_BB(cSquare); + g_RookRayAll[c] |= COOR_TO_BB(cSquare); } } } @@ -625,6 +636,9 @@ BITBOARD g_BishopRayToEdge[4][128]; const int g_BishopRayDeltas[4] = { 17, -17, 15, -15 }; // NE, SW, NW, SE (0x88) const FLAG g_BishopRayPositiveDir[4] = { TRUE, FALSE, TRUE, FALSE }; +// g_RookRayAll's counterpart for the bishop's 4 diagonal directions. +BITBOARD g_BishopRayAll[128]; + void InitializeBishopRayTables(void) /** @@ -647,6 +661,7 @@ Return value: COOR c, cSquare; memset(g_BishopRayToEdge, 0, sizeof(g_BishopRayToEdge)); + memset(g_BishopRayAll, 0, sizeof(g_BishopRayAll)); for (uRank = 0; uRank < 8; uRank++) { for (uFile = 0; uFile < 8; uFile++) @@ -659,6 +674,7 @@ Return value: cSquare += g_BishopRayDeltas[uDir]) { g_BishopRayToEdge[uDir][c] |= COOR_TO_BB(cSquare); + g_BishopRayAll[c] |= COOR_TO_BB(cSquare); } } } @@ -720,3 +736,60 @@ Return value: } } } + +// +// Per-square, per-side "the (up to 2) squares a pawn of this side +// would need to stand on to attack c" bitboard -- e.g. +// g_PawnAttackOriginBB[WHITE][c] is c's two SE/SW neighbors (a white +// pawn attacks diagonally forward, so it must stand behind-and-beside +// c to hit it). Same idea as g_KnightAttacksBB: a single lookup+AND +// against bbPawns[side] answers "does uSide have a pawn attacking c" +// entirely in bit-space, no COOR arithmetic/IS_ON_BOARD check at +// runtime -- see _GetAttacksBB (see.c) for the consumer. +// +BITBOARD g_PawnAttackOriginBB[2][128]; + +void +InitializePawnAttackOriginTable(void) +/** + +Routine description: + + One-time startup init for g_PawnAttackOriginBB -- see its comment. + +Parameters: + + void + +Return value: + + void + +**/ +{ + static const int iSeeDelta[2] = { -17, +15 }; // BLACK, WHITE + ULONG uRank, uFile, uSide; + COOR c, cOrigin; + + memset(g_PawnAttackOriginBB, 0, sizeof(g_PawnAttackOriginBB)); + for (uRank = 0; uRank < 8; uRank++) + { + for (uFile = 0; uFile < 8; uFile++) + { + c = (uRank << 4) | uFile; + for (uSide = 0; uSide < 2; uSide++) + { + cOrigin = c + iSeeDelta[uSide]; + if (IS_ON_BOARD(cOrigin)) + { + g_PawnAttackOriginBB[uSide][c] |= COOR_TO_BB(cOrigin); + } + cOrigin += 2; + if (IS_ON_BOARD(cOrigin)) + { + g_PawnAttackOriginBB[uSide][c] |= COOR_TO_BB(cOrigin); + } + } + } + } +} |
