Merge branch 'master' into map_generator

This commit is contained in:
Magdalena Wilczyńska 2019-05-21 22:01:54 +02:00
commit 67e86029bb
3 changed files with 20 additions and 1 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ env
.vscode
*.swp
linux_env
Results/*

View File

@ -3,7 +3,7 @@ from DataModels.Road import Road
from DataModels.House import House
from DataModels.Dump import Dump
from config import GRID_WIDTH, GRID_HEIGHT, DELAY
from utilities import movement, check_moves
from utilities import movement, check_moves, save_moveset
from Traversal.DFS import DFS
from Traversal.BestFS import BestFS
from Traversal.BFS import BFS
@ -66,6 +66,7 @@ class GC(Cell):
for x in element_list:
x.unvisited = True
self.moves.reverse()
save_moveset(self.moves)
def find_houses_BestFS(self, environment):

View File

@ -1,5 +1,7 @@
from config import GRID_WIDTH, GRID_HEIGHT
from DataModels.Road import Road
import json, os
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),
@ -21,3 +23,18 @@ 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]])
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')