Skip to content

4PC Teams: king safety, endgame activity, mate threats, pins/X-rays and castling rights - #55

Open
KnightStackSys wants to merge 18 commits into
mainfrom
feature/king-evaluation
Open

KnightStackSys wants to merge 18 commits into
mainfrom
feature/king-evaluation

Conversation

@KnightStackSys

@KnightStackSys KnightStackSys commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

King evaluation

  • Add phase-tapered middlegame pawn shield, enemy pawn storm, and king-zone attack penalties for both allied kings vs both enemy armies
  • Endgame king centralization and pawnless-wing penalties, respecting all four seat orientations
  • Static mate-at-a-glance pressure proxy when a king is already attacked and has severely restricted safe escapes; intentionally never claims a proven mate or alters terminal search scoring
  • Slider-based absolute pin and queen X-ray scoring across valid 14x14 rays
  • Castling-rights reward only when live bit, configured lane, king and rook all agree
  • Nine tunable EvalKing* options; retain all established search/eval weights, with NNUE pathway unchanged
  • Dedicated 4PC king evaluation test and docs

Validation

CI Linux GCC and Windows MSVC, existing regression tests and new 4PC feature tests; then tune weights and conduct paired SPRT before merging. This branch is intentionally not merged into main.

Search and HCE performance improvements

  • Cache immutable king-square pawn-shield, three-square-radius storm, king-center-distance, and wing geometry masks (built once after geometry initialization)
  • Accumulate per-team material phases, pawns, and slider bitboards once per evaluation, not separately for each king
  • Detect candidate pin/X-ray screens using fast current-occupancy slider lookups and reuse slider attacks generated during mobility scoring, avoiding unnecessary ray walks
  • Add conservative fast givesCheck() prefilters to PV move ordering (PV move ordering), checking discovered checks and pre-existing attacks before skipping a full simulation
  • Add tunable SearchFastCheckPrefilter (default 1, 0 restores original slow check detection); equivalence regression checks ordered moves, gives-check metadata and depth-3 bestmove/score
  • Expand ironphoenix_nps_bench with same-runner diagnostic measurements of each king feature group and fast-check on/off

Benchmark interpretation: CI runners vary in CPU, so comparisons across different runs cannot establish a precise gain. The same-runner benchmarks enable more meaningful relative comparisons. Retain/merge based on CI correctness plus independent local throughput and strength SPRT. Changes remain exclusive to this feature branch; main is untouched.

  • Optional IRONPHOENIX_NATIVE_CPU=ON Release configuration: GCC/Clang -march=native, MSVC /arch:AVX2 (nonportable; default remains OFF). See docs/performance.md for Windows/Linux build instructions.
  • The broader non-PV check shortcut was explicitly reverted after same-runner benchmarking showed no meaningful improvement.

Further throughput work (latest commits)

  • 16K-entry per-search-worker exact full-evaluation cache with new-search epoch invalidation; SearchEvalCache default 1, off at 0, benchmarked on/off.
  • Single-thread TT probe/store now bypasses mutex object construction; striped locks retained for multi-thread Lazy SMP.
  • Conservative geometry-aware king legality shortcut in negamax and qsearch: skip self-check recomputation only when an already-safe king cannot be exposed by vacating a non-collinear square. Keeps king moves, EP, castling, check evasions and aligned moves fully verified. SearchFastKingLegality default 1, off at 0.
  • New regression tests verify cached score exactness/epoch invalidation and skipped check safety on generated 4PC positions, plus depth-3 bestmove/score equivalence.
  • Expanded same-runner benchmark diagnostics: experimental comparison SearchEvalCache 598,037 off vs 612,344 on NPS; SearchFastKingLegality 856,053 off vs 861,818 on NPS (different CI runs; individual on/off pairs are same-runner only). See docs/performance.md.

Do not merge on NPS alone; measure your own Release executable at Threads=1 with long repeated benches, then verify paired Elo. main remains unchanged.

New HCE performance experiments (October 23)

  • Per-worker pawn attack union cache: SearchPawnAttackCache 0/1 (default 1), bitboard-exact output, tested on changing pawn structures and legal 4-player positions. On one Linux CI runner: 510,898 NPS disabled vs 524,508 enabled (+2.7%).
  • Geometric king ray prefilter: SearchKingRayPrefilter 0/1 (default 1). Precomputed rank/file/diagonal rays skip impossible king pins and queen X-ray probes without changing scores. On one Linux CI runner: 509,880 NPS disabled vs 537,731 enabled (+5.5%). Added four-color and X-ray score-equivalence cases.
  • Reverted experimental non-PV lazy qsearch picking: 512,945 NPS versus 516,048 NPS with full sorting on the same CI runner.
  • Documented optional whole-program CMake IPO build for further user-machine experiments. main remains untouched.

These are independent single-runner diagnostics, not additive gains or guaranteed local throughput; verify Release build median NPS and paired Elo.

…astling rights

Introduce phase-tapered king evaluation for Red/Yellow and Blue/Green; oriented shield/wing safety, hostile attack zones and mate-threat pattern penalties, true slider-ray pins and X-rays, and validated castling-right bonuses. Add nine UCI-tunable evaluation parameters and dedicated regression tests.
…red phase

Replace per-king per-pawn scans and directional empty-square walks with immutable shield/storm/wing masks and slider lookup rays. Accumulate material phases/armies once per position, reuse occupancy and attack maps; keep all nine tunable king heuristics and their scale.
Benchmark pinned slider pressure, pawn-zone safety, king-zone danger and all king heuristics disabled against the tuned combination. Restore evaluation parameters afterward.
…ay rays

Build slider-only team attacks alongside existing mobility maps and intersect candidate screens with these attacks. Avoid expensive directional x-ray probes when no opposing slider actually attacks friendly screening material; preserve all king-evaluation terms and existing tunables.
…uiet moves

Keep check move ordering identical using conservative source/destination collinearity tests and one per-node existing-check query. Add SearchFastCheckPrefilter (default on) for A/B testing, strict ordering/metadata regression across real successor states, and same-runner NPS comparison.
Avoid full simulated-check queries for geometrically impossible quiet moves during pruning, preserving pre-existing opponent checks with a cached per-node test. Add fixed-depth score/bestmove equivalence coverage against the original ordering path.
…mark

The hot-loop extension brought no measurable NPS improvement (831k vs 834k with it off) and added extra per-node attack checks. Keep the verified PV move-ordering shortcut and all faster king-evaluation features.
Add opt-in -march=native GCC/Clang or MSVC /arch:AVX2 for Release, including header-inline bitboard paths. Keep portable CI defaults and document reproducible same-machine HCE/king feature throughput tests.
…idation

Cache full HCE scores for repeated Zobrist positions using private 16K-entry direct-mapped tables, invalidate each new search/variant, expose SearchEvalCache (default 1) and compare on/off with fixed-position same-runner NPS diagnostics.
Inline the unlocked cluster operation and acquire striped mutexes only for concurrent SMP, preserving synchronization. Cache replacement priority inside TT store to avoid repeat scoring.
…ation

Exercise cache hits, disabled mode, side-to-move Zobrist keys and stale score avoidance when tuning weights change between searches.
Use 4PC rank/file/diagonal alignment to verify only moves that could uncover an enemy slider attack on a previously safe king; retain full tests for checks, king moves, en passant and castling. Apply in negamax and qsearch, add SearchFastKingLegality A/B option, property-style legality and depth-three score tests, and same-runner NPS diagnostic.
…izations

Document A/B UCI switches, correctness boundaries and single-runner diagnostic comparisons, with explicit caution about CI variance and Elo.
Use small thread-local per-color pawn-structure cache to avoid rescanning pawns during HCE. Add SearchPawnAttackCache UCI A/B switch, score-equivalence tests across changing pawn structures and four-player move sequences, and same-runner NPS diagnostics.
Avoid full capture sorting before potential beta cutoffs when tactical lists are long. Keep PV and check-evasion ordering unchanged; add SearchQSearchLazyOrdering A/B switch, QSearch score equivalence tests, and diagnostic throughput comparison.
Full tactical sorting scored 516,048 NPS against lazy picking 512,945 NPS in the fixed fixture; keep verified thread-local pawn-attack cache instead.
…king-alignment masks

Before expensive occupancy-dependent king/queen slider probes, reject directions without any geometrically aligned opponent slider. Preserve exact scores with SearchKingRayPrefilter on/off tests and same-runner throughput comparisons.
Test four moving-color perspectives and screened queen X-rays; document A/B UCI options, diagnostic 2.7% pawn cache and 5.5% ray-mask gains, reverted QSearch sorting trial and optional MSVC IPO experiment.

This branch has not been deployed

No deployments
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