Merge branch 'master' into map_generator
This commit is contained in:
commit
67e86029bb
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ env
|
||||
.vscode
|
||||
*.swp
|
||||
linux_env
|
||||
Results/*
|
||||
|
@ -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):
|
||||
|
17
utilities.py
17
utilities.py
@ -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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user