Repository navigation
Move lists in inplace vectors and range-based move picking - #66
Merged
Merged
Conversation
Move generation wrote through PseudoLegalMove*& cursors into caller-owned std::array buffers, and legal moves came back in a heap-allocated std::vector. Add InplaceVector<T, N>, a fixed-capacity vector with the subset of the std::inplace_vector interface the engine needs. std::inplace_vector itself needs libstdc++ 16, and GCC 16 currently builds this engine slower. GeneratePseudoLegalMoves and GenerateLegalMoves return PseudoLegalMoves and LegalMoves by value, the helpers append with unchecked_push_back, the en passant filter is erase_if, and callers use range-for, std::ranges::contains and views::concat instead of pointer loops. GenerateMoves duplicated GenerateLegalMoves and is gone. The principal variation gets its own type bounded by the deepest depth, so move generation and PV extraction no longer allocate. Search is unchanged: identical nodes and best moves on 30 positions, perft startpos d5 4865609 and kiwipete d4 4085603. The push loops keep the size in a register and store it once, and the returned lists are built in place without copies. Instructions per node +0.04% (11708-11719 vs 11714-11721), cycles within noise. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PartialInsertionSort took raw begin/end pointers and a limit that was always INT64_MIN, so the partial part never applied. It becomes SortByScore over a ScoredRange, a std::ranges::subrange of the scored move array, written with iterators and std::prev. The killer lookup in bad captures uses std::ranges::find with a &ScoredMove::move projection instead of find_if over data() pointers. The range is a subrange of std::array iterators rather than a std::span: GCC 15 keeps an extra pointer copy per shifted element in loops over span iterators, while array iterators compile to the same 7-instruction inner loop as before. Search is unchanged (identical nodes and best moves on 30 positions); instructions per node 11712-11716 vs 11710-11713, cycles per node 13468-13524 vs 13590-13602. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bench: 696698
Bench: 696698 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the Stockfish-style move list plumbing with standard-library idioms, with no change in search or speed.
Move generation (
d34eecb)InplaceVector<T, N>(Chess/InplaceVector.h): a fixed-capacity vector with the subset of thestd::inplace_vectorinterface the engine uses.std::inplace_vectoritself needs libstdc++ 16, and GCC 16 currently builds this engine about 10% slower (under investigation).GeneratePseudoLegalMoves/GenerateLegalMovesreturnPseudoLegalMoves/LegalMovesby value instead of writing throughPseudoLegalMove*&cursors into caller-owned arrays.unchecked_push_back.erase_if.std::ranges::containsandviews::concatinstead of pointer loops.GenerateMovesis gone.Move picker (
1fc4ead)PartialInsertionSort(begin, end, INT64_MIN)becomesSortByScore(ScoredRange), an iterator-based insertion sort.std::ranges::findwith a&ScoredMove::moveprojection.ScoredRangeis asubrangeofstd::arrayiterators rather than astd::span: GCC 15 adds one instruction per shifted element in loops over span iterators.Verification (GCC 15, gate build with
-flto-partition=one, CPU 19, three alternating runs each)Identical nodes and best moves on 30 positions (7,274,560 nodes).
Perft: startpos d5 = 4,865,609; kiwipete d4 = 4,085,603.
Instructions per node:
d34eecb1fc4eadCycles within noise;
1fc4eadshows 0.8% fewer.Machine code:
Tests: 206/206 pass in Release.
Stacked on #63.
🤖 Generated with Claude Code