reformat & code cleanup
parent
6bb38066d6
commit
ea30ec2b6b
10
build.gradle
10
build.gradle
|
|
@ -10,13 +10,13 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.2'
|
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
|
||||||
implementation 'org.jgrapht:jgrapht-io:1.5.1'
|
implementation 'org.jgrapht:jgrapht-io:1.5.1'
|
||||||
implementation 'guru.nidi:graphviz-java:0.18.1'
|
implementation 'guru.nidi:graphviz-java:0.18.1'
|
||||||
implementation 'org.graalvm.js:js:20.0.0'
|
implementation 'org.graalvm.js:js:22.1.0.1'
|
||||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.13.0'
|
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ public class Database {
|
||||||
Water.setPreference(water);
|
Water.setPreference(water);
|
||||||
|
|
||||||
// gases
|
// gases
|
||||||
NitrogenGas.add(new Recipe(1,"pressure thingy", false, ResourceWellExtractor.class));
|
NitrogenGas.add(new Recipe(1, "pressure thingy", false, ResourceWellExtractor.class));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Steel Ingot
|
// Steel Ingot
|
||||||
|
|
@ -496,72 +496,72 @@ public class Database {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(6, Refinery.class);
|
Recipe recipe = new Recipe(6, Refinery.class);
|
||||||
recipe.addInput(Sulfur,5);
|
recipe.addInput(Sulfur, 5);
|
||||||
recipe.addInput(Water,5);
|
recipe.addInput(Water, 5);
|
||||||
recipe.addOutput(SulfuricAcid, 5);
|
recipe.addOutput(SulfuricAcid, 5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(150,Manufacturer.class);
|
Recipe recipe = new Recipe(150, Manufacturer.class);
|
||||||
recipe.addInput(EncasedUraniumCell, 50);
|
recipe.addInput(EncasedUraniumCell, 50);
|
||||||
recipe.addInput(EncasedIndustrialBeam,3);
|
recipe.addInput(EncasedIndustrialBeam, 3);
|
||||||
recipe.addInput(ElectromagneticControlRod, 5);
|
recipe.addInput(ElectromagneticControlRod, 5);
|
||||||
recipe.addOutput(UraniumFuelRod,1);
|
recipe.addOutput(UraniumFuelRod, 1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(12, Blender.class);
|
Recipe recipe = new Recipe(12, Blender.class);
|
||||||
recipe.addInput(Uranium, 10);
|
recipe.addInput(Uranium, 10);
|
||||||
recipe.addInput(Concrete,3);
|
recipe.addInput(Concrete, 3);
|
||||||
recipe.addInput(SulfuricAcid, 8);
|
recipe.addInput(SulfuricAcid, 8);
|
||||||
recipe.addOutput(EncasedUraniumCell, 5);
|
recipe.addOutput(EncasedUraniumCell, 5);
|
||||||
recipe.addOutput(SulfuricAcid, 2);
|
recipe.addOutput(SulfuricAcid, 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(120,Manufacturer.class);
|
Recipe recipe = new Recipe(120, Manufacturer.class);
|
||||||
recipe.addInput(VersatileFrameWork,5);
|
recipe.addInput(VersatileFrameWork, 5);
|
||||||
recipe.addInput(ElectromagneticControlRod, 5);
|
recipe.addInput(ElectromagneticControlRod, 5);
|
||||||
recipe.addInput(Battery, 10);
|
recipe.addInput(Battery, 10);
|
||||||
recipe.addOutput(MagneticFieldGenerator,2);
|
recipe.addOutput(MagneticFieldGenerator, 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(3, Blender.class);
|
Recipe recipe = new Recipe(3, Blender.class);
|
||||||
recipe.addInput(SulfuricAcid,2.5);
|
recipe.addInput(SulfuricAcid, 2.5);
|
||||||
recipe.addInput(AluminaSolution,2);
|
recipe.addInput(AluminaSolution, 2);
|
||||||
recipe.addInput(AluminumCasing,1);
|
recipe.addInput(AluminumCasing, 1);
|
||||||
recipe.addOutput(Battery, 1);
|
recipe.addOutput(Battery, 1);
|
||||||
recipe.addOutput(Water, 1.5);
|
recipe.addOutput(Water, 1.5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(8, Assembler.class);
|
Recipe recipe = new Recipe(8, Assembler.class);
|
||||||
recipe.addInput(AlcladAluminumSheet,5);
|
recipe.addInput(AlcladAluminumSheet, 5);
|
||||||
recipe.addInput(CopperSheet,3);
|
recipe.addInput(CopperSheet, 3);
|
||||||
recipe.addOutput(HeatSink, 1);
|
recipe.addOutput(HeatSink, 1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(80, Assembler.class);
|
Recipe recipe = new Recipe(80, Assembler.class);
|
||||||
recipe.addInput(AdaptiveControlUnit,2);
|
recipe.addInput(AdaptiveControlUnit, 2);
|
||||||
recipe.addInput(SuperComputer,1);
|
recipe.addInput(SuperComputer, 1);
|
||||||
recipe.addOutput(AssemblyDirectorSystem,1);
|
recipe.addOutput(AssemblyDirectorSystem, 1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(30,Assembler.class);
|
Recipe recipe = new Recipe(30, Assembler.class);
|
||||||
recipe.addInput(Stator,3);
|
recipe.addInput(Stator, 3);
|
||||||
recipe.addInput(AILimiter,2);
|
recipe.addInput(AILimiter, 2);
|
||||||
recipe.addOutput(ElectromagneticControlRod,2);
|
recipe.addOutput(ElectromagneticControlRod, 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(10, Blender.class);
|
Recipe recipe = new Recipe(10, Blender.class);
|
||||||
recipe.addInput(HeatSink,2);
|
recipe.addInput(HeatSink, 2);
|
||||||
recipe.addInput(Rubber,2);
|
recipe.addInput(Rubber, 2);
|
||||||
recipe.addInput(Water,5);
|
recipe.addInput(Water, 5);
|
||||||
recipe.addInput(NitrogenGas,25);
|
recipe.addInput(NitrogenGas, 25);
|
||||||
recipe.addOutput(CoolingSystem,1);
|
recipe.addOutput(CoolingSystem, 1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Recipe recipe = new Recipe(40, Blender.class);
|
Recipe recipe = new Recipe(40, Blender.class);
|
||||||
recipe.addInput(HeavyModularFrame,1);
|
recipe.addInput(HeavyModularFrame, 1);
|
||||||
recipe.addInput(AluminumCasing,50);
|
recipe.addInput(AluminumCasing, 50);
|
||||||
recipe.addInput(NitrogenGas,25);
|
recipe.addInput(NitrogenGas, 25);
|
||||||
recipe.addOutput(FusedModularFrame,1);
|
recipe.addOutput(FusedModularFrame, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ package satisfactory;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import guru.nidi.graphviz.engine.Format;
|
import guru.nidi.graphviz.engine.Format;
|
||||||
import guru.nidi.graphviz.engine.Graphviz;
|
import guru.nidi.graphviz.engine.Graphviz;
|
||||||
import guru.nidi.graphviz.engine.GraphvizCmdLineEngine;
|
|
||||||
import guru.nidi.graphviz.engine.GraphvizJdkEngine;
|
|
||||||
import guru.nidi.graphviz.model.MutableGraph;
|
import guru.nidi.graphviz.model.MutableGraph;
|
||||||
import guru.nidi.graphviz.parse.Parser;
|
import guru.nidi.graphviz.parse.Parser;
|
||||||
import org.jgrapht.Graph;
|
import org.jgrapht.Graph;
|
||||||
|
|
@ -141,9 +139,7 @@ public class Test {
|
||||||
});
|
});
|
||||||
de.exportGraph(screws, new File(PLOTS + name + ".dot"));
|
de.exportGraph(screws, new File(PLOTS + name + ".dot"));
|
||||||
System.out.println(name);
|
System.out.println(name);
|
||||||
Item.production(screws).forEach((item, rate) -> {
|
Item.production(screws).forEach((item, rate) -> System.out.println("\t" + item.getName() + "\t" + rate));
|
||||||
System.out.println("\t" + item.getName() + "\t" + rate);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void javaPlot(String name) {
|
private static void javaPlot(String name) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import org.jgrapht.event.ConnectedComponentTraversalEvent;
|
||||||
import org.jgrapht.event.EdgeTraversalEvent;
|
import org.jgrapht.event.EdgeTraversalEvent;
|
||||||
import org.jgrapht.event.TraversalListener;
|
import org.jgrapht.event.TraversalListener;
|
||||||
import org.jgrapht.event.VertexTraversalEvent;
|
import org.jgrapht.event.VertexTraversalEvent;
|
||||||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
|
||||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||||
import org.jgrapht.graph.EdgeReversedGraph;
|
import org.jgrapht.graph.EdgeReversedGraph;
|
||||||
import org.jgrapht.nio.Attribute;
|
import org.jgrapht.nio.Attribute;
|
||||||
|
|
@ -15,11 +14,9 @@ import org.jgrapht.traverse.DepthFirstIterator;
|
||||||
import org.jgrapht.traverse.GraphIterator;
|
import org.jgrapht.traverse.GraphIterator;
|
||||||
import satisfactory.items.Item;
|
import satisfactory.items.Item;
|
||||||
import satisfactory.items.ProductionEdge;
|
import satisfactory.items.ProductionEdge;
|
||||||
import satisfactory.items.SumResult;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -29,7 +26,7 @@ public class Utils {
|
||||||
|
|
||||||
public static Map<Item, Integer> getRawOnly(Map<Item, Integer> totals) {
|
public static Map<Item, Integer> getRawOnly(Map<Item, Integer> totals) {
|
||||||
Map<Item, Integer> raws = new HashMap<>();
|
Map<Item, Integer> raws = new HashMap<>();
|
||||||
for (Item item : totals.keySet().stream().filter(Item::isRaw).collect(Collectors.toList())) {
|
for (Item item : totals.keySet().stream().filter(Item::isRaw).toList()) {
|
||||||
raws.put(item, totals.get(item));
|
raws.put(item, totals.get(item));
|
||||||
}
|
}
|
||||||
return raws;
|
return raws;
|
||||||
|
|
@ -52,7 +49,7 @@ public class Utils {
|
||||||
EdgeReversedGraph<Item, DefaultWeightedEdge> inverse = new EdgeReversedGraph<>(graph);
|
EdgeReversedGraph<Item, DefaultWeightedEdge> inverse = new EdgeReversedGraph<>(graph);
|
||||||
|
|
||||||
GraphIterator<Item, DefaultWeightedEdge> iterator = new DepthFirstIterator<>(inverse, target);
|
GraphIterator<Item, DefaultWeightedEdge> iterator = new DepthFirstIterator<>(inverse, target);
|
||||||
iterator.addTraversalListener(new TraversalListener<Item, DefaultWeightedEdge>() {
|
iterator.addTraversalListener(new TraversalListener<>() {
|
||||||
@Override
|
@Override
|
||||||
public void connectedComponentFinished(ConnectedComponentTraversalEvent e) {
|
public void connectedComponentFinished(ConnectedComponentTraversalEvent e) {
|
||||||
System.out.println("\tconnectedComponentFinished: " + e);
|
System.out.println("\tconnectedComponentFinished: " + e);
|
||||||
|
|
@ -105,7 +102,7 @@ public class Utils {
|
||||||
m.put("label", DefaultAttribute.createAttribute(label));
|
m.put("label", DefaultAttribute.createAttribute(label));
|
||||||
return m;
|
return m;
|
||||||
});
|
});
|
||||||
de.exportGraph(sum, new File(PLOTS +filename + ".dot"));
|
de.exportGraph(sum, new File(PLOTS + filename + ".dot"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import java.util.*;
|
||||||
|
|
||||||
public abstract class Item {
|
public abstract class Item {
|
||||||
protected boolean isRaw = false;
|
protected boolean isRaw = false;
|
||||||
private String name;
|
private final String name;
|
||||||
private Set<Recipe> recipes;
|
private final Set<Recipe> recipes;
|
||||||
private Recipe preference = null;
|
private Recipe preference = null;
|
||||||
public int sum = 0;
|
public int sum = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import org.jgrapht.Graphs;
|
||||||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
||||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||||
import satisfactory.buildings.Building;
|
import satisfactory.buildings.Building;
|
||||||
import satisfactory.buildings.production.Assembler;
|
|
||||||
import satisfactory.items.requirements.RateAccumulator;
|
import satisfactory.items.requirements.RateAccumulator;
|
||||||
import satisfactory.items.requirements.TotalAccumulator;
|
import satisfactory.items.requirements.TotalAccumulator;
|
||||||
|
|
||||||
|
|
@ -124,18 +123,19 @@ public class Recipe {
|
||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Item,Double> getByProducts(Item reference){
|
public Map<Item, Double> getByProducts(Item reference) {
|
||||||
if (!outputs.containsKey(reference)){
|
if (!outputs.containsKey(reference)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return outputs.entrySet().stream().filter(itemIntegerEntry -> isByProduct(reference, itemIntegerEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
return outputs.entrySet().stream().filter(itemIntegerEntry -> isByProduct(reference, itemIntegerEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
}
|
}
|
||||||
public boolean isByProduct(Item reference, Item test){
|
|
||||||
|
public boolean isByProduct(Item reference, Item test) {
|
||||||
return !reference.equals(test) && outputs.containsKey(reference) && outputs.containsKey(test);
|
return !reference.equals(test) && outputs.containsKey(reference) && outputs.containsKey(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Graph<Item, DefaultWeightedEdge> buildGraph(Item target) {
|
public Graph<Item, DefaultWeightedEdge> buildGraph(Item target) {
|
||||||
System.out.println("buildGraph(" + target.getName() + ") @ "+ name);
|
System.out.println("buildGraph(" + target.getName() + ") @ " + name);
|
||||||
Graph<Item, DefaultWeightedEdge> graph = new DefaultDirectedWeightedGraph<>(DefaultWeightedEdge.class);
|
Graph<Item, DefaultWeightedEdge> graph = new DefaultDirectedWeightedGraph<>(DefaultWeightedEdge.class);
|
||||||
graph.addVertex(target);
|
graph.addVertex(target);
|
||||||
target.sum += 1;
|
target.sum += 1;
|
||||||
|
|
@ -171,7 +171,7 @@ public class Recipe {
|
||||||
return productWantedPerMinute / productPerProcess;
|
return productWantedPerMinute / productPerProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getByproductRate(Item main, Item product, double production){
|
private double getByproductRate(Item main, Item product, double production) {
|
||||||
double runs = getRequiredProcessRuns(main, production);
|
double runs = getRequiredProcessRuns(main, production);
|
||||||
return product.getRecipe().outputs.get(product) * runs;
|
return product.getRecipe().outputs.get(product) * runs;
|
||||||
}
|
}
|
||||||
|
|
@ -182,14 +182,14 @@ public class Recipe {
|
||||||
Map<Item, Double> map = new HashMap<>();
|
Map<Item, Double> map = new HashMap<>();
|
||||||
Queue<Item> queue = new LinkedList<>();
|
Queue<Item> queue = new LinkedList<>();
|
||||||
queue.add(target);
|
queue.add(target);
|
||||||
map.put(target, (double) prodPerMinute);
|
map.put(target, prodPerMinute);
|
||||||
production.addVertex(target);
|
production.addVertex(target);
|
||||||
production.addEdge(target, target, new ProductionEdge(target, target, prodPerMinute, processesNeeded(target, prodPerMinute)));
|
production.addEdge(target, target, new ProductionEdge(target, target, prodPerMinute, processesNeeded(target, prodPerMinute)));
|
||||||
Set<Item> visited = new HashSet<>();
|
Set<Item> visited = new HashSet<>();
|
||||||
while (!queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
Item item = queue.remove();
|
Item item = queue.remove();
|
||||||
if (visited.contains(item)){
|
if (visited.contains(item)) {
|
||||||
System.out.println("hint: already processed " + item.getName()+ "! Skip!");
|
System.out.println("hint: already processed " + item.getName() + "! Skip!");
|
||||||
//continue;
|
//continue;
|
||||||
} else {
|
} else {
|
||||||
// next items
|
// next items
|
||||||
|
|
@ -207,7 +207,7 @@ public class Recipe {
|
||||||
System.out.println(item.getName());
|
System.out.println(item.getName());
|
||||||
if (item.getRecipe().outputs.containsKey(product)) { // TODO: method isByProduct
|
if (item.getRecipe().outputs.containsKey(product)) { // TODO: method isByProduct
|
||||||
// product is by-product, no forward dependency
|
// product is by-product, no forward dependency
|
||||||
System.out.println("BY-PRODUCT " + item.getName() + " -> " + product.getName() + "... "+ queue);
|
System.out.println("BY-PRODUCT " + item.getName() + " -> " + product.getName() + "... " + queue);
|
||||||
byProducts.add(product);
|
byProducts.add(product);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -237,9 +237,7 @@ public class Recipe {
|
||||||
}
|
}
|
||||||
visited.add(item);
|
visited.add(item);
|
||||||
}
|
}
|
||||||
map.forEach((item, aDouble) -> {
|
map.forEach((item, aDouble) -> System.out.println(item.getName() + ": " + aDouble));
|
||||||
System.out.println(item.getName() + ": " + aDouble);
|
|
||||||
});
|
|
||||||
return new SumResult(production, map);
|
return new SumResult(production, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ public class SumResult {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SumResult merge(SumResult other){
|
public SumResult merge(SumResult other) {
|
||||||
HashMap<Item, Double> map = new HashMap<>();
|
HashMap<Item, Double> map = new HashMap<>();
|
||||||
this.map.forEach(map::put);
|
map.putAll(this.map);
|
||||||
other.map.forEach((item, aDouble) -> map.merge(item,aDouble,Double::sum));
|
other.map.forEach((item, aDouble) -> map.merge(item, aDouble, Double::sum));
|
||||||
return new SumResult(merge(production, other.getProduction()), map);
|
return new SumResult(merge(production, other.getProduction()), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,8 +58,7 @@ public class SumResult {
|
||||||
graph1.vertexSet().forEach(result::addVertex);
|
graph1.vertexSet().forEach(result::addVertex);
|
||||||
graph1.edgeSet().forEach(productionEdge -> {
|
graph1.edgeSet().forEach(productionEdge -> {
|
||||||
List<ProductionEdge> collect = result.edgeSet().stream()
|
List<ProductionEdge> collect = result.edgeSet().stream()
|
||||||
.filter(productionEdge1 -> productionEdge1.hasSource(productionEdge.getSource()))
|
.filter(productionEdge1 -> productionEdge1.hasSource(productionEdge.getSource())).toList();
|
||||||
.collect(Collectors.toList());
|
|
||||||
collect.forEach(edge -> {
|
collect.forEach(edge -> {
|
||||||
Item src = result.getEdgeSource(edge);
|
Item src = result.getEdgeSource(edge);
|
||||||
Item target = result.getEdgeTarget(edge);
|
Item target = result.getEdgeTarget(edge);
|
||||||
|
|
|
||||||
|
|
@ -6,43 +6,43 @@ import satisfactory.items.Recipe;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class Accumulator<E extends Number> implements RequirementAccumulator<E>{
|
public abstract class Accumulator<E extends Number> implements RequirementAccumulator<E> {
|
||||||
protected Map<Item, E> inputs;
|
protected Map<Item, E> inputs;
|
||||||
|
|
||||||
public Accumulator(Map<Item, E> inputs) {
|
public Accumulator(Map<Item, E> inputs) {
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract E calculate(Item i, E subAmount, E amount, Map<Item, E> total);
|
protected abstract E calculate(Item i, E subAmount, E amount, Map<Item, E> total);
|
||||||
|
|
||||||
protected abstract E dequeue(Item item, E amount, Map<Item, E> totals);
|
protected abstract E dequeue(Item item, E amount, Map<Item, E> totals);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Item, E> accumulate() {
|
public Map<Item, E> accumulate() {
|
||||||
Map<Item, E> total = new HashMap<>();
|
Map<Item, E> total = new HashMap<>();
|
||||||
Map<Item, E> queue = new HashMap<>();
|
Map<Item, E> queue = new HashMap<>();
|
||||||
for (Item i : inputs.keySet()) {
|
for (Item i : inputs.keySet()) {
|
||||||
queue.put(i, inputs.get(i));
|
queue.put(i, inputs.get(i));
|
||||||
}
|
}
|
||||||
while (!queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
Item i = queue.keySet().iterator().next();
|
Item i = queue.keySet().iterator().next();
|
||||||
E amount = queue.remove(i);
|
E amount = queue.remove(i);
|
||||||
E newTotal = dequeue(i, amount, total);
|
E newTotal = dequeue(i, amount, total);
|
||||||
total.put(i,newTotal);
|
total.put(i, newTotal);
|
||||||
if (i.getRecipes().isEmpty()) {
|
if (i.getRecipes().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Recipe r = i.getRecipes().iterator().next();
|
Recipe r = i.getRecipes().iterator().next();
|
||||||
Map<Item, E> subRequirements = getRequirements(r, i);
|
Map<Item, E> subRequirements = getRequirements(r, i);
|
||||||
for (Item subItem : subRequirements.keySet()) {
|
for (Item subItem : subRequirements.keySet()) {
|
||||||
E subAmount = subRequirements.get(subItem);
|
E subAmount = subRequirements.get(subItem);
|
||||||
E newSubTotal = calculate(subItem, subAmount, amount, total);
|
E newSubTotal = calculate(subItem, subAmount, amount, total);
|
||||||
total.put(subItem, newSubTotal);
|
total.put(subItem, newSubTotal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Map<Item,E> getRequirements(Recipe r, Item i);// r.getTotalRequirements()
|
protected abstract Map<Item, E> getRequirements(Recipe r, Item i);// r.getTotalRequirements()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,28 +7,28 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class RateAccumulator extends Accumulator<Double> {
|
public class RateAccumulator extends Accumulator<Double> {
|
||||||
private Item item;
|
private final Item item;
|
||||||
|
|
||||||
public RateAccumulator(Recipe recipe, Item item) {
|
public RateAccumulator(Recipe recipe, Item item) {
|
||||||
super(new HashMap<>());
|
super(new HashMap<>());
|
||||||
recipe.getInputs().forEach((item1, integer) -> inputs.put(item1, integer));
|
inputs.putAll(recipe.getInputs());
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Double calculate(Item i, Double subAmount, Double amount, Map<Item, Double> total) {
|
protected Double calculate(Item i, Double subAmount, Double amount, Map<Item, Double> total) {
|
||||||
Double base = total.getOrDefault(i, 0.0);
|
Double base = total.getOrDefault(i, 0.0);
|
||||||
double additional = subAmount * amount * i.getProductionRate();
|
double additional = subAmount * amount * i.getProductionRate();
|
||||||
return base + additional;
|
return base + additional;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Double dequeue(Item item, Double amount, Map<Item, Double> totals) {
|
protected Double dequeue(Item item, Double amount, Map<Item, Double> totals) {
|
||||||
return totals.getOrDefault(item, 0.0) + amount;
|
return totals.getOrDefault(item, 0.0) + amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<Item, Double> getRequirements(Recipe r, Item i) {
|
protected Map<Item, Double> getRequirements(Recipe r, Item i) {
|
||||||
return r.getRequirementRates(i);
|
return r.getRequirementRates(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@ import satisfactory.items.Item;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface RequirementAccumulator<E extends Number> {
|
public interface RequirementAccumulator<E extends Number> {
|
||||||
Map<Item, E> accumulate();
|
Map<Item, E> accumulate();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,25 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class TotalAccumulator extends Accumulator<Double>{
|
public class TotalAccumulator extends Accumulator<Double> {
|
||||||
|
|
||||||
public TotalAccumulator(Map<Item, Double> inputs) {
|
public TotalAccumulator(Map<Item, Double> inputs) {
|
||||||
super(inputs);
|
super(inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Double calculate(Item i, Double subAmount, Double amount, Map<Item, Double> total) {
|
protected Double calculate(Item i, Double subAmount, Double amount, Map<Item, Double> total) {
|
||||||
return total.getOrDefault(i, 0.0) + subAmount * amount;
|
return total.getOrDefault(i, 0.0) + subAmount * amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Double dequeue(Item item, Double amount, Map<Item, Double> totals) {
|
protected Double dequeue(Item item, Double amount, Map<Item, Double> totals) {
|
||||||
return totals.getOrDefault(item, 0.0) + amount;
|
return totals.getOrDefault(item, 0.0) + amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<Item, Double> getRequirements(Recipe r, Item i) {
|
protected Map<Item, Double> getRequirements(Recipe r, Item i) {
|
||||||
return r.getTotalRequirements();
|
return r.getTotalRequirements();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public abstract class Fluid extends Item {
|
public abstract class Fluid extends Item {
|
||||||
|
|
||||||
public Fluid(String name, Recipe... recipes) {
|
public Fluid(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Fluid(String name) {
|
public Fluid(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class Gas extends Item {
|
public class Gas extends Item {
|
||||||
|
|
||||||
public Gas(String name, Recipe... recipes) {
|
public Gas(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gas(String name) {
|
public Gas(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class Ingot extends Item {
|
public class Ingot extends Item {
|
||||||
|
|
||||||
public Ingot(String name, Recipe... recipes) {
|
public Ingot(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ingot(String name) {
|
public Ingot(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class Ore extends Item {
|
public class Ore extends Item {
|
||||||
|
|
||||||
public Ore(String name, Recipe... recipes) {
|
public Ore(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ore(String name) {
|
public Ore(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class Part extends Item {
|
public class Part extends Item {
|
||||||
|
|
||||||
public Part(String name, Recipe... recipes) {
|
public Part(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Part(String name) {
|
public Part(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class Pickup extends Item {
|
public class Pickup extends Item {
|
||||||
|
|
||||||
public Pickup(String name, Recipe... recipes) {
|
public Pickup(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pickup(String name) {
|
public Pickup(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class ProcessedFluid extends Fluid {
|
public class ProcessedFluid extends Fluid {
|
||||||
|
|
||||||
public ProcessedFluid(String name, Recipe... recipes) {
|
public ProcessedFluid(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessedFluid(String name) {
|
public ProcessedFluid(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class RawFluid extends Fluid {
|
public class RawFluid extends Fluid {
|
||||||
|
|
||||||
public RawFluid(String name, Recipe... recipes) {
|
public RawFluid(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawFluid(String name) {
|
public RawFluid(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
setIsRaw();
|
setIsRaw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import satisfactory.items.Recipe;
|
||||||
|
|
||||||
public class Tool extends Item {
|
public class Tool extends Item {
|
||||||
|
|
||||||
public Tool(String name, Recipe... recipes) {
|
public Tool(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tool(String name) {
|
public Tool(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package satisfactory.items;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import satisfactory.Database;
|
import satisfactory.Database;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class DatabaseTest {
|
public class DatabaseTest {
|
||||||
|
|
@ -9,7 +10,7 @@ public class DatabaseTest {
|
||||||
void testWaterPreference() {
|
void testWaterPreference() {
|
||||||
Item i = Database.Water;
|
Item i = Database.Water;
|
||||||
assertSame(i.getPreference(), i.getRecipe());
|
assertSame(i.getPreference(), i.getRecipe());
|
||||||
assertTrue(i.getPreference() == i.getRecipe());
|
assertSame(i.getPreference(), i.getRecipe());
|
||||||
assertTrue(i.getRecipe().toString().contains("water pump thingy"));
|
assertTrue(i.getRecipe().toString().contains("water pump thingy"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue