-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
random.seed(int) breaks the game unit isolation #107
Comments
suggestion from cooljoseph (unvalidated):
|
(also for the record, seems like a duplicate of #106 but is waay better documented) |
Ahh, dangit, I didn't see a duplicate when I started typing. 🤣 Missed it by thaaat much. |
Fix idea (validated on my computer): import importlib
import random and then edit the following lines: if name == 'random':
import random
return random to if name == 'random':
importlib.reload(random)
return random |
TLDR: The
random
built-in library does not seem to be isolated globally, which is exploitable in a few potential ways, but might also indicate that other libraries may not be isolated.On a whim, I added
random.seed(9001)
to the global/class layer of my bot, to see if I could change the seed and get a new game, but found some interesting bugs.Right away, I noticed that the
examplefuncsplayer
I was playing against immediately started putting all its new bots in a single lane.....which suggested to me that, even though I was setting the seed inmybot
, it was affectingexamplefuncsplayer
as well. I was able to confirm this by adding some logging statements:Inspecting the prints, for a few turns in a row, after the seed gets set, I was able to confirm this behavior with the print statements:
Even though Black team is the only team setting the seed, once the seed gets changed, it affects not only all of Black teams other units, but all of White teams units too. Collectively, they will all produce/receive the same sequence of random numbers.
This implies that the
random
package is not isolated unit-to-unit, and is global for all units on both teams. This could be exploited by one team to predict and/or control the other team. For example, as I mentioned, I first noticed thatexamplefuncsplayer
immediately just started to put all of its units in only one or two columns, instead of "randomly". This is because, once I reset the same seed statically over and over, every time White teamexamplefuncsplayer
"randomly" chose a column, it was getting the same sequence over and over again because the pawn that Blackmybot
spawned immediately reset the random seed sequence.This makes me wonder, ifhe
random
built-in library does not seem to be isolated globally, other libraries/packages might not be isolated either. 🤷♂️The text was updated successfully, but these errors were encountered: