Fixed Logicerror with double traversal of edge.

This commit is contained in:
Bernhard Schoeffel 2025-05-26 12:35:24 +02:00
parent 929963aa3a
commit 50444c6f7a
2 changed files with 6 additions and 2 deletions

View File

@ -5,7 +5,8 @@
"Ost/West-Passage" <> "Schwefelgewölbe"
"Schwefelgewölbe" > "Steiniger Pfad"
"Schatzkammer" > "Nebelraum"
"Steiniger Pfad" > "Schatzkammer"
"Steiniger Pfad" <> "Schatzkammer"
"Steiniger Pfad" > "Höhleneingang"
"Kristallhöhle" <> "Schwefelgewölbe"
"Kristallhöhle" <> "Nebelraum"
"Versteckter Gang" > "Kristallhöhle"

View File

@ -56,7 +56,9 @@ class Graph:
visited.add(currentNode)
for neighbor in self.adjacencyList[currentNode]:
edge = (currentNode, neighbor)
if neighbor not in visited and (edgesGonePassed is None or edge not in edgesGonePassed):
# We already went this Edge. Read Part3 as not allowing this to happen
edgeReverse = (neighbor, currentNode)
if neighbor not in visited and (edgesGonePassed is None or edge not in edgesGonePassed) and (edgesGonePassed is None or edgeReverse not in edgesGonePassed):
# Pythonic way of saying neighbour, path no next clear neighbour
# and union of edgesGone with current edge
queue.append((neighbor, path + [neighbor], edgesGone | {edge}))
@ -103,6 +105,7 @@ if __name__ == "__main__":
goal = "Schatzkammer"
shortestPath, edgesGoneInitial = caveGraph.breadthFirstSearch(start, goal)
logger.debug(caveGraph.adjacencyList)
logger.debug(edgesGoneInitial)
if shortestPath:
print(f"Shortest path from {start} to {goal} is:")