changeset 20:82d447306f36 misc

Move parsealloys to materials-directory.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Apr 2009 22:15:20 +0000
parents 3f5b8222255c
children f2af3d55ac51
files materials/parsealloys.pl parsealloys.pl
diffstat 2 files changed, 143 insertions(+), 147 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/materials/parsealloys.pl	Thu Apr 16 22:15:20 2009 +0000
@@ -0,0 +1,143 @@
+#!/usr/bin/perl -w
+# Superklunssi by Ggr
+# Old format of alloying skill output was somewhat different, but
+# it has been tuned somewhere after 2005. New output format is:
+#
+#You mix obsidian and crystal and create a quantity of glass
+#You mix nullium and illumium and create a quantity of dukonium
+#You mix nullium and illumium and create a quantity of dukonium
+use strict;
+
+my ($opt_php);
+
+if ($#ARGV >= 0) {
+  if ($ARGV[0] eq "-php") { $opt_php = 1; }
+}   
+
+our %alloyNames = ("adamantium" => 0,"air" => 1,"alabaster" => 2,"alexandrite" => 3,"aluminium" => 4,"amber" => 5,"amethyst" => 6,"anipium" => 7,"aquamarine" => 8,"bamboo" => 9,"bark" => 10,"basalt" => 11,"batium" => 12,"birch" => 13,"bloodstone" => 14,"bone" => 15,"brass" => 16,"brick" => 17,"bronze" => 18,"burlap" => 19,"carnelian" => 20,"cedar" => 21,"cesium" => 22,"chalk" => 23,"charcoal" => 24,"chromium" => 25,"chrysoberyl" => 26,"clay" => 27,"cloth" => 28,"coal" => 29,"cobalt" => 30,"concrete" => 31,"copper" => 32,"coral" => 33,"cork" => 34,"cotton" => 35,"crystal" => 36,"darksteel" => 37,"diamond" => 38,"diggalite" => 39,"dragonscale" => 40,"dukonium" => 41,"duraluminium" => 42,"durandium" => 43,"earth" => 44,"ebony" => 45,"electrum" => 46,"elm" => 47,"emerald" => 48,"emulsion" => 49,"enchanted air" => 50,"feathers" => 51,"fire" => 52,"flesh" => 53,"food" => 54,"fur" => 55,"garnet" => 56,"glass" => 57,"gold" => 58,"granite" => 59,"graphite" => 60,"hematite" => 61,"hemp" => 62,"highsteel" => 63,"ice" => 64,"illumium" => 65,"indium" => 66,"iridium" => 67,"iron" => 68,"ivory" => 69,"jade" => 70,"kryptonite" => 71,"laen" => 72,"lead" => 73,"leather" => 74,"magnesium" => 75,"mahogany" => 76,"malachite" => 77,"mallorn" => 78,"maple" => 79,"marble" => 80,"marlor" => 81,"mithril" => 82,"molybdenum" => 83,"moonstone" => 84,"moss agate" => 85,"mowgles" => 86,"mowglite" => 87,"neo burlap" => 88,"nickel" => 89,"nullium" => 90,"oak" => 91,"obsidian" => 92,"olivine" => 93,"onyx" => 94,"opal" => 95,"osmium" => 96,"palladium" => 97,"paper" => 98,"pearl" => 99,"petrified wood" => 100,"pewter" => 101,"phosphorus" => 102,"platinum" => 103,"porcelain" => 104,"potassium" => 105,"pyrite" => 106,"quartz" => 107,"quicksilver" => 108,"rhodium" => 109,"rhodonite" => 110,"rubber" => 111,"ruby" => 112,"sapphire" => 113,"silicon" => 114,"silk" => 115,"silver" => 116,"slate" => 117,"starmetal" => 118,"steel" => 119,"steuben" => 120,"stone" => 121,"sulphur" => 122,"sunstone" => 123,"tadmium" => 124,"tin" => 125,"titanium" => 126,"topaz" => 127,"tormium" => 128,"tungsten" => 129,"turquoise" => 130,"uranium" => 131,"vanadium" => 132,"vegetation" => 133,"water" => 134,"wax" => 135,"weenite" => 136,"wood" => 137,"wool" => 138,"zhentorium" => 139,"zinc" => 140,"zircon" => 141,);
+our @alloyNameTable = ("adamantium","air","alabaster","alexandrite","aluminium","amber","amethyst","anipium","aquamarine","bamboo","bark","basalt","batium","birch","bloodstone","bone","brass","brick","bronze","burlap","carnelian","cedar","cesium","chalk","charcoal","chromium","chrysoberyl","clay","cloth","coal","cobalt","concrete","copper","coral","cork","cotton","crystal","darksteel","diamond","diggalite","dragonscale","dukonium","duraluminium","durandium","earth","ebony","electrum","elm","emerald","emulsion","enchanted air","feathers","fire","flesh","food","fur","garnet","glass","gold","granite","graphite","hematite","hemp","highsteel","ice","illumium","indium","iridium","iron","ivory","jade","kryptonite","laen","lead","leather","magnesium","mahogany","malachite","mallorn","maple","marble","marlor","mithril","molybdenum","moonstone","moss agate","mowgles","mowglite","neo burlap","nickel","nullium","oak","obsidian","olivine","onyx","opal","osmium","palladium","paper","pearl","petrified wood","pewter","phosphorus","platinum","porcelain","potassium","pyrite","quartz","quicksilver","rhodium","rhodonite","rubber","ruby","sapphire","silicon","silk","silver","slate","starmetal","steel","steuben","stone","sulphur","sunstone","tadmium","tin","titanium","topaz","tormium","tungsten","turquoise","uranium","vanadium","vegetation","water","wax","weenite","wood","wool","zhentorium","zinc","zircon",);
+
+
+## Parse data from input, ignoring fumbled alloys
+my %data = ();
+my $fumble = 0;
+my $nline = 0;
+print STDERR "Processing input ...";
+while (<STDIN>) {
+  chomp;
+  $nline++;
+  if ($nline % 10000 == 1) { print STDERR ".";  }
+  if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+)$/) {
+    my $min1 = $1; my $min2 = $2; my $res = $3;
+    if (!$fumble) {
+      push(@{$data{$1}{$2}}, $3);
+    } else {
+      print STDERR "\nIgnoring fumbled combo $1 + $2 = $3\n";
+    }
+    $fumble = 0;
+  } elsif (/^(You slip up and fumble your attempt.)/) {
+    $fumble = 1;
+  }
+}
+print STDERR " OK\n\n";
+
+## Re-format the data into single "ordered" hash, using as
+## close to alphabetical order as possible.
+my %final = ();
+foreach my $min1 (keys %data) {
+  foreach my $min2 (keys %{$data{$min1}}) {
+    if (!defined($final{$min1}{$min2}) && !defined($final{$min2}{$min1})) {
+      # Get both (a, b) and (b, a) combinations results into same array
+      my @tmp = ();
+      if (defined($data{$min1}{$min2})) {
+        push(@tmp, @{$data{$min1}{$min2}});
+      }
+      if (defined($data{$min2}{$min1})) {
+        push(@tmp, @{$data{$min2}{$min1}});
+      }
+      
+      # Determine if there are multiple results and which is the most likely.
+      # Some alloy combinations are inherently "unstable".
+      my %seen = ();
+      foreach my $mat (@tmp) { $seen{$mat}++; }
+      if ($opt_php) {
+        my $n = -1;
+        my $res = "";
+        foreach my $mat (keys %seen) {
+          if ($seen{$mat} > $n) {
+            $n = $seen{$mat};
+            $res = $mat;
+          }
+        }
+        $final{$min1}{$min2} = $res;
+        $final{$min2}{$min1} = $res;
+      } else {
+        if ($min1 lt $min2) {
+          $final{$min1}{$min2} = \%seen;
+        } else {
+          $final{$min2}{$min1} = \%seen;
+        }
+      }
+    }
+  }
+}
+
+
+## Output the results
+if ($opt_php) {
+  print "<?\n".
+  "\$alloyTable = array(\n";
+  
+  foreach my $min1 (@alloyNameTable) {
+    print "  \"$min1\" => array(";
+    foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
+      print "\"$min2\" => \"".$final{$min1}{$min2}."\", ";
+    }
+    print "),\n";
+  }
+  
+  print ");\n\n";
+  
+  # Create 'reverse' alloy table
+  my %restab = ();
+  foreach my $res (@alloyNameTable) {
+    foreach my $min1 (keys %final) {
+      foreach my $min2 (keys %{$final{$min1}}) {
+        if ($final{$min1}{$min2} eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1})) {
+          $restab{$res}{$min1}{$min2} = 1;
+        }
+      }
+    }
+  }
+
+  print "\$alloyRevTable = array(\n";
+  foreach my $res (sort { $a cmp $b } keys %restab) {
+    print "  \"$res\" => array(\n";
+    foreach my $min1 (sort { $a cmp $b } keys %{$restab{$res}}) {
+      if (scalar keys %{$restab{$res}{$min1}} > 0) {
+        print "    \"$min1\" => array(";
+        foreach my $min2 (sort { $a cmp $b } keys %{$restab{$res}{$min1}}) {
+          print "\"$min2\",";
+        }
+        print "),\n";
+      }
+    }
+    print "  ),\n";
+  }
+  
+  print ");\n\n".
+  "?>";
+} else {
+  print
+  "| Mineral1        | Mineral 2       | Result(s)\n".
+  "+-----------------+-----------------+--------------------------------\n";
+  foreach my $min1 (sort { $a cmp $b } keys %final) {
+    foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
+      printf "| %-15s | %-15s | ", $min1, $min2;
+      foreach my $res (sort { $_{$a} <=> $_{$b} } keys %{$final{$min1}{$min2}}) {
+        print "$res($final{$min1}{$min2}{$res}) ";
+      }
+      print "\n";
+    }
+  }
+}
--- a/parsealloys.pl	Thu Apr 16 20:02:39 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,147 +0,0 @@
-#!/usr/bin/perl -w
-# Superklunssi by Ggr
-# Old format of alloying skill output was somewhat different, but
-# it has been tuned somewhere after 2005. New output format is:
-#
-#You mix obsidian and crystal and create a quantity of glass
-#You mix nullium and illumium and create a quantity of dukonium
-#You mix nullium and illumium and create a quantity of dukonium
-use strict;
-
-my ($opt_php);
-
-if ($#ARGV >= 0) {
-  if ($ARGV[0] eq "-php") { $opt_php = 1; }
-}   
-
-our %alloyNames = ("adamantium" => 0,"air" => 1,"alabaster" => 2,"alexandrite" => 3,"aluminium" => 4,"amber" => 5,"amethyst" => 6,"anipium" => 7,"aquamarine" => 8,"bamboo" => 9,"bark" => 10,"basalt" => 11,"batium" => 12,"birch" => 13,"bloodstone" => 14,"bone" => 15,"brass" => 16,"brick" => 17,"bronze" => 18,"burlap" => 19,"carnelian" => 20,"cedar" => 21,"cesium" => 22,"chalk" => 23,"charcoal" => 24,"chromium" => 25,"chrysoberyl" => 26,"clay" => 27,"cloth" => 28,"coal" => 29,"cobalt" => 30,"concrete" => 31,"copper" => 32,"coral" => 33,"cork" => 34,"cotton" => 35,"crystal" => 36,"darksteel" => 37,"diamond" => 38,"diggalite" => 39,"dragonscale" => 40,"dukonium" => 41,"duraluminium" => 42,"durandium" => 43,"earth" => 44,"ebony" => 45,"electrum" => 46,"elm" => 47,"emerald" => 48,"emulsion" => 49,"enchanted air" => 50,"feathers" => 51,"fire" => 52,"flesh" => 53,"food" => 54,"fur" => 55,"garnet" => 56,"glass" => 57,"gold" => 58,"granite" => 59,"graphite" => 60,"hematite" => 61,"hemp" => 62,"highsteel" => 63,"ice" => 64,"illumium" => 65,"indium" => 66,"iridium" => 67,"iron" => 68,"ivory" => 69,"jade" => 70,"kryptonite" => 71,"laen" => 72,"lead" => 73,"leather" => 74,"magnesium" => 75,"mahogany" => 76,"malachite" => 77,"mallorn" => 78,"maple" => 79,"marble" => 80,"marlor" => 81,"mithril" => 82,"molybdenum" => 83,"moonstone" => 84,"moss agate" => 85,"mowgles" => 86,"mowglite" => 87,"neo burlap" => 88,"nickel" => 89,"nullium" => 90,"oak" => 91,"obsidian" => 92,"olivine" => 93,"onyx" => 94,"opal" => 95,"osmium" => 96,"palladium" => 97,"paper" => 98,"pearl" => 99,"petrified wood" => 100,"pewter" => 101,"phosphorus" => 102,"platinum" => 103,"porcelain" => 104,"potassium" => 105,"pyrite" => 106,"quartz" => 107,"quicksilver" => 108,"rhodium" => 109,"rhodonite" => 110,"rubber" => 111,"ruby" => 112,"sapphire" => 113,"silicon" => 114,"silk" => 115,"silver" => 116,"slate" => 117,"starmetal" => 118,"steel" => 119,"steuben" => 120,"stone" => 121,"sulphur" => 122,"sunstone" => 123,"tadmium" => 124,"tin" => 125,"titanium" => 126,"topaz" => 127,"tormium" => 128,"tungsten" => 129,"turquoise" => 130,"uranium" => 131,"vanadium" => 132,"vegetation" => 133,"water" => 134,"wax" => 135,"weenite" => 136,"wood" => 137,"wool" => 138,"zhentorium" => 139,"zinc" => 140,"zircon" => 141,);
-our @alloyNameTable = ("adamantium","air","alabaster","alexandrite","aluminium","amber","amethyst","anipium","aquamarine","bamboo","bark","basalt","batium","birch","bloodstone","bone","brass","brick","bronze","burlap","carnelian","cedar","cesium","chalk","charcoal","chromium","chrysoberyl","clay","cloth","coal","cobalt","concrete","copper","coral","cork","cotton","crystal","darksteel","diamond","diggalite","dragonscale","dukonium","duraluminium","durandium","earth","ebony","electrum","elm","emerald","emulsion","enchanted air","feathers","fire","flesh","food","fur","garnet","glass","gold","granite","graphite","hematite","hemp","highsteel","ice","illumium","indium","iridium","iron","ivory","jade","kryptonite","laen","lead","leather","magnesium","mahogany","malachite","mallorn","maple","marble","marlor","mithril","molybdenum","moonstone","moss agate","mowgles","mowglite","neo burlap","nickel","nullium","oak","obsidian","olivine","onyx","opal","osmium","palladium","paper","pearl","petrified wood","pewter","phosphorus","platinum","porcelain","potassium","pyrite","quartz","quicksilver","rhodium","rhodonite","rubber","ruby","sapphire","silicon","silk","silver","slate","starmetal","steel","steuben","stone","sulphur","sunstone","tadmium","tin","titanium","topaz","tormium","tungsten","turquoise","uranium","vanadium","vegetation","water","wax","weenite","wood","wool","zhentorium","zinc","zircon",);
-
-
-## Parse data from input, ignoring fumbled alloys
-my %data = ();
-my $fumble = 0;
-my $nline = 0;
-print STDERR "Processing input ...";
-while (<STDIN>) {
-  chomp;
-  $nline++;
-  if ($nline % 10000 == 1) { print STDERR ".";  }
-  if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+)$/) {
-    my $min1 = $1; my $min2 = $2; my $res = $3;
-    if (!$fumble) {
-      push(@{$data{$1}{$2}}, $3);
-    } else {
-      print STDERR "\nIgnoring fumbled combo $1 + $2 = $3\n";
-    }
-    $fumble = 0;
-  } elsif (/^(You slip up and fumble your attempt.)/) {
-    $fumble = 1;
-  }
-}
-print STDERR " OK\n\n";
-
-## Re-format the data into single "ordered" hash, using as
-## close to alphabetical order as possible.
-my %final = ();
-foreach my $min1 (keys %data) {
-  foreach my $min2 (keys %{$data{$min1}}) {
-    if (!defined($final{$min1}{$min2}) && !defined($final{$min2}{$min1})) {
-      # Get both (a, b) and (b, a) combinations results into same array
-      my @tmp = ();
-      if (defined($data{$min1}{$min2})) {
-        push(@tmp, @{$data{$min1}{$min2}});
-      }
-      if (defined($data{$min2}{$min1})) {
-        push(@tmp, @{$data{$min2}{$min1}});
-      }
-      
-      # Determine if there are multiple results and which is the most likely.
-      # Some alloy combinations are inherently "unstable".
-      my %seen = ();
-      foreach my $mat (@tmp) { $seen{$mat}++; }
-      if ($opt_php) {
-        my $n = -1;
-        my $res = "";
-        foreach my $mat (keys %seen) {
-          if ($seen{$mat} > $n) {
-            $n = $seen{$mat};
-            $res = $mat;
-          }
-        }
-        if ($min1 lt $min2) {
-          $final{$min1}{$min2} = $res;
-        } else {
-          $final{$min2}{$min1} = $res;
-        }
-        
-      } else {
-        if ($min1 lt $min2) {
-          $final{$min1}{$min2} = \%seen;
-        } else {
-          $final{$min2}{$min1} = \%seen;
-        }
-      }
-    }
-  }
-}
-
-
-## Output the results
-if ($opt_php) {
-  print "<?\n".
-  "\$alloyTable = array(\n";
-  
-  foreach my $min1 (@alloyNameTable) {
-    print "  \"$min1\" => array(";
-    foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
-      print "\"$min2\" => \"".$final{$min1}{$min2}."\", ";
-    }
-    print "),\n";
-  }
-  
-  print ");\n\n";
-  
-  # Create 'reverse' alloy table
-  my %restab = ();
-  foreach my $res (@alloyNameTable) {
-    foreach my $min1 (keys %final) {
-      foreach my $min2 (keys %{$final{$min1}}) {
-        if ($final{$min1}{$min2} eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1})) {
-          $restab{$res}{$min1}{$min2} = 1;
-        }
-      }
-    }
-  }
-
-  print "\$alloyRevTable = array(\n";
-  foreach my $res (sort { $a cmp $b } keys %restab) {
-    print "  \"$res\" => array(\n";
-    foreach my $min1 (sort { $a cmp $b } keys %{$restab{$res}}) {
-      if (scalar keys %{$restab{$res}{$min1}} > 0) {
-        print "    \"$min1\" => array(";
-        foreach my $min2 (sort { $a cmp $b } keys %{$restab{$res}{$min1}}) {
-          print "\"$min2\",";
-        }
-        print "),\n";
-      }
-    }
-    print "  ),\n";
-  }
-  
-  print ");\n\n".
-  "?>";
-} else {
-  print
-  "| Mineral1        | Mineral 2       | Result(s)\n".
-  "+-----------------+-----------------+--------------------------------\n";
-  foreach my $min1 (sort { $a cmp $b } keys %final) {
-    foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
-      printf "| %-15s | %-15s | ", $min1, $min2;
-      foreach my $res (sort { $_{$a} <=> $_{$b} } keys %{$final{$min1}{$min2}}) {
-        print "$res($final{$min1}{$min2}{$res}) ";
-      }
-      print "\n";
-    }
-  }
-}