Skip to content

Initialization order fix#62

Closed
winapiadmin wants to merge 19 commits into
mainfrom
initialization_order_fix
Closed

Initialization order fix#62
winapiadmin wants to merge 19 commits into
mainfrom
initialization_order_fix

Conversation

@winapiadmin
Copy link
Copy Markdown
Owner

No description provided.

…isable base nodes limit for debug mode, rank/file offsets
Reduce the number of elements taken from bucket3 from 5 to 1.
Reduce the limits for bucket2 and bucket3 sizes in optimization.
Replaced random device initialization with a fixed seed for reproducibility in tests.
yeah... the logs showed that the attacks testcase took the longest:(
downgrading requirements somehow.... yeah it always fails due to TLE
Add assertions to Rank and File operator overloads for Direction.
Adjust the size limit for bucket2 based on platform to improve performance on Windows runners.
Refactor size determination for bucket2 and bucket3 based on platform.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 39bb80b6-e733-4883-9814-41b20a0fc403

📥 Commits

Reviewing files that changed from the base of the PR and between 7f09846 and 59c3fac.

📒 Files selected for processing (15)
  • .github/workflows/clang-format.yml
  • .github/workflows/test.yml
  • attacks.cpp
  • attacks.h
  • chess960_tests.cpp
  • movegen.cpp
  • movegen.h
  • moves_io.cpp
  • moves_io.h
  • non_core_tests.cpp
  • position.cpp
  • position.h
  • printers.cpp
  • tests.cpp
  • types.h
🔥 Files not summarized due to errors (1)
  • chess960_tests.cpp: Server error: no LLM provider could handle the message

📝 Walkthrough

Summary by CodeRabbit

  • Chores

    • Consolidated code formatting checks into the main test workflow for improved CI/CD efficiency.
    • Updated internal APIs for better consistency and maintainability across the codebase.
  • Refactor

    • Optimized move generation and position state handling for improved performance.
    • Streamlined position update and query logic for cleaner internal architecture.

Walkthrough

This PR refactors the chesslib engine's core Position API from camelCase to snake_case naming, introduces explicit repetition-hash tracking, restructures castling metadata storage, modernizes attack generation to support runtime compilation, and updates all dependent code to use the new APIs.

Changes

Core Engine API & State Architecture

Layer / File(s) Summary
CI Workflow Consolidation
.github/workflows/test.yml, .github/workflows/clang-format.yml
Clang-format checking is removed from its standalone workflow and integrated as a prerequisite format job in test.yml, ensuring formatting runs before build/test steps.
Attack Generation Modernization
attacks.cpp, attacks.h, movegen.h
_POSSIBLY_CONSTEXPR macro now expands to constexpr when runtime generation is disabled, or to empty when enabled; SQUARES_BETWEEN_BB shrinks from 65×65 to 64×64 fixed dimensions; bishop/rook functions gain [[nodiscard]] and become inline instead of constexpr definitions; queen/slider templates convert from constexpr to inline with extern magic-table declarations removed from headers.
Position State Architecture
position.h
Restructures state storage: adds rep_hashes_ vector for explicit repetition tracking, introduces CastlingMeta struct to replace per-history castling metadata, extends HistoryEntry with cached pin/check masks (saved_rook_pin, saved_bishop_pin, saved_checkers, saved_check_mask) for faster undo, updates copy-constructor to initialize/copy new members.
Move Execution & Undo Logic
position.cpp, position.h
doMove now computes is_capt flag, saves cached pin/check/checkers state to HistoryEntry, and updates halfmove clock based on capture flag; introduces ep_pawn_masks constexpr lookup table for efficient en-passant validation; undo_move restores cached state and pops rep_hashes_ without calling refresh_attacks(); do_null_move pushes current hash into rep_hashes_.
FEN Parsing & Castling Setup
position.cpp
setFEN clears/repopulates rep_hashes_, refactors Chess960 castling rook discovery into lambdas, stores castling metadata in castling_meta_ struct, uses ep_pawn_masks for en-passant inclusion testing, and appends initial hash to repetition tracking; castling-path precomputation derives from castling_meta_ instead of per-history state.
Position Queries & Snake_case Public API
position.h
Adds hash(), side_to_move(), ep_square(), king_sq(Color) accessors and snake_case wrappers (is_capture, is_attacked, is_zeroing, fullmove_number, rule50_count, gives_check, is_half_move_draw); introduces move/null-move snake_case entry points do_move, undo_move, do_null_move that delegate to camelCase implementations; updates constructor to reserve rep_hashes_ capacity.
FEN Serialization & Check Detection
position.cpp
fen() generates castling strings from castling_meta_ and prints rule50/fullmove via accessors; is_valid() refactored to use side_to_move()/king_sq() naming; givesCheck() updated with consistent snake_case queries and pinMasks() calls; refresh_attacks() refactored to compute pin/check state using new naming; zobrist() EP hashing uses side_to_move() and file-based Zobrist keys; _valid_ep_square() uses ep_pawn_masks and side_to_move() for validation.
Move Generation Integration
movegen.cpp, movegen.h
En-passant, king, and sliding move generation updated: kingSq(c)king_sq(c), getCastlingPath/getCastlingMetadataget_castling_path/get_castling_metadata(...).rook_start_{ks,qs}, precomputed occ_all/occ_opp bitboards for occupancy reuse.
Move I/O & SAN Parsing
moves_io.cpp, moves_io.h
uciToMove uses pos.side_to_move() and pos.ep_square(); parseSan castling shortcuts fetch squares via pos.king_sq() and pos.get_castling_metadata(...).rook_start_{ks,qs}; moveToSan position updates use p.do_move(move); new snake_case templates parse_san() and move_to_san() in chess::uci namespace delegate to existing camelCase functions; types.h include added to moves_io.h.
Type System Updates
types.h
Rank and File gain arithmetic operator overloads (+, -, +=, -=) for combining with Direction (constrained to EAST/WEST/DIR_NONE by assertions); Move::promotion_type() implementation simplified; deprecated alias methods typeOf() and promotionType() removed in favor of type_of() and promotion_type().
Comprehensive Test Migration
non_core_tests.cpp
All test call sites updated: FEN setup (setFENset_fen), move application (doMovedo_move), and SAN conversions (uci::moveToSan/uci::parseSanuci::move_to_san/uci::parse_san) across FEN reconstruction, repetition checking, castling, ambiguous move handling, and strict/lenient SAN parsing test suites.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

  • winapiadmin/chesslib#59: Addresses overlapping refactoring of position state management (doMove/undo_move logic, castling metadata handling, and is_insufficient_material signature).

Possibly related PRs

  • winapiadmin/chesslib#55: Shares the null-move and move-undo mechanics refactoring, especially do_null_move/undo_move state consistency and repetition-hash tracking.
  • winapiadmin/chesslib#58: Implements the same attack-generation API/linkage changes—_POSSIBLY_CONSTEXPR macro behavior, removal of extern magic-table declarations, and constexpr-to-inline function conversions.

Poem

🐰 A rabbit hops through castling's ancient gates,
With hashes stacked in vectors, fate awaits,
Old camelCase now bows to snake_case grace,
While magic tables run at runtime's pace,
No more constexpr chains—just inline flight,
The chessboard blooms in refactored light.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch initialization_order_fix
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch initialization_order_fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@winapiadmin winapiadmin deleted the initialization_order_fix branch May 24, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant