Conversation
Make Bag(Vec<u8>) field private. Add methods: return_tiles, return_tile, set_from_iter, as_slice, len, is_empty, swap_remove_tile. Replace all external bag.0 accesses across 8 files. No behavior change. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rewrite Bag as a struct with a front cursor (fc) so tiles can be drawn from either end without allocation. Add went_first field to GameState and reset_and_draw_tiles_double_ended for the new drawing path. Existing reset_and_draw_tiles uses replenish_back only (no behavior change for main_endgame). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Removes the m<=16 assumption. When fc >= 2m, scratch lives in dead space with zero allocation. When fc < 2m, scratch is appended to the vec's back (within existing capacity in practice). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
return_tiles,return_tile,set_from_iter,as_slice,len,is_empty,remove_tile)fc) withtiles[0..fc]as dead space. Optimizedput_backwith special cases for m=1 (1 random call), m=2 (2 random calls, swap doubles as coin flip), and general m>=3 (interleave with early break). Order-preservingremove_tile.put_backusesself.tilesas scratch buffer instead of fixed[0u8; 16], removing the m<=16 assumption. When fc >= 2m, scratch lives in dead space (zero allocation). Otherwise, scratch is appended to the vec's back.Why
Prepares infrastructure for game pairs (playing each seed twice with different initial players).
Notes
main_endgame.rsunchanged — still usesreset_and_draw_tiles(back-only)reset_and_draw_tiles_double_endedunsafeexcept in the general (m>=3)put_backloop, with safety proof in comments🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com