March 15, 2004
my first graphs (geekin, pic(s), random re me, video games)
Graphs are cool. They help people understand things that are hard to explain in other ways or they organize information differently in order to try to infiltrate your brain.I like video games. First Person Shooters, Real Time Strategy, Turn-Based Strategy, Role Playing Games and almost any combination of those. The problem with a lot of video games (especially RPGs) is that they are so complicated that it's hard to remember all the information you need to know in order to play the game effectively.
In particular, I'm playing Final Fantasy Tactics: Advance right now. The character progression is cool, but it's hard to remember all the different dependencies and all the abilities associated with each class. So I graphed them. Woo! code warning:
#!/usr/bin/perl -w use strict; use GraphViz; open F,'<races' or die "couldn't read races: $!\n"; my $fc; { local $/ = undef; $fc = <F> } close F; # race -> base -> child # split on 3+ "blank" lines my @races = split /(?:\s*?\n\s*?){3,}/, $fc; for my $race (@races) { my $g = GraphViz->new(); my ($r,@r,$flag); $r = $1 if $race =~ /=.*?\n(.*?).\n/s; # grab race name $g->add_node($r); $race =~ s/^.*?\-\s*?\n//s; # only keep ability information # iterate over abilities, saving class and prerequisite while ($race =~ m|^(\w+(?:\s\w+)?)\s*\-\s+(.*)$|gm) { my ($class, $prereq) = ($1, $2); $g->add_node($class); if ($prereq =~ m|N/A|) { # print "base [$class]\n"; $g->add_edge($r,$class); } else { # print " child [$class] "; print "(multiple) " if $prereq =~ /,/; # print "dependency [$1] " while $prereq =~ /(\d (\w+(?:\s*\w+)?))/g; while ($prereq =~ /(\d) (\w+(?:\s*\w+)?)/g) { my ($label, $dep) = ($1, $2); my @options = (style => 'dotted', fontcolor => 'red', dir => 'both'); $g->add_edge($dep, $class, label => $label, @options); } # print "\n"; } } $g->as_png("$r.png"); }Posted by yargevad at March 15, 2004 02:15 PM