3 usage: make-graph.py [-a] [-m] [-s]
5 Make a DOT graph of Colossal Cave
7 -a = emit graph of entire dungeon
8 -m = emit graph of maze all alike
9 -s = emit graph of surface locations
11 # Copyright (c) 2017 by Eric S. Raymond
12 # SPDX-License-Identifier: BSD-2-clause
14 import sys, yaml, getopt
17 "Select out loci related to the Maze All Alike"
18 return ("ALIKE" in loc) or (loc == "LOC_PITBRINK") or ("MAZEEND" in loc) or ("STALACTITE" in loc)
21 "Select out surface locations"
22 if ("ABOVE" in attrs["conditions"]) and attrs["conditions"]["ABOVE"]:
24 if ("FOREST" in attrs["conditions"]) and attrs["conditions"]["FOREST"]:
29 m = {"NORTH":"N", "EAST":"E", "SOUTH":"S", "WEST":"W", "UPWAR":"U", "DOWN":"D"}
32 if __name__ == "__main__":
33 with open("adventure.yaml", "r") as f:
34 db = yaml.safe_load(f)
37 (options, arguments) = getopt.getopt(sys.argv[1:], "ams")
38 except getopt.GetoptError as e:
43 for (switch, val) in options:
51 sys.stderr.write(__doc__)
55 for obj in db["objects"]:
57 location = obj[1].get("locations")
58 if "OBJ" not in objname and location != "LOC_NOWHERE" and ("immovable" not in obj[1] or not obj[1]["immovable"]):
59 if location in startlocs:
60 startlocs[location].append(objname)
62 startlocs[location] = [objname]
65 for obj in db["objects"]:
67 location = obj[1].get("locations")
68 if "OBJ" not in objname and location != "LOC_NOWHERE" and ("immovable" not in obj[1] or not obj[1]["immovable"]):
69 if location in startlocs:
70 startlocs[location].append(objname)
72 startlocs[location] = [objname]
76 for (loc, attrs) in db["locations"]:
77 if subset == "surface" and not surface(attrs):
79 if subset == "maze" and not allalike(loc):
83 node_label += "\\n" + ",".join(startlocs[loc]).lower()
84 print(' %s [shape=box,label="%s"]' % (loc[4:], node_label))
86 for (loc, attrs) in db["locations"]:
87 if subset == "surface" and not surface(attrs):
89 travel = attrs["travel"]
92 verbs = [abbreviate(x) for x in dest["verbs"]]
95 action = dest["action"]
96 if action[0] == "goto":
98 if subset == "maze" and not (allalike(loc) or allalike(dest)):
100 arc = "%s -> %s" % (loc[4:], dest[4:])
101 label=",".join(verbs).lower()
103 arc += ' [label="%s"]' % label