SWU-Karabast / SWUOnline

Star Wars Unlimited Sim
GNU General Public License v3.0
44 stars 35 forks source link

feat: randomness improved #302

Closed brubraz closed 2 months ago

brubraz commented 3 months ago

Improved randomness when shuffling the deck

OotTheMonk commented 3 months ago

Is it possible to manually seed the new function? The reason this all was done is because people were complaining about other people abusing undo to achieve a more desired random result (for example undo and redo a mulligan, or a random discard, or a die roll in FaB). This was written to make the result be deterministic if they undo then redo the same sequence of game actions while still being sufficiently unpredictable to be suitable for achieving card mixing.

brubraz commented 3 months ago

Is it possible to manually seed the new function? The reason this all was done is because people were complaining about other people abusing undo to achieve a more desired random result (for example undo and redo a mulligan, or a random discard, or a die roll in FaB). This was written to make the result be deterministic if they undo then redo the same sequence of game actions while still being sufficiently unpredictable to be suitable for achieving card mixing.

I updated the code to perform the initial shuffle (before the start of the game) using the random_int function for better randomness. Subsequent shuffles will be done using mt_rand with a seed to allow undo operations.

OotTheMonk commented 2 months ago

I think there's a very subtle bug here; the problem is that randomSeeded is true both on the initial shuffle, and also for all calls to GetRandom after the first one while processing the same gamestate. So it would only respect the undo invariance if no more than one random effect is done during that gamestate processing.

brubraz commented 2 months ago

I think there's a very subtle bug here; the problem is that randomSeeded is true both on the initial shuffle, and also for all calls to GetRandom after the first one while processing the same gamestate. So it would only respect the undo invariance if no more than one random effect is done during that gamestate processing.

I got your point and I updated the code to use random_int only on the initial shuffle.