From: Eric S. Raymond Date: Wed, 6 Apr 2022 21:47:57 +0000 (-0400) Subject: Proof of concept for dungeon graph maker. X-Git-Tag: 1.10~3 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=07f77a8ffd7e9f1dfdd09fe534323d3d1b206df7;p=open-adventure.git Proof of concept for dungeon graph maker. --- diff --git a/make_graph.py b/make_graph.py new file mode 100755 index 0000000..28af8f7 --- /dev/null +++ b/make_graph.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +# Make a DOT graph of the dungeon +# +# Copyright (c) 2017 by Eric S. Raymond +# SPDX-License-Identifier: BSD-2-clause + +import sys, yaml + +def allalike(loc): + "Select out loci related to the Maze All Alike" + return (loc == "LOC_MISTWEST") or ("ALIKE" in loc) or ("DEADEND" in loc) or ("STALACTITE" in loc) + +if __name__ == "__main__": + with open("adventure.yaml", "r") as f: + db = yaml.safe_load(f) + + print("digraph G {") + for (loc, attrs) in db["locations"]: + if not allalike(loc): + continue + travel = attrs["travel"] + if len(travel) > 0: + for dest in travel: + verbs = dest["verbs"] + if len(verbs) == 0: + continue + action = dest["action"] + if action[0] == "goto": + arc = "%s -> %s" % (loc[4:], action[1][4:]) + label=",".join(verbs).lower() + if len(label) > 0: + arc += ' [label="%s"]' % label + print(" " + arc) + print("}") + +