Skip to content

Commit

Permalink
allow more variety in the location graph generation
Browse files Browse the repository at this point in the history
  • Loading branch information
neuromancer committed Jan 16, 2025
1 parent bea0da0 commit 43a8b3d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mystery_o_matic/location.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from random import shuffle, choice

from networkx import gnr_graph, relabel_nodes, Graph
from networkx import gnp_random_graph, relabel_nodes, Graph, is_planar, is_connected
from networkx.drawing.nx_agraph import to_agraph

locations = ["egypt", "castle", "train", "ship", "space station", "mansion"]
Expand Down Expand Up @@ -402,12 +402,18 @@ def create_locations_graph(self, nodes):
Returns:
- graph: The created graph.
"""
if self.name == "train":
graph = Graph()
for n in range(self.number_places - 1):
graph.add_edge("ROOM" + str(n), "ROOM" + str(n + 1))
else:
graph = gnr_graph(self.number_places, 0.5).to_undirected()
keepGenerating = True

while keepGenerating:
if self.name == "train":
graph = Graph()
for n in range(self.number_places - 1):
graph.add_edge("ROOM" + str(n), "ROOM" + str(n + 1))
else:
graph = gnp_random_graph(self.number_places, 0.5)

keepGenerating = not (is_planar(graph) and is_connected(graph))

graph = relabel_nodes(graph, nodes)
return graph

Expand Down

0 comments on commit 43a8b3d

Please sign in to comment.