Explain which evaluations are run in this engine BEFORE the eval call, and which could then be used in a NNUE that will replace the current eval function. Be specific.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To answer the question, let's break it into two parts: the evaluations run before the call to the main EvalPosition() function and what evaluations could be adapted or used in a NNUE (neural-network-based evaluation function).
1. Evaluations Run BEFORE the EvalPosition() Call
The Weiss chess engine evaluates certain aspects of the position before calling the main EvalPosition() function. These pre-evaluations are primarily aimed at early pruning, move ordering, and optimization of the search process. Here is a detailed breakdown:
Static Evaluation (Static Eval)
The static evaluation is frequently calculated and reused during search. It is derived either:
From the transposition table (TT) if a valid entry for the position exists (ttEval), or
By calling EvalPosition() directly when needed.
In certain cases, the static evaluation from the parent node is adjusted instead of recalculating it:
Static null-move adjustment: If the last move was a null move, the static evaluation is adjusted as:
c
eval = -(ss-1)->staticEval + 2 * Tempo;
This adjustment adds a tempo bonus for the side to move.
TT-based Evaluation
If a transposition table (TT) entry exists, its evaluation (ttEval) is used where possible. This avoids recomputation of the position's evaluation during alpha-beta pruning and quiescence search.
Syzygy Tablebase Probes
For endgames, the engine probes Syzygy tablebases before deeper evaluation. If the position matches a known endgame configuration, this gives an exact score (win/loss/draw) and bypasses further evaluation:
c
if (ProbeWDL(pos, &tbScore, &bound, ss->ply)) {
...
// Use tbScore or bound to skip EvalPosition
}
Repetition and Rule 50 Checks
Before calling EvalPosition, the engine evaluates whether the position is:
A repetition (via IsRepetition(pos)),
Or if the 50-move rule applies (pos->rule50 >= 100).
Such positions are immediately assigned a draw score and avoid deeper evaluation.
2. Evaluations Performed WITHIN EvalPosition()
The EvalPosition() function handles the bulk of the engine's position evaluation. It evaluates several components of the chess position, which could be incorporated into a neural network (NNUE). Below is a detailed breakdown of the evaluations and how they might map to a NNUE-based model:
2.1 Pawn Evaluation
The EvalPawns() function evaluates the pawn structure. It includes:
Doubled pawns (pawns on the same file): Penalized.
Isolated pawns (no adjacent pawns on neighboring files): Penalized.
Pawn chains (connected pawns): Rewarded for supporting each other.
Passed pawns: Rewarded based on their rank and potential to promote.
Pawn phalanx (pawns side-by-side): Bonus based on rank.
Open pawns (pawns without enemy pawns in front): Penalized.
This information is often critical for NNUE models, as pawn structure significantly influences positional play. Specifically:
Bitboards for pawn placements could serve as direct input features for the NNUE.
Precomputed features like passed pawns, isolated pawns, and phalanxes could also enhance NNUE efficiency.
2.2 Piece-Specific Evaluations
The EvalPiece() function evaluates each piece type (knights, bishops, rooks, queens) based on piece-square tables (PSQT) and dynamic features:
Piece mobility: Number of squares a piece can move to.
Bishop pair: Bonus for having two bishops.
Minor pieces behind pawns: Bonus for positioning knights/bishops behind advancing pawns.
Rooks on open/semi-open files: Rewarded for rooks on files without pawns or with only opponent pawns.
Bad bishops: Penalized for bishops blocked by pawns of the same color.
For NNUE:
Piece-bitboards could serve as input features.
Mobility and dynamic piece-square weights could be replaced by NNUE's pattern recognition.
2.3 King Safety
The EvalKings() function evaluates king safety:
King's shelter pawns: Pawns in front of the king are rewarded.
King attacks: Penalty for proximity of enemy pieces to the king.
Open lines near the king: Penalized for exposed kings.
This aspect could be encoded in NNUE using:
Bitboards of pawns near the king.
Attack maps representing threats to the king.
2.4 Passed Pawn Evaluation
The EvalPassedPawns() function evaluates passed pawns specifically:
Distance to promotion squares.
Support from friendly pieces and threats from enemy pieces.
Blocked or free paths to promotion.
NNUE could use:
Bitboards for passed pawns.
Distance-to-promotion information.
2.5 Threat Evaluation
The EvalThreats() function evaluates:
Threats to enemy pieces by pawns and other pieces.
Threats by minor pieces and rooks.
NNUE can encode threats through:
Piece attack maps (e.g., which pieces are attacking which squares).
2.6 Endgame Scaling
The ScaleFactor() function adjusts the evaluation based on:
Material imbalances (e.g., lone king vs. king and pawns).
Endgame-specific rules like opposite-colored bishops.
NNUE could incorporate this scaling implicitly by recognizing material configurations and adjusting scores accordingly.
3. Evaluations That Could Be Used in NNUE
A NNUE model can leverage many of the features already computed by the Weiss engine. Specifically, the following aspects could be adapted:
Piece Placement and Piece-Square Tables:
NNUE can replace the current PSQT-based evaluation with a learned neural network representation of how pieces interact on the board.
Pawn Structure:
Features like isolated pawns, doubled pawns, passed pawns, and pawn attacks are critical positional elements that NNUE can encode.
King Safety:
The engine's attack calculations and shelter evaluations can be integrated into NNUE through attack maps and king-proximity features.
Piece Attacks and Mobility:
NNUE can replace the manual mobility calculations with learned patterns about effective piece activity.
Endgame Recognition:
Endgame-specific evaluations (e.g., scaling for opposite-colored bishops) can be replaced by NNUE's ability to learn from similar positions in its training data.
Conclusion
The current Weiss engine performs significant pre-evaluation steps (e.g., TT probing, repetition checks) to avoid unnecessary calls to EvalPosition(). Within EvalPosition(), it evaluates pawn structure, piece activity, king safety, and threats, all of which could be incorporated into a NNUE model. Specifically:
Bitboards for piece positions, attacks, and pawn structures could serve as direct NNUE inputs.
Features like mobility, king safety, and passed pawns could be replaced by NNUE's learned representations, simplifying the code while potentially improving accuracy.
User
When are SEE/Noisy other check performed and how do they work
Assistant
Static Exchange Evaluation (SEE) and Noisy Move Checks in Weiss
In the Weiss chess engine, SEE (Static Exchange Evaluation) and Noisy Move Checks are used to improve move ordering and pruning decisions during the search, particularly in quiescence search and regular search. Let’s explore when and how these mechanisms are used in the engine.
1. When Are SEE and Noisy Move Checks Performed?
1.1 During Quiescence Search
Quiescence search (Quiescence()) is used to evaluate positions at the leaf nodes of the search tree where no further depth search is performed. It aims to avoid the "horizon effect" by evaluating moves that may significantly change the static evaluation, particularly noisy moves (captures, promotions, and checks).
SEE is used in pruning within quiescence search:
SEE checks whether a capture move is likely to result in a material gain or loss.
Moves with bad SEE values (i.e., negative material outcomes) are pruned early to save computation.
Noisy move checks classify moves into categories handled during quiescence:
Here, the engine skips moves that fail the SEE test unless they improve the current best score.
Noisy move classification:
c
InitNoisyMP(&mp, thread, ss, ttMove);
while ((move = NextMove(&mp))) {
...
if (mp.stage > NOISY_GOOD) break;
}
1.2 During Alpha-Beta Search
During the main alpha-beta search (AlphaBeta()), SEE and noisy move checks are used for move pruning and :
User
Explain which bitboards are precomputed and could be useful for a NNUE with limited capacity.
Assistant
In the Weiss chess engine, several bitboards are precomputed and used to efficiently evaluate positions during search. These precomputed bitboards represent various positional features (e.g., attacks, piece placements, pawn structures), which are calculated once and reused throughout the engine. If you were to integrate a NNUE (Efficiently Updateable Neural Network) with limited capacity, leveraging these precomputed bitboards could help reduce the computational load on the NNUE and simplify input features. Here's a breakdown of which bitboards are precomputed in Weiss and how they could be useful for an NNUE.
1. Precomputed Bitboards in Weiss
1.1 Attack Maps
The engine precomputes attack bitboards for all pieces, which represent the squares attacked by each piece type from a given position.
Pawn Attacks:
PawnBBAttackBB(pawns, color) computes the squares attacked by pawns for a given color.
Useful for detecting pawn threats and evaluating king safety or passed pawns.
Piece Attacks:
AttackBB(pieceType, square, occupiedSquares) computes the attack bitboard for any piece type at a specific square, taking into account occupied squares.
XRayAttackBB(pos, color, pieceType, square) computes attacks considering x-ray vision (e.g., rooks/bishops looking "through" their own pieces).
These maps could feed directly into an NNUE as compact representations of threats and piece activity.
1.2 Mobility Bitboards
Mobility Area:
The EvalInfo struct includes mobilityArea[color], which excludes squares that are:
Attacked by enemy pawns.
Occupied by friendly pawns on their starting squares or blocked from advancing.
Precomputing mobility areas reduces the need to dynamically calculate legal moves during evaluation.
For NNUE: Mobility areas can be used to evaluate piece freedom and influence.
1.3 King Safety Bitboards
KingZone:
kingZone[color] is a precomputed bitboard that includes all squares near the king (e.g., the 8 squares adjacent to the king).
Used to evaluate king safety by checking how many enemy pieces attack the king's zone.
User
Where and when are these called?
Assistant
The precomputed bitboards in Weiss are calculated and used throughout the evaluation and search process. They are designed to optimize runtime performance by avoiding redundant calculations during iterative deepening, alpha-beta pruning, and quiescence search. Here's a detailed explanation of where and when these bitboards are computed and used:
1. Where Are the Bitboards Computed?
1.1 Attack Maps
Pawn Attacks (PawnBBAttackBB):
Computed dynamically as needed in functions like EvalPawns() (in evaluate.c) and during king safety evaluation (EvalKings()).
In Weiss, precomputed bitboards are primarily used within the EvalPosition() function and its subfunctions (e.g., EvalPawns(), EvalPiece(), EvalKings()). However, some bitboards are also called or computed outside of the evaluation function during move generation, search, and other features like pruning and ordering. Below, I outline which bitboards are used outside the evaluation function and their specific roles.
Bitboards Called Outside the Eval Function
1. Attack Maps
Attack maps are heavily used outside the evaluation function for move generation, quiescence search, and pruning decisions.
Where Used:
Search Functions:
AlphaBeta(): Attack maps are used for SEE (Static Exchange Evaluation) and pruning decisions.
Quiescence(): Attack maps are used to classify and evaluate noisy moves (captures, promotions, and checks).
Move Generation (MovePicker):
Attack maps determine legal moves and classify them into captures, quiet moves, and checks.
King Safety:
Attack maps are used to check if the king is under attack (e.g., KingAttacked()).
Key Code Examples:
King Attack Check:
c
if (KingAttacked(pos, sideToMove^1))
return TakeMove(pos), false;
KingAttacked() uses attack bitboards to see if the king is under threat after a move.
Move Generation:
c
InitNormalMP(&mp, thread, ss, depth, ttMove, ss->killer);
while ((move = NextMove(&mp))) {
if (!MakeMove(pos, move)) continue;
}
Each move is checked for legality using attack maps to ensure the king is not left in check.
User
Always specify which file you are quoting.
Assistant
Got it! I’ll always specify the file being referenced in the context of the Weiss chess engine. Let’s revisit the question and clarify where and when bitboards are called outside EvalPosition(), specifying the corresponding files.
Bitboards Used Outside EvalPosition()
The Weiss engine uses several precomputed or dynamically computed bitboards outside the EvalPosition() function, primarily for move generation, pruning, and king safety checks. Below is a detailed breakdown, specifying the files where these bitboards are computed and used.
1. Attack Maps
Where Computed:
AttackBB() and PawnBBAttackBB() (File: bitboard.h and bitboard.c):
These functions compute attack maps dynamically for all piece types and pawns.
Where Used Outside EvalPosition():
Move Legality Checks:
File: makemove.c
Function: KingAttacked()
Attack maps are used to check if the king is under attack after a move is made. This ensures moves that leave the king in check are rejected.
c
if (KingAttacked(pos, sideToMove^1))
return TakeMove(pos), false;
Search Functions:
File: search.c
Functions: AlphaBeta(), Quiescence()
Attack maps are used to evaluate positions and prune moves during search. For example, in Quiescence(), attack maps prioritize noisy moves (captures, checks, and promotions).
c
if (!MakeMove(pos, move)) continue;
int score = -Quiescence(thread, ss+1, -beta, -alpha);
Move Generation:
File: movepicker.c
ordering
SEE is used to evaluate whether a move is worth searching further based on its static material outcome.
Noisy moves (captures, promotions, or checks) are prioritized in the move ordering process to improve the likelihood of encountering a beta cutoff early.
InitNormalMP(&mp, thread, ss, depth, ttMove, ss->killer);
while ((move = NextMove(&mp))) {
if (mp.stage > NOISY_GOOD) break;
}
1.3 During ProbCut
ProbCut is a pruning technique used to skip deeper searches when a move with high material gain is unlikely to affect the final evaluation. SEE and noisy move checks help identify such moves quickly.
Relevant Code Snippet:
c
if (SEE(pos, move, 1) < probCutBeta)
continue;
2. How Do SEE and Noisy Move Checks Work?
2.1 Static Exchange Evaluation (SEE)
SEE is a fast, heuristic method to evaluate the static material consequences of a capture sequence on a specific square. It examines the exchange of pieces on a square without considering the tactical nuances of the position (e.g., pins, skewers).
How SEE Works
Identify Attackers and Defenders:
The engine identifies all pieces that can attack and defend the target square using precomputed attack bitboards.
Sort by Value:
Attackers and defenders are sorted by piece value (pawn, knight, bishop, rook, queen, king), with the least valuable attackers capturing first.
Simulate the Exchange:
The engine simulates the sequence of captures on the square:
The attacking side moves first, capturing the piece currently on the square.
The defending side recaptures, if possible, using the least valuable defending piece.
The process alternates until no more captures are possible.
Calculate the Net Material Gain/Loss:
The engine computes the resulting material difference after the simulated exchange.
If the material loss exceeds a threshold (e.g., zero or the current alpha value), the move may be pruned.
SEE in Weiss
SEE is implemented in the SEE() function, with parameters:
pos: The current position.
move: The move being evaluated.
threshold: A minimum material gain required for the move to be considered.
The function checks whether the move is worth evaluating further by determining if the material gain/loss exceeds the threshold. If not, the move is pruned.
Benefits of SEE:
SEE avoids searching clearly bad captures or trades.
It improves move ordering by prioritizing moves that are likely to lead to a material advantage.
2.2 Noisy Move Checks
Noisy moves are defined as moves that can significantly alter the material balance or king safety in a position. These include:
Captures: Moves that take opponent pieces.
Promotions: Pawn moves that result in promotion to a queen, rook, bishop, or knight.
Checks: Moves that place the opponent’s king in check.
How Noisy Move Checks Work
Moves are classified into "stages" by their noisiness using the move picker (e.g., MovePicker class in the engine).
Noisy moves are prioritized in the move ordering process to increase the chances of beta cutoffs early in the search tree.
In Weiss, noisy moves are handled through:
MovePicker Stages:
c
InitNoisyMP(&mp, thread, ss, ttMove);
while ((move = NextMove(&mp))) {
if (mp.stage > NOISY_GOOD) break;
}
Here, the move picker prioritizes noisy moves first (e.g., good captures, promotions) and skips non-noisy moves unless needed.
SEE Filtering:
Noisy moves are further filtered using SEE to remove bad exchanges:
c
if (!SEE(pos, move, 1)) continue;
3. Summary
SEE is used to evaluate the static material consequences of moves, particularly captures, by simulating exchanges on a square. It helps prune bad moves and prioritize good ones.
Noisy Move Checks classify and prioritize moves that can significantly alter the position (captures, promotions, and checks). These moves are evaluated earlier in the search tree to improve efficiency and accuracy.
When Used:
Quiescence Search: SEE is used to decide whether to include captures in the search.
Alpha-Beta Search: SEE and noisy checks are used for move pruning and ordering.
ProbCut: SEE is used to skip moves unlikely to affect the evaluation.
How They Work:
SEE simulates captures and calculates the net material gain/loss.
Noisy moves are prioritized, and bad noisy moves are pruned with SEE.
These optimizations ensure the engine avoids wasting time on unpromising moves, making it faster and more efficient.
For NNUE: King zones combined with attack maps could simplify king safety evaluation by indicating threats near the king.
1.4 Pawn Structure Bitboards
Passed, Isolated, and Doubled Pawns:
Passed pawn detection uses bitboards like PassedMask[color][square], which represent the squares in front of a pawn that need to be clear for the pawn to be considered passed.
Isolated pawns are detected using IsolatedMask[square], which represents squares adjacent to a pawn’s file.
Doubled pawns are evaluated using bitboards like ShiftBB(pawns, NORTH) and ShiftBB(pawns, 2 * NORTH) to check if pawns are stacked on the same file.
For NNUE: These bitboards can directly encode pawn structures into the network, avoiding redundant computation.
1.5 Blocker and Distance Bitboards
Blocked Pawns:
The engine computes bitboards to detect pawns blocked by other pieces, using operations like ShiftBB(pieceBB(ALL), direction).
For NNUE: Blocking information could be crucial for passed pawn evaluation.
Distance to Promotion:
Distance-to-promotion bitboards are used for evaluating passed pawns and endgames, particularly in EvalPassedPawns().
For NNUE: These bitboards can encode the relative progress of pawns toward promotion.
1.6 File and Rank Bitboards
Predefined bitboards represent specific files and ranks:
RankBB[RANK_X] and FileBB[FILE_X] are used to represent specific ranks and files.
For NNUE: These bitboards simplify the encoding of positional features like rooks on open files or pawns on specific ranks.
1.7 Bitboards for Specific Features
Open and Semi-Open Files:
Used to evaluate rook positions. Open files are detected by checking if there are no pawns on a file (~Fill(pawns, direction)).
For NNUE: This feature could encode rook activity on open/semi-open files.
Central Squares:
Central squares are often hardcoded as a bitboard for quick access (e.g., fileCBB | fileDBB | fileEBB | fileFBB).
For NNUE: Central square occupation is a critical feature for piece activity and control.
Color-Specific Squares:
BlackSquaresBB and its complement are used to evaluate bishop activity and pawn weaknesses on specific color complexes.
For NNUE: This feature helps encode color-complex weaknesses and bishop activity.
2. Useful Precomputed Bitboards for NNUE
For an NNUE with limited capacity, the following precomputed bitboards would be most useful:
Encode squares available for piece movement, which is useful for evaluating positional activity.
Precomputed mobility reduces the burden on NNUE to infer this information.
2.6 Endgame Features
Distance-to-promotion bitboards:
Encodes progress of pawns toward promotion in endgames.
This helps NNUE focus on critical features without needing to compute distances dynamically.
2.7 File and Rank Features
File and rank bitboards:
Useful for encoding open files, semi-open files, and pawn ranks.
2.8 Color Complexes
[Redacted Person]:
Provides direct encoding of weaknesses on dark/light squares.
3. Benefits of Using Precomputed Bitboards in NNUE
Reduced NNUE Complexity:
Precomputing bitboards for common features like attacks, pawn structures, and king safety reduces the burden on the NNUE, allowing it to focus on higher-level position evaluation.
Improved Efficiency:
Bitboards are compact representations that NNUE can directly process as inputs, avoiding redundant computations.
Simplified Training:
Using precomputed features (e.g., passed pawn masks) ensures the NNUE doesn't need to "learn" basic chess rules, freeing up capacity for strategic evaluation.
Smaller NNUE Model:
With precomputed bitboards, the NNUE model can be smaller and faster, as many basic features are already provided.
4. Example NNUE Input Design Using Bitboards
An NNUE model could use a feature vector like:
Piece-bitboards: One per piece type and color (12 bitboards total for pawns, knights, bishops, rooks, queens, kings).
Attack maps: Combined attack maps for all pieces of each color (2 bitboards).
Pawn structure:
Passed pawns: 2 bitboards (one for each color).
Isolated pawns: 2 bitboards.
Doubled pawns: 2 bitboards.
King safety:
KingZone: 2 bitboards.
Control and mobility:
MobilityArea: 2 bitboards.
Endgame-specific features:
Distance-to-promotion for pawns: 1 bitboard.
This totals 25-30 bitboards, a compact and efficient representation for NNUE with limited capacity.
Conclusion
[Redacted Person] precomputes several bitboards for pawn structures, attack maps, mobility, and king safety. These bitboards are excellent candidates for input features in an NNUE, as they encapsulate critical chess concepts compactly and efficiently. By leveraging these precomputed features, an NNUE with limited capacity can focus on high-level strategic evaluation rather than recalculating basic positional features, leading to better performance and efficiency.
Precomputed bitboards (PassedMask) are used within EvalPawns() and EvalPassedPawns() to check for passed pawns.
Example:
c
if (!((PassedMask[color][sq]) & colorPieceBB(!color, PAWN))) {
ei->passedPawns |= BB(sq);
}
Isolated Pawns:
IsolatedMask[sq] is used in EvalPawns() to detect isolated pawns.
Example:
c
if (!(IsolatedMask[sq] & colorPieceBB(color, PAWN))) {
eval += PawnIsolated;
}
These bitboards (FileBB[FILE_X] and RankBB[RANK_X]) are predefined constants, initialized when the engine starts. They are used throughout the evaluation and search functions to evaluate rooks, pawns, and other positional patterns.
2. When Are the Bitboards Computed and Used?
2.1 During Position Initialization
KingZone and Mobility Area are computed in the InitEvalInfo() function, which is called near the beginning of EvalPosition():
In endgames, precomputed bitboards are used to evaluate material imbalances and special rules:
Passed Pawns:
Distance-to-promotion bitboards are used in EvalPassedPawns() to evaluate how far pawns are from queening.
Example:
c
if (pieceOn(forward)) {
eval += PassedBlocked[r];
} else if (!(BB(forward) & ei->attackedBy[!color][ALL])) {
eval += PassedFreeAdv[r];
}
3. High-Level Workflow
Here’s a high-level flow of where and when these bitboards are computed and used during the engine's operation:
3.1 Engine Initialization
Predefined bitboards (FileBB, RankBB, etc.) are initialized as constants at startup.
3.2 Search Process
Move Generation:
Attack maps (AttackBB) are used to generate legal moves and classify them (noisy moves vs. quiet moves).
Alpha-Beta Search:
Mobility and attack maps guide move ordering, pruning, and reduction decisions.
Quiescence Search:
KingZone, attack maps, and pawn-related bitboards help decide which moves to evaluate and which to prune.
3.3 Evaluation (EvalPosition() Call)
Initialize EvalInfo:
Calculate kingZone, mobilityArea, and other positional data.
Pawn Evaluation (EvalPawns()):
Use PassedMask, IsolatedMask, and ShiftBB to evaluate pawn structure.
Piece Evaluation (EvalPiece()):
Use attack maps and mobility bitboards for knights, bishops, rooks, and queens.
King Safety (EvalKings()):
Combine kingZone and attack maps to evaluate threats to the king.
3.4 Endgame Adjustments
Passed pawns and distance-to-promotion bitboards are used to scale evaluations in endgames.
4. Summary
Precomputed bitboards are computed at engine initialization (e.g., FileBB, RankBB) or dynamically during evaluation and search (e.g., kingZone, mobilityArea, PassedMask).
When they are used:
Move generation: Attack maps guide move selection and ordering.
Search: Mobility and attack maps guide pruning and reductions/extensions.
Evaluation: Pawn structure, king safety, and piece activity are evaluated using these bitboards.
Endgame Evaluation: Distance-to-promotion and passed pawns are critical in endgames.
By leveraging precomputed bitboards, the engine avoids redundant calculations and improves performance during both evaluation and search.
SEE Pruning in Quiescence:
c
if (!SEE(pos, move, 1)) continue;
2. Static Exchange Evaluation (SEE)
SEE relies on attack maps to evaluate the material gain/loss from potential captures. It is used outside the evaluation function during:
Quiescence Search:
Helps decide whether a capture move is worth exploring further.
Alpha-Beta Search:
Used for pruning moves that result in clear material loss.
Move Ordering:
SEE is used in the MovePicker to prioritize captures that result in a net material gain.
Where Used:
Quiescence(), AlphaBeta(), and MovePicker.
Key Code Examples:
c
if (SEE(pos, move, -60 * depth) < 0)
continue; // Skip moves with bad SEE values
3. King Safety Bitboards
kingZone is precomputed in InitEvalInfo() and used exclusively in EvalKings() for evaluating king safety. However:
Outside of evaluation, attack maps on king squares are frequently used to check if the king is in check or under threat.
For example, Checkers() uses attack bitboards to determine which enemy pieces are attacking the king:
c
pos->checkers = Checkers(pos);
The KingAttacked() function also uses attack maps to validate moves during search.
4. Mobility Area
mobilityArea is computed in InitEvalInfo() and used in EvalPieces() to evaluate piece mobility.
Outside of evaluation, mobility is indirectly assessed through:
Move Generation:
Mobility is implicitly considered when generating legal moves using attack maps and occupancy bitboards.
Move Ordering:
Moves that increase mobility (e.g., centralizing pieces) may be prioritized.
5. Pawn Structure Bitboards
Pawn-related bitboards, while primarily used in EvalPawns() and EvalPassedPawns(), are also relevant outside evaluation for:
Move Generation:
Passed pawns and their promotion potential are critical for generating promotion moves.
For example, in MakeMove():
c
if (pieceTypeOn(to) == PAWN) {
if (moveIsPStart(move)) {
// Set en passant square
} else if (moveIsEnPas(move)) {
// Handle en passant capture
} else if (promotion(move)) {
// Replace pawn with promoted piece
}
}
Search and Pruning:
Passed pawn masks (PassedMask) and distance-to-promotion bitboards are used during endgame pruning.
- Quiescence pruning- Alpha-beta pruning- Move ordering in MovePicker
Summary
While most precomputed bitboards are used within EvalPosition() to calculate evaluation scores, several are called outside the eval function to support move generation, pruning, and ordering during the search process. Specifically:
Attack maps (piece and pawn attacks) are widely used for move legality checks, SEE pruning, and king safety validation.
Pawn structure bitboards (passed, isolated, doubled pawns) are used during move generation (e.g., promotions) and endgame pruning.
File and rank bitboards support sliding piece move generation and rook/queen evaluation.
SEE relies on attack maps and is used in both pruning and move ordering.
These bitboards allow Weiss to perform efficient search and move generation without recalculating key positional features repeatedly, making them vital outside the evaluation function.
Function: NextMove()
Attack maps are used to classify moves into noisy moves (captures, promotions, checks) and quiet moves. This is critical for efficient move ordering.
c
InitNoisyMP(&mp, thread, ss, ttMove);
while ((move = NextMove(&mp))) {
if (mp.stage > NOISY_GOOD) break;
}
Static Exchange Evaluation (SEE):
File: search.c
Function: SEE()
Attack maps are used to evaluate the material consequences of captures during SEE.
c
if (!SEE(pos, move, 1)) continue;
2. King Safety Bitboards
Where Computed:
kingZone:
Precomputed in InitEvalInfo() (File: evaluate.c).
King zones represent the squares immediately surrounding the king. These are used for evaluating king safety.
Where Used Outside EvalPosition():
Move Legality Checks:
File: makemove.c
Function: KingAttacked()
While kingZone itself is not directly used, king safety is checked dynamically using attack maps on the king’s square.
c
if (KingAttacked(pos, sideToMove^1))
return TakeMove(pos), false;
Detecting Checkers:
File: makemove.c
Function: MakeMove()
The engine uses attack maps to track which enemy pieces are attacking the king.
c
pos->checkers = Checkers(pos);
3. Pawn Structure Bitboards
Where Computed:
PassedMask and IsolatedMask:
Precomputed for each square and color (File: evaluate.c).
These bitboards are used to evaluate passed pawns, isolated pawns, and doubled pawns.
Where Used Outside EvalPosition():
Move Generation:
File: makemove.c
Function: MakeMove()
Passed pawn masks and promotion rules are used to handle pawn moves, including promotions and en passant captures.
c
if (pieceTypeOn(to) == PAWN) {
if (promotion(move)) {
ClearPiece(pos, to, true);
AddPiece(pos, to, promo, true);
}
}
Endgame Pruning and Search:
File: search.c
Function: AlphaBeta()
Passed pawn masks are used in endgame-specific pruning to evaluate whether a passed pawn can promote without interference.
Several bitboards, including attack maps, pawn structure masks, SEE, and file/rank bitboards, are called outside EvalPosition() in critical parts of the engine, such as move generation, search pruning, and king safety checks. These bitboards are primarily used in files like search.c, makemove.c, and movepicker.c. By precomputing or dynamically generating these bitboards, Weiss ensures efficient and accurate handling of moves and positions across the search tree