Skip to content

Encapsulate Bag; double-ended drawing#11

Merged
andy-k merged 3 commits intomainfrom
bag-encapsulation
Mar 25, 2026
Merged

Encapsulate Bag; double-ended drawing#11
andy-k merged 3 commits intomainfrom
bag-encapsulation

Conversation

@andy-k
Copy link
Owner

@andy-k andy-k commented Mar 25, 2026

Summary

  • Commit 1: Encapsulate Bag internals — make field private, add semantic methods (return_tiles, return_tile, set_from_iter, as_slice, len, is_empty, remove_tile)
  • Commit 2: Double-ended bag drawing — even players draw from back, odd from front. Bag uses front cursor (fc) with tiles[0..fc] as dead space. Optimized put_back with 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-preserving remove_tile.
  • Commit 3: put_back uses self.tiles as 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

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

andy-k and others added 3 commits March 24, 2026 08:19
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>
@andy-k andy-k merged commit 54e2480 into main Mar 25, 2026
9 checks passed
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