From 07f77a8ffd7e9f1dfdd09fe534323d3d1b206df7 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 6 Apr 2022 17:47:57 -0400 Subject: [PATCH] Proof of concept for dungeon graph maker. --- make_graph.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 make_graph.py 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("}") + + -- 2.31.1