From 65a29aa59a321d86097b7226d06f830072fbaf06 Mon Sep 17 00:00:00 2001 From: Angelo Huang Date: Sun, 31 Jul 2022 13:47:03 +0200 Subject: [PATCH] fix(ai): add legacy policy support --- PyGame/orso_ai.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/PyGame/orso_ai.py b/PyGame/orso_ai.py index e16a9f8..0a1afcb 100644 --- a/PyGame/orso_ai.py +++ b/PyGame/orso_ai.py @@ -770,10 +770,13 @@ def print_value(self, board): print(f"{self.name}: {board.get_hash()} -> {self.states_value.get(board.get_hash())}") def load_policy(self, file): - fr = open(file, 'rb') - data = pickle.load(fr) - self.states_value = data['states_value'] - fr.close() + with open(file, 'rb') as file_read: + data = pickle.load(file_read) + + self.states_value = ( + data if 'states_value' not in data else # data legacy support + data['states_value'] + ) # Main if __name__ == "__main__":