Give each game its own random.Random - #380
Open
taziksh wants to merge 5 commits into
Open
Conversation
Game and State previously seeded the module-global random, so concurrent games in one process corrupted each other's streams. State now owns a Random(seed), shared by reference with state copies so simulations advance the same stream. Streams are identical to the previous global behavior for a given seed.
👷 Deploy request for catanatron-staging pending review.Visit the deploys page to approve it
|
The test assumed WHITE sits after RED, but State shuffles seating and the discard sequence advances by seat index without wrapping, so it failed for about half the seatings. Pick roles by seat index instead.
bcollazo
reviewed
Jul 27, 2026
bcollazo
left a comment
Owner
There was a problem hiding this comment.
This is really cool! I'm a bit busy these days, but will try to review ASAP. If someone else can review / test that'd be great too!
Do games serialize nicely still to the Database? Does the GUI work nicely still?
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.
Problem
Game.__init__callsrandom.seed(self.seed). The stream is shared by every game in the same process, so games running concurrently corrupt each other's draws and break reproducibility of seeds.Change
Gamecreatesself.random = random.Random(seed)and passes it toState, which uses it everywhere the module global was used before.State.copy()andGame.copy()share the rng by reference, so simulations on copies advance the same stream, matching current behaviorgame.state.random, instead of the same globalrandomrngparameter inroll_dice()andinitialize_tilesthat defaults torandomTests
We tested by replaying seeded games with AlphaBeta, MCTS, and random bots, and checking the logs are identical to main. We also added
test_seeded_games_are_isolated_from_each_other(fails on main, passes here) and a playout-diversity test, and fixedtest_gym_reproducibilityand the discard sequence test, which relied on the old global seeding.