clean up Fusion_Graph and fix get_path
parent
20e24a40e3
commit
2f2c281265
|
@ -15,7 +15,7 @@ import sys
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
|
|
||||||
def __init__(self, vanillaGame, randoSettings = (None,)):
|
def __init__(self, vanillaGame, randoSettings=None):
|
||||||
self.graph = dict()
|
self.graph = dict()
|
||||||
self.areaConnections = dict()
|
self.areaConnections = dict()
|
||||||
self.areaConnectionOffsets = dict()
|
self.areaConnectionOffsets = dict()
|
||||||
|
@ -50,7 +50,7 @@ class Game:
|
||||||
sourceDoor = int.from_bytes(sourceRom.read(1), 'little')
|
sourceDoor = int.from_bytes(sourceRom.read(1), 'little')
|
||||||
targetOffset = sourceRom.tell()
|
targetOffset = sourceRom.tell()
|
||||||
targetArea = int.from_bytes(sourceRom.read(1), 'little')
|
targetArea = int.from_bytes(sourceRom.read(1), 'little')
|
||||||
if sourceArea != 255:
|
while sourceArea != 255:
|
||||||
self.areaConnections.update({
|
self.areaConnections.update({
|
||||||
'S{}-{:02X}'.format(sourceArea, sourceDoor): targetArea })
|
'S{}-{:02X}'.format(sourceArea, sourceDoor): targetArea })
|
||||||
self.areaConnectionOffsets.update({
|
self.areaConnectionOffsets.update({
|
||||||
|
@ -91,7 +91,7 @@ class Game:
|
||||||
doorString]
|
doorString]
|
||||||
doorNumber += 1
|
doorNumber += 1
|
||||||
# print('DEBUG: Parsing seemingly done?')
|
# print('DEBUG: Parsing seemingly done?')
|
||||||
except:
|
except FileNotFoundError:
|
||||||
print('Error:', vanillaGame, 'could not be opened.')
|
print('Error:', vanillaGame, 'could not be opened.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -212,32 +212,32 @@ class Game:
|
||||||
checkRequirement = (start, end)
|
checkRequirement = (start, end)
|
||||||
return self.requirements.get(checkRequirement)
|
return self.requirements.get(checkRequirement)
|
||||||
|
|
||||||
def get_path(self, start, end, LimitArea, path, depth = (False, None, 100)):
|
def get_path(self, start, end, LimitArea=False, path=None, depth=100):
|
||||||
if path == None:
|
if path == None:
|
||||||
self.visited.clear()
|
self.visited.clear()
|
||||||
self.queue.clear()
|
self.queue.clear()
|
||||||
path = list()
|
path = list()
|
||||||
path = path + [
|
path = path + [start]
|
||||||
start]
|
|
||||||
if start not in self.graph:
|
if start not in self.graph:
|
||||||
return None
|
return None
|
||||||
if None == end:
|
if start == end:
|
||||||
return path
|
return path
|
||||||
# if None(path) >= depth:
|
if len(path) >= depth:
|
||||||
if path >= depth:
|
|
||||||
return None
|
return None
|
||||||
for point in None.graph[start]:
|
for point in self.graph[start]:
|
||||||
if point in self.itemLocations and point not in end:
|
if point in self.itemLocations:
|
||||||
|
if point not in end:
|
||||||
continue
|
continue
|
||||||
if point in path:
|
if point in path:
|
||||||
continue
|
continue
|
||||||
if LimitArea:
|
if LimitArea:
|
||||||
for area in range(0, 7):
|
for area in range(0, 7):
|
||||||
if 'S{}'.format(area) in start and 'S{}'.format(area) not in point:
|
if 'S{}'.format(area) in start:
|
||||||
|
if 'S{}'.format(area) not in point:
|
||||||
return None
|
return None
|
||||||
edge = (start, point)
|
edge = (start, point)
|
||||||
self.queue.append(edge)
|
self.queue.append(edge)
|
||||||
if self.queue:
|
while self.queue:
|
||||||
edge = self.queue.pop()
|
edge = self.queue.pop()
|
||||||
if edge not in self.visited:
|
if edge not in self.visited:
|
||||||
self.visited.append(edge)
|
self.visited.append(edge)
|
||||||
|
@ -246,14 +246,10 @@ class Game:
|
||||||
if pathReqs == None:
|
if pathReqs == None:
|
||||||
newpath = self.get_path(node, end, LimitArea, path, depth)
|
newpath = self.get_path(node, end, LimitArea, path, depth)
|
||||||
if newpath:
|
if newpath:
|
||||||
path = path + [
|
path = path + [node]
|
||||||
node]
|
|
||||||
return newpath
|
return newpath
|
||||||
if pathReqs == True:
|
elif pathReqs == True:
|
||||||
newpath = self.get_path(node, end, LimitArea, path, depth)
|
newpath = self.get_path(node, end, LimitArea, path, depth)
|
||||||
if newpath:
|
if newpath:
|
||||||
path = path + [
|
path = path + [node]
|
||||||
node]
|
|
||||||
return newpath
|
return newpath
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue