Before any evaluation occurs in [Redacted Person], the following classical information is available:
-
Piece Placement: The Position struct contains a board array representing the chessboard, where each square holds a Piece representing the occupying piece (or EMPTY). This gives the location of all pieces on the board. Relatedly, the Position struct also maintains several bitboards, including:
pieceBB: Bitboards for each piece type (pawn, knight, bishop, rook, queen) and all pieces combined.
colorBB: Bitboards for each color (white, black). These bitboards allow efficient manipulation and querying of piece locations.
-
Side to Move: The stm member of the Position struct stores the side (WHITE or BLACK) whose turn it is to move.
-
Castling Rights: The castlingRights member indicates which castling moves are still available (WHITE_OO, WHITE_OOO, BLACK_OO, BLACK_OOO, or a combination thereof). Additionally:
CastlePerm: An array storing permitted castling rights for each square.
CastlePath: Bitboards representing the squares traversed during each castling type.
RookSquare: Stores the initial square of the rook involved in each castling type.
-
En Passant Square: The epSquare member stores the en passant target square, if any. Zero otherwise.
-
50-Move Rule Counter: The rule50 member counts the number of moves since the last pawn move or capture.
-
Game Move Counter: The gameMoves member stores the number of moves made in the game so far.
-
History: The gameHistory array stores the history of moves played in the game, along with associated information like the position key, castling rights, and en passant square for each ply.
-
Distance Lookup Table: The SqDistance table provides pre-calculated distances between any two squares, accessible via the Distance function.
-
Zobrist Hash Keys: Several tables store pre-generated Zobrist keys for various position aspects:
PieceKeys: Keys for each piece on each square.
CastleKeys: Keys for each castling rights combination.
SideKey: Key for the side to move. These keys are used to incrementally update the position's hash key (pos->key) after each move. The position also has a materialKey and a pawnKey for specific hashing purposes.
-
Cuckoo Table for Repetition Detection: The cuckoo table and associated cuckooMove table are used for fast detection of threefold repetitions, populated at initialization.
-
Phase Value: The phaseValue and phase members represent the current phase of the game (opening, middlegame, endgame), based on the remaining material. The PhaseValue array stores a value for each piece type used in phase calculation.
-
Piece Type Value & Piece Value: These arrays hold values for each piece type, used in evaluation later. PieceValue is used specifically for futility pruning and is separated by game phase (middlegame / endgame).
-
Checkers: The checkers bitboard represents the pieces currently giving check to the king.
It's important to note that while data structures like attack bitboards are not pre-calculated and stored, the functions to generate them (e.g., AttackBB, PawnBBAttackBB, XRayAttackBB, Attackers, Checkers) are available and utilized during move generation and other operations before the evaluation function (EvalPosition) is called. Evaluation itself uses these functions to calculate attacks and other tactical information as needed.
It's impossible to say precisely how much space would be saved by removing the evaluation portions of the Weiss engine without analyzing its compiled size and determining how much of that size is attributable to the evaluation functions and associated data structures. The provided source code gives a general idea of the components involved in evaluation, but the actual size depends on factors like compiler optimizations, architecture, and data structure packing.
Here's a breakdown of what would be removed and why it's difficult to estimate the size savings:
Components to be Removed:
- Evaluation Functions:
EvalPosition, EvalPawns, EvalPiece, EvalKings, EvalPassedPawns, EvalThreats, InitEvalInfo, ScaleFactor, and related helper functions.
- Evaluation Data Structures:
EvalInfo struct, PhaseValue array, PieceTypeValue array, PieceValue array, and numerous evaluation constants (e.g., PawnDoubled, PawnIsolated, BishopPair, Mobility, etc.) and tables (PawnPassed, PawnPhalanx, etc.).
- Pawn Cache: The pawn hash table (
PawnCache) and associated functions (ProbePawnCache).
- Parts of other modules: Portions of other files relying on evaluation scores, like move ordering in search. This reduction is difficult to quantify.
Challenges in Estimation:
- Code Size vs. Data Size: The size of the code for the evaluation functions is likely small compared to the size of the various lookup tables and constants. The relative proportions are unknown without compilation.
- Compiler Optimizations: Aggressive compiler optimizations could significantly reduce the size of both the code and data sections.
- Interdependencies: Evaluation is intertwined with other engine components (e.g., search, move generation). Removing evaluation requires careful refactoring, potentially affecting the size of remaining code.
General Approach:
The only reliable way to determine the size savings would be to:
- Compile the full engine: Compile Weiss and measure the compressed size.
- Remove evaluation components: Carefully remove all evaluation-related code and data structures.
- Recompile and measure: Compile the modified engine and measure its compressed size.
- Compare sizes: The difference between the two compressed sizes would represent the space saved.
Even with a 50KB compressed size target, without performing the steps outlined above, any estimate would be highly speculative. The savings could range from a few kilobytes to potentially a significant portion of the engine's size, depending on the implementation details and the degree of interdependency with evaluation.