In the Weiss Chess Engine, before evaluation occurs, certain classical information is precomputed and stored in data structures, providing the engine with foundational insights into the chess position. This information includes attack tables, pawn structures, and mobility areas, among other things. Here's a breakdown of the classical information available before evaluation:
1. Bitboards
Bitboards are the primary representation of the board state in Weiss. They store the positions of various pieces, colors, and other features of the board using 64-bit integers. The following bitboards are available:
pos->pieceBB[type]: Tracks the positions of specific piece types (PAWN, KNIGHT, BISHOP, etc.).
pos->colorBB[color]: Tracks the positions of all pieces for each color (WHITE, BLACK).
pos->pieceBB[ALL]: Tracks all pieces on the board.
These bitboards allow the engine to quickly look up which squares are occupied by which pieces and calculate derived information such as attacks, mobility, or threats.
2. Attack Tables
Before evaluation, [Redacted Person] precomputes attack tables for all pieces on the board. This is done using bitboard operations and magic bitboards for fast sliding piece ([Redacted Person], [Redacted Person], and queen) attack generation. These attack tables are used to determine:
- Which squares are attacked by each piece.
- Which squares are attacked by all pieces of a certain type (e.g., all pawns or all knights).
- Whether specific squares (e.g., the king's square) are under attack.
The attack generation functions include:
AttackBB(pt, sq, occ): Returns the attack bitboard for a given piece type pt on square sq, considering the occupied squares occ.
PawnAttackBB(color, sq): Returns the attack bitboard for pawns of a given color from a square.
XRayAttackBB(pos, color, pt, sq): Handles x-ray attacks for sliding pieces, considering blockers of the same color or enemy queens.
These attack tables form the basis for many evaluations, such as mobility, king safety, and passed pawn detection.
3. King Safety Information
The king's position is crucial for evaluating king safety. The following information is derived early:
kingSq(color): The square of the given color's king.
AttackBB(KING, sq, 0): The set of squares attacked by the king, used to define the king's "zone."
ei->kingZone[color]: A bitboard representing the king's zone, which includes squares directly adjacent to the king.
The king zone is essential for evaluating king safety and assessing how well-protected the king is.
4. Pawn Structures
Pawns are evaluated separately because of their unique movement and influence. Before evaluation, the following pawn-specific information is extracted:
PawnBBAttackBB(pawns, color): Calculates all squares attacked by pawns of a given color.
PassedMask[color][sq]: Precomputed bitboards that help determine if a pawn is a passed pawn (no enemy pawns block its progress).
IsolatedMask[sq]: Precomputed bitboards that help identify isolated pawns (pawns without neighbors on adjacent files).
Pawn attacks and structures are fundamental for detecting weaknesses (e.g., isolated or doubled pawns) and strengths (e.g., passed pawns).
5. Mobility Areas
[Redacted Person] precomputes mobility areas for each color, which define where pieces are free to move without being blocked by their own pawns or attacked by enemy pawns:
ei->mobilityArea[color]:
- Includes squares that are not occupied by the engine's own pawns.
- Excludes squares attacked by enemy pawns.
- Excludes squares blocked by friendly pawns that cannot move forward.
Mobility areas are used to evaluate the freedom of movement for each piece, which correlates with the position's quality and activity.
6. Checker Detection
Before evaluation, the engine identifies whether the side to move is in check:
pos->checkers: A bitboard holding all pieces currently delivering checks to the king of the side to move.
Checkers(pos): A function that produces the pos->checkers bitboard, combining all possible attacks on the king's square.
KingAttacked(pos, color): A function that determines whether the king of a specific color is under attack.
This information is crucial for move legality and tactical evaluations.
7. Between and Line Masks
Precomputed masks help detect relationships between pieces and squares:
BetweenBB[sq1][sq2]: A bitboard representing all squares between two given squares sq1 and sq2. This is used for pin detection and determining if a move blocks a check.
AttackBB(pt, sq1, BB(sq2)): Used to check if sliding pieces (bishops, rooks, or queens) attack a square while considering blockers.
These masks are used for pin detection, x-ray evaluations, and tactical considerations.
8. Pawn Hash Table
Weiss uses a pawn hash table to cache precomputed pawn evaluations:
pos->pawnKey: A Zobrist hash representing the current pawn structure.
- Pawn Cache (
pc): A lookup table storing evaluations of pawn structures to avoid redundant calculations.
If the pawn evaluation for the current position exists in the pawn cache, it can be reused directly.
9. Material Imbalances
Material values for each piece type are precomputed, including midgame and endgame weights:
PieceValue[phase][piece]: Midgame and endgame values for each piece.
pos->material: Total material evaluation (including piece-square tables) for the current position.
Material values are combined with other features during evaluation.
10. Game Phase
The game phase is precomputed based on the number of remaining pieces:
pos->phaseValue: A value representing the material composition of the board.
pos->phase: A normalized value (0 to 256) representing the stage of the game (early, midgame, or endgame).
The game phase is used for tapered evaluation, where midgame and endgame scores are blended.
Summary of Precomputed Information
Before evaluation, [Redacted Person] has access to the following classical information:
- Piece positions and types via bitboards.
- Attack tables for all piece types.
- King safety zones and adjacent attacks.
- Pawn structures (isolated, doubled, passed pawns, etc.).
- Mobility areas for each color.
- Checkers and pin detection.
- BetweenBB and line masks for tactical considerations.
- Pawn hash table for cached pawn evaluations.
- Material imbalances for midgame and endgame.
- Game phase for blending evaluations.
This foundational information allows the engine to quickly and efficiently perform detailed evaluations and make strategic decisions.