Mercurial > sypikslang
diff gamelib/visualize.py @ 111:bb76ce231ff9
Merge changes.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Wed, 09 May 2012 22:37:49 +0200 |
parents | 86a6434c4eb2 |
children | 94258a86f773 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/visualize.py Wed May 09 22:37:49 2012 +0200 @@ -0,0 +1,32 @@ +import networkx + +from gamelib.lab import Lab + + +def construct_research_tree(lab): + rt = networkx.DiGraph() + for research in lab.new_research: + rt.add_node(research, label=research.NAME, color='green') + for research in lab.new_research: + for prereq in research.PREREQUISITES: + rt.add_edge(prereq[0], research, weight=1.0 / prereq[1], \ + label=prereq[1], color='green') + for schematic in lab.new_schematics: + rt.add_node(schematic, label=schematic.NAME, color='red') + for schematic in lab.new_schematics: + for prereq in schematic.PREREQUISITES: + rt.add_edge(prereq[0], schematic, weight=1.0 / prereq[1], \ + label=prereq[1], color='red', size=schematic.COST / 10) + return rt + + +def draw(rt): + agraph = networkx.to_agraph(rt) + agraph.graph_attr['label'] = 'Research Tree' + agraph.write('research_tree.dot') + + +def main(): + lab = Lab({'science': {}}) + research_tree = construct_research_tree(lab) + draw(research_tree)