64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
from config import GRID_WIDTH, GRID_HEIGHT
|
|
from DataModels.Road import Road
|
|
import platform,os,json
|
|
def movement(environment, x ,y):
|
|
movement = {
|
|
"right": (x + 1, y) if x + 1 < GRID_WIDTH and type(environment[x + 1][y]) == Road else (x, y),
|
|
"left": (x - 1, y) if x - 1 >= 0 and type(environment[x - 1][y]) == Road else (x, y),
|
|
"down": (x, y + 1) if y + 1 < GRID_HEIGHT and type(environment[x][y + 1]) == Road else (x, y),
|
|
"up": (x, y - 1) if y - 1 >= 0 and type(environment[x][y - 1]) == Road else (x, y)
|
|
}
|
|
|
|
forbidden_movement = {
|
|
"right": "left",
|
|
"left": "right",
|
|
"up": "down",
|
|
"down": "up"
|
|
}
|
|
|
|
return (movement, forbidden_movement)
|
|
|
|
def check_moves(environment, x,y,direction=None):
|
|
if direction == None:
|
|
return ([dir for dir in movement(environment, x, y)[0] if movement(environment, x,y)[0][dir] != (x,y)])
|
|
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]])
|
|
|
|
<<<<<<< Updated upstream
|
|
def save_moveset(moveset):
|
|
if platform.system() == 'Windows':
|
|
path = '\moveset_data.json'
|
|
else:
|
|
path = '/moveset_data.json'
|
|
output_file = os.path.normpath(os.getcwd()) + path
|
|
|
|
results = {}
|
|
try:
|
|
f = open(output_file, 'r+')
|
|
except:
|
|
open(output_file, 'a').close()
|
|
finally:
|
|
f = open(output_file, 'r+')
|
|
|
|
try:
|
|
results = json.load(f)
|
|
except:
|
|
pass
|
|
finally:
|
|
if "moveset" not in results:
|
|
results = { "moveset": [] }
|
|
|
|
results["moveset"].append(moveset)
|
|
f.seek(0)
|
|
json.dump(results, f, indent=1)
|
|
f.close()
|
|
=======
|
|
def parse_list(whole_result):
|
|
moves = []
|
|
parser = {[0,1]:"up",[0,-1]:"down",[1,0]:"right",[-1,0]:"left"}
|
|
for x in len(whole_result)-1:
|
|
x_subtraction = whole_result[x+1][0]-whole_result[x][0]
|
|
y_subtraction = whole_result[x+1][1]-whole_result[x][1]
|
|
moves.append(parser[[x_subtraction,y_subtraction]])
|
|
return moves
|
|
>>>>>>> Stashed changes
|