From 28d38d7589d34f9cbaca70f557c1499137adcf24 Mon Sep 17 00:00:00 2001 From: michalStarski Date: Tue, 21 May 2019 23:51:03 +0200 Subject: [PATCH] windows update --- .gitignore | 2 +- utilities.py | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 41bb08d..d58da4b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ env .vscode *.swp linux_env -Results/* +moveset_data.json \ No newline at end of file diff --git a/utilities.py b/utilities.py index d55f205..26482d9 100644 --- a/utilities.py +++ b/utilities.py @@ -1,6 +1,6 @@ from config import GRID_WIDTH, GRID_HEIGHT from DataModels.Road import Road -import json, os +import json, os, platform def movement(environment, x ,y): movement = { @@ -25,16 +25,20 @@ def check_moves(environment, x,y,direction=None): return ([dir for dir in movement(environment, x, y)[0] if movement(environment, x,y)[0][dir] != (x,y) and dir != movement(environment,x,y)[1][direction]]) def save_moveset(moveset): - output_file = os.path.normpath(os.getcwd()) + '/Results/moveset_data.json' - with open(output_file, 'w') as f: - try: - results = json.loads(f) - except: - results = { - "moveset": [] - } - finally: - results["moveset"].append(moveset) - json.dump(results, f, indent=2) - print('Moveset saved to the file /Results/moveset_data.json') + if platform.system() == 'Windows': + path = '\moveset_data.json' + else: + path = '/moveset_data.json' + output_file = os.path.normpath(os.getcwd()) + '\moveset_data.json' + with open(output_file, 'w') as f: + try: + results = json.loads(f) + except: + results = { + "moveset": [] + } + finally: + results["moveset"].append(moveset) + json.dump(results, f, indent=2) + print('Moveset saved to the file moveset_data.json')