Skip to content

Code-quality pass: deduplicate move-making/primitives and tighten lints - #324

Merged
kirillbobyrev merged 2 commits into
mainfrom
claude/codebase-review-0hfehw
Jul 20, 2026
Merged

Code-quality pass: deduplicate move-making/primitives and tighten lints#324
kirillbobyrev merged 2 commits into
mainfrom
claude/codebase-review-0hfehw

Conversation

@kirillbobyrev

Copy link
Copy Markdown
Owner

Summary

A quality-focused pass over the chess core and the tooling config. No behaviour changes — purely deduplication, modern idioms, and stricter lints. Verified against the full perft suite (including the shakmaty differential test), the incremental-hash invariant test, the UCI integration tests, and a self-play smoke game.

Refactoring (refactor: commit)

  • make_move: the Zobrist hash-update boilerplate (self.hash ^= generated::get_piece_key(Piece { player, kind }, square)) was repeated ~12 times across four sub-functions, each of which re-scanned the piece bitboards to find the mover. Introduced toggle_piece/move_piece helpers that keep the hash in sync, and determine the moving piece once via Pieces::at, then dispatch. Shorter and does less work per move (the old code ran every move through all four sub-functions).
  • Piece ↔ char: replaced the two 12-arm charPiece matches with a single source of truth, PieceKind::to_char/from_char; Piece now derives Copy/Clone/Eq.
  • Castling generation: encapsulated the static castle geometry in a const Castle table and iterate over it, deleting the 9-argument try_castle helper and its parallel 9-tuple destructure.
  • UCI: the go command now carries a Go parameter struct instead of an 8-field enum variant feeding an 8-argument Engine::go; extracted Engine::limits. Both "too many arguments" clippy smells are gone, and the parser tests shrank via ..Go::default().
  • Completed the Bitboard operator set with toggle + BitXorAssign.

Harness (chore: commit)

You mentioned the lint config hadn't been revisited in a while — I measured the churn of every commented-out lint and turned on the ones that are already clean:

  • rustc lints: enabled unreachable_pub, trivial_numeric_casts, unused_qualifications, unused_import_braces, unused_lifetimes, unused_extern_crates, macro_use_extern_crate, absolute_paths_not_starting_with_crate (all +0 warnings today). Left missing_docs / let_underscore_drop / unused_results deferred with a note — they still fire on undocumented public API and the search stubs.
  • clippy groups: enabled correctness (deny), plus complexity and style (warn), alongside the existing perf/suspicious denies. pedantic (+844), nursery (+26) and cargo stay off — dominated by literal-separator noise and transitive-dependency version reports, not real issues.
  • rustfmt: adopted style_edition = "2024".
  • Fixed the one real style finding this surfaced (match? in the FEN parser).

Testing

  • cargo test: 130 tests + doctests pass.
  • cargo test --release -- --ignored: all 12 expensive perft / shakmaty-differential tests pass (re-run after the castling and make/move refactors).
  • Self-play smoke game (120 plies, incl. castling) over real UCI — no crashes, legal throughout.
  • cargo +nightly fmt --check clean; cargo clippy --all-targets --all-features clean of denied lints.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GVrKvkMe4xDmkRAksacBzk


Generated by Claude Code

claude added 2 commits July 20, 2026 22:47
- make_move: extract toggle_piece/move_piece helpers that keep the
  Zobrist hash in sync, collapsing ~12 repetitions of the manual
  bitboard-mutate-plus-hash-xor pattern. Determine the moving piece
  once via Pieces::at and dispatch, instead of running every move
  through four sub-functions that each re-scan the bitboards.
- Piece: make the algebraic-notation letter the single source of truth
  via PieceKind::to_char/from_char, replacing the two 12-arm
  char<->Piece matches; derive Copy/Clone/Eq for Piece.
- Castling generation: encapsulate the static castle geometry in a
  const Castle table and iterate, removing the 9-argument try_castle
  helper and the parallel 9-tuple destructure.
- UCI: carry a Go parameter struct instead of an 8-field command variant
  and an 8-argument Engine::go; extract Engine::limits. parse_go builds
  the struct with a shared millisecond parser.
- Add Bitboard::toggle and BitXorAssign to complete the operator set.

Behaviour is unchanged: full perft suite (incl. the shakmaty
differential test), the incremental-hash invariant test, and UCI
integration tests all pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVrKvkMe4xDmkRAksacBzk
- Enable the rustc lints that were commented out and already pass clean:
  unreachable_pub, trivial_numeric_casts, unused_qualifications,
  unused_import_braces, unused_lifetimes, unused_extern_crates,
  macro_use_extern_crate and absolute_paths_not_starting_with_crate.
  Keep missing_docs / let_underscore_drop / unused_results deferred with
  a note, since they still fire on undocumented API and the search stubs.
- Enable the core clippy groups: correctness (deny), complexity and style
  (warn), alongside the existing perf/suspicious denies. pedantic, nursery
  and cargo stay off — they are dominated by literal-separator noise and
  transitive-dependency version reports.
- Adopt rustfmt style_edition = "2024".
- Simplify the FEN piece-placement parser with the ? operator (surfaced by
  the newly enabled clippy::style group).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVrKvkMe4xDmkRAksacBzk
@kirillbobyrev
kirillbobyrev marked this pull request as ready for review July 20, 2026 22:57
@kirillbobyrev
kirillbobyrev merged commit c9ab93f into main Jul 20, 2026
13 checks passed
@kirillbobyrev
kirillbobyrev deleted the claude/codebase-review-0hfehw branch July 20, 2026 22:57
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.

2 participants