From c3ad3e3c86d68501981ca164e5aefb1d9c69bdbe Mon Sep 17 00:00:00 2001 From: Liwei Cai Date: Sun, 23 May 2021 12:08:18 -0400 Subject: [PATCH] Reload to clear module-level variables between games Mitigates #58 by forcing to `reload` the module and reset its global variables (See https://docs.python.org/3/library/importlib.html#importlib.reload) Confirmed that this fix makes the code in #58 no longer work. However, there is still ways to get around, and I don't think a complete fix is possible. To prevent this completely we may have to rely on manual inspection. --- code/prisonersDilemma.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/prisonersDilemma.py b/code/prisonersDilemma.py index 5a12d49..3e644f1 100644 --- a/code/prisonersDilemma.py +++ b/code/prisonersDilemma.py @@ -39,6 +39,8 @@ def strategyMove(move): def runRound(pair): moduleA = importlib.import_module(STRATEGY_FOLDER+"."+pair[0]) moduleB = importlib.import_module(STRATEGY_FOLDER+"."+pair[1]) + importlib.reload(moduleA) + importlib.reload(moduleB) memoryA = None memoryB = None