Last active
December 26, 2015 01:19
-
-
Save Vazkii/7070447 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package vazkii.research; | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import thaumcraft.api.aspects.Aspect; | |
import static thaumcraft.api.aspects.Aspect.*; | |
public class AspectCartographer { | |
static long ms; | |
static boolean failed = false; | |
static File file; | |
static Map<Aspect, Integer> timesToCraft = new HashMap(); | |
static Map<Aspect, Integer> currentAspects = new HashMap(); | |
static List<Aspect> aspectsKnown = new ArrayList(); | |
static final List<Aspect> blacklist = Arrays.asList(AIR, FIRE, EARTH, WATER, ORDER, ENTROPY, VOID); | |
static final Aspect[] allAspects = new Aspect[] { AIR, EARTH, FIRE, WATER, ORDER, ENTROPY, VOID, LIGHT, ENERGY, MOTION, STONE, LIFE, WEATHER, ICE, CRYSTAL, DEATH, FLIGHT, DARKNESS, SOUL, HEAL, TRAVEL, POISON, ELDRITCH, MAGIC, AURA, TAINT, SEED, SLIME, PLANT, TREE, BEAST, FLESH, UNDEAD, MIND, SENSES, MAN, CROP, HARVEST, METAL, MINE, TOOL, WEAPON, ARMOR, HUNGER, GREED, CRAFT, CLOTH, MECHANISM, TRAP, EXCHANGE }; | |
static final int PRIMAL_COUNT = 50; | |
static final int VACUOS_COUNT = 20; // From bedrock research | |
// START HERE | |
public static void doStuff() { | |
System.out.println("STARTING! =========================================================="); | |
ms = System.currentTimeMillis(); | |
file = new File(".", "aspects.txt"); | |
try { | |
if(file.exists()) | |
file.delete(); | |
file.createNewFile(); | |
fillInStartingInfo(); | |
for(Aspect aspect : aspects.values()) { | |
if(blacklist.contains(aspect)) | |
continue; | |
System.out.println("Going to craft aspect from scratch. " + aspect.getName()); | |
craftAspect(aspect); | |
if(failed) { | |
System.out.println("Fail at crating aspect " + aspect.getName() + "!"); | |
break; | |
} else System.out.println("Crafted aspect from scratch. " + aspect.getName()); | |
System.out.println("-------------------------------"); | |
} | |
writeData(); | |
System.out.println("Done. Took " + (System.currentTimeMillis() - ms) + "ms."); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
static void fillInStartingInfo() { | |
failed = false; | |
aspectsKnown.clear(); | |
timesToCraft.clear(); | |
aspectsKnown.addAll(blacklist); | |
for(Aspect aspect : allAspects) { | |
currentAspects.put(aspect, 0); | |
timesToCraft.put(aspect, 0); | |
} | |
for(Aspect aspect : aspectsKnown) | |
currentAspects.put(aspect, PRIMAL_COUNT); | |
currentAspects.put(VOID, VACUOS_COUNT); // Bedrock scan | |
} | |
static void craftAspect(Aspect aspect) { | |
System.out.println("Trying to craft aspect " + aspect.getName()); | |
if(aspect.isPrimal()) { | |
System.out.println("Aspect " + aspect.getName() + " is primal, triggering fail."); | |
failed = true; | |
} | |
if(failed) { | |
System.out.println("Fail detected, aborting."); | |
return; | |
} | |
Aspect comp1 = aspect.getComponents()[0]; | |
Aspect comp2 = aspect.getComponents()[1]; | |
if(hasRequirementsForAspect(aspect)) { | |
currentAspects.put(comp1, currentAspects.get(comp1) - 1); | |
currentAspects.put(comp2, currentAspects.get(comp2) - 1); | |
boolean hasCrafted = aspectsKnown.contains(aspect); | |
int add = 1; | |
if(!hasCrafted) { | |
aspectsKnown.add(aspect); | |
add++; | |
} | |
currentAspects.put(aspect, currentAspects.get(aspect) + add); | |
timesToCraft.put(aspect, timesToCraft.get(aspect) + 1); | |
System.out.println("Crafted aspect " + aspect.getName() + " succefully! Count = " + currentAspects.get(aspect) + ". Times = " + timesToCraft.get(aspect)); | |
} else { | |
System.out.println("Components not acquired, trying to craft them."); | |
if(currentAspects.get(comp1) == 0) | |
craftAspect(comp1); | |
if(currentAspects.get(comp2) == (comp1 == comp2 ? 1 : 0)) | |
craftAspect(comp2); | |
craftAspect(aspect); | |
} | |
} | |
static boolean hasRequirementsForAspect(Aspect aspect) { | |
System.out.println("Checking requirements for " + aspect.getName()); | |
if(aspect.isPrimal()) { | |
System.out.println(aspect.getName() + " is a primal, ran out of it. Triggering fail."); | |
failed = true; | |
return false; | |
} | |
Aspect comp1 = aspect.getComponents()[0]; | |
Aspect comp2 = aspect.getComponents()[1]; | |
System.out.println("Components: " + comp1.getName() + " " + comp2.getName()); | |
boolean has = currentAspects.get(comp1) > 0 && currentAspects.get(comp2) > 0; | |
if(has) | |
System.out.println("Has Aspects for " + aspect.getName() + "."); | |
else System.out.println("Doesn't have Aspects! " + comp1.getName() + " = " + currentAspects.get(comp1) + ", " + comp2.getName() + " = " + currentAspects.get(comp2)); | |
return has; | |
} | |
static void writeData() throws IOException { | |
System.out.println("Writing file."); | |
BufferedWriter writer = new BufferedWriter(new FileWriter(file)); | |
writer.write("Linear path for all aspects. Assuming started with " + PRIMAL_COUNT + " of all primals and" + VACUOS_COUNT + "Vacuos (from bedrock scan):\r\r"); | |
for(Aspect aspect : allAspects) { | |
System.out.println(aspect.getName() + " = x" + timesToCraft.get(aspect)); | |
if(timesToCraft.get(aspect) == 0) | |
continue; | |
writer.write(aspect.getComponents()[0].getName() + " + " + aspect.getComponents()[1].getName() + " -> " + aspect.getName() + " (" + timesToCraft.get(aspect) + "x combined)\r"); | |
} | |
if(failed) | |
writer.write("FAILED!\r"); | |
writer.write("\rEND RESULTS:\r"); | |
for(Aspect aspect : allAspects) { | |
writer.write(aspect.getName() + " = " + currentAspects.get(aspect) + " remaining.\r"); | |
if(aspect.isPrimal() || aspect == VOID) | |
writer.write(" Total Used: " + ((aspect == VOID ? VACUOS_COUNT : PRIMAL_COUNT) - currentAspects.get(aspect)) + "\r"); | |
} | |
writer.close(); | |
System.out.println("-------------------------------"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment