public void SilverAndCobalt2() { var cobalt = new Blueprint("CobaltOreToIngot", 1, new ItemAndQuantity("Ore/Cobalt", 0.25), new ItemAndQuantity("Ingot/Cobalt", 0.075)); var silver = new Blueprint("SilverOreToIngot", 1, new ItemAndQuantity("Ore/Silver", 1), new ItemAndQuantity("Ingot/Silver", 0.1)); var stockpiles = new IngotStockpiles(new[] { new IngotStockpile(new IngotType("Ingot/Cobalt", 220) { ProductionNormalisationFactor = 0.075 }), new IngotStockpile(new IngotType("Ingot/Silver", 10) { ProductionNormalisationFactor = 0.1 }) }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateAssemblerSpeed(10); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/Cobalt", 220 }, { "Ingot/Silver", 10 } }); ingotWorklist.Initialise(); var cobaltScore = ingotWorklist.ScoreBlueprint(cobalt); var silverScore = ingotWorklist.ScoreBlueprint(silver); Assert.That(silverScore, Is.EqualTo(cobaltScore).Within(0.01).Percent); }
public void AllocatesWork() { var state = new SystemState(staticState); var worklist = new RefineryWorklist(staticState.OreTypes, staticState.IngotTypes, staticState.RefineryFactory, staticState.Blueprints); worklist.Initialise(new List <Refinery> { Refinery.Get(Mocks.MockRefinery(), Constants.REFINERY_TYPES.Single(t => t.BlockDefinitionName.EndsWith("LargeRefinery")), 1), }); var ingotWorklist = new IngotWorklist(state.Ingots); var inventoryScanner = new InventoryScanner(staticState.IngotTypes.AllIngotItemTypes, staticState.OreTypes.All); inventoryScanner.Ore[new ItemType("Ore/Iron")] = new List <OreDonor> { CreateOreDonor(new ItemType("Ore/Iron"), 4000) }; state.Ingots.UpdateQuantities(new Dictionary <ItemType, double>()); // No existing ingots. ingotWorklist.Initialise(); var refineryWorkAllocator = new RefineryWorkAllocator(worklist, inventoryScanner.Ore); var allocated = refineryWorkAllocator.AllocateSingle(ingotWorklist); Assert.True(allocated); }
public void SilverAndCobalt() { var stockpiles = new IngotStockpiles(new[] { new IngotStockpile(new IngotType("Ingot/Cobalt", 220) { ProductionNormalisationFactor = 0.075 }), new IngotStockpile(new IngotType("Ingot/Silver", 10) { ProductionNormalisationFactor = 0.1 }) }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateAssemblerSpeed(10); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/Cobalt", 275 }, { "Ingot/Silver", 34 } }); ingotWorklist.Initialise(); IngotStockpile preferred; Assert.That(ingotWorklist.TryGetPreferred(out preferred)); Assert.That(preferred.Ingot.ItemType, Is.EqualTo(new ItemType("Ingot/Cobalt"))); }
public void IronAndGold() { var stockpiles = new IngotStockpiles(new[] { new IngotStockpile(new IngotType("Ingot/Gold", 5) { ProductionNormalisationFactor = 0.025 }), new IngotStockpile(new IngotType("Ingot/Iron", 80) { ProductionNormalisationFactor = 14 }) }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateAssemblerSpeed(10); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/Gold", 27 }, { "Ingot/Iron", 15000 } }); ingotWorklist.Initialise(); IngotStockpile preferred; Assert.That(ingotWorklist.TryGetPreferred(out preferred)); Assert.That(preferred.Ingot.ItemType, Is.EqualTo(new ItemType("Ingot/Gold"))); }
public void AssignedWorkAffectsQuotaFactor() { var blueprint = new Blueprint("A", 1, new ItemAndQuantity("Ore/A", 10), new ItemAndQuantity("Ingot/A", 10)); var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/A", 100 } }); var ingotWorklist = new IngotWorklist(stockpiles); var refinery = Refinery.Get(mockRefinery, new RefineryType("Refinery") { SupportedBlueprints = { "A" } }, 1); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/A", 50 } }); ingotWorklist.Initialise(); IngotStockpile preferred; Assume.That(ingotWorklist.TryGetPreferred(out preferred)); Assume.That(preferred.EstimatedProduction, Is.EqualTo(0)); var initialQuotaFraction = preferred.QuotaFraction; ingotWorklist.UpdateStockpileEstimates(refinery, blueprint, 5); IngotStockpile updatedPreferred; Assume.That(ingotWorklist.TryGetPreferred(out updatedPreferred)); Assert.That(updatedPreferred.QuotaFraction, Is.GreaterThan(initialQuotaFraction)); Assert.That(updatedPreferred.EstimatedProduction, Is.GreaterThan(0)); }
public void HighYieldBlueprintScoresHigherThanLowYieldBlueprint() { var blueprintALow = new Blueprint("ALow", 1, new ItemAndQuantity("Ore/A", 10), new ItemAndQuantity("Ingot/A", 10)); var blueprintAHigh = new Blueprint("AHigh", 1, new ItemAndQuantity("Ore/A", 10), new ItemAndQuantity("Ingot/A", 12)); var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/A", 100 } }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/A", 50 } }); ingotWorklist.Initialise(); var aLowScore = ingotWorklist.ScoreBlueprint(blueprintALow); var aHighScore = ingotWorklist.ScoreBlueprint(blueprintAHigh); Assert.That(aHighScore, Is.GreaterThan(aLowScore)); }
public void ZeroStockpileDoesNotCauseAllYieldingBlueprintsToBeScoredEqually() { var blueprintALow = new Blueprint("ALow", 1, new ItemAndQuantity("Ore/A", 10), new ItemAndQuantity("Ingot/A", 10)); var blueprintAHigh = new Blueprint("AHigh", 1, new ItemAndQuantity("Ore/A", 10), new ItemAndQuantity("Ingot/A", 12)); var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/A", 100 } }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/A", 0 } }); ingotWorklist.Initialise(); var aLowScore = ingotWorklist.ScoreBlueprint(blueprintALow); var aHighScore = ingotWorklist.ScoreBlueprint(blueprintAHigh); Assert.That(aHighScore, Is.GreaterThan(aLowScore)); }
public void ToleratesBlueprintsWithUnknownIngotTypes() { var blueprint = new Blueprint("A", 1, new ItemAndQuantity("Ore/A", 10), new ItemAndQuantity("Ingot/A", 10)); var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/B", 100 } }); var ingotWorklist = new IngotWorklist(stockpiles); var refinery = Refinery.Get(mockRefinery, new RefineryType("Refinery") { SupportedBlueprints = { "A" } }, 1); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/B", 20 } }); ingotWorklist.Initialise(); ingotWorklist.ScoreBlueprint(blueprint); ingotWorklist.UpdateStockpileEstimates(refinery, blueprint, 5); }
public void UpdatingStockpilesUpdatesPreferredIngotType() { var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/A", 10 }, { "Ingot/B", 100 } }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/A", 5 }, // 50% { "Ingot/B", 10 } // 10% }); ingotWorklist.Initialise(); ingotWorklist.UpdateStockpileEstimates(Util.DefaultRefinery, Util.DefaultBlueprintProducing("Ingot/B"), 100); IngotStockpile preferred; Assert.That(ingotWorklist.TryGetPreferred(out preferred)); Assert.That(preferred.Ingot.ItemType, Is.EqualTo(new ItemType("Ingot/A"))); }
public void InitialPreferredIngotTypeIsFurthestFromTarget() { var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/A", 10 }, { "Ingot/B", 100 }, { "Ingot/C", 20 }, { "Ingot/D", 8 } }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/A", 5 }, // 50% { "Ingot/B", 10 }, // 10% { "Ingot/C", 8 }, // 40% { "Ingot/D", 12 } // 150% }); ingotWorklist.Initialise(); IngotStockpile preferred; Assume.That(ingotWorklist.TryGetPreferred(out preferred)); Assert.That(preferred.Ingot.ItemType, Is.EqualTo(new ItemType("Ingot/B"))); }
public void BlueprintWithAllOutputsInDemandScoresHigherThanBlueprintWithOnlyOneOutputInDemand() { var blueprintAB = new Blueprint("AB", 1, new ItemAndQuantity("Ore/AB", 10), new ItemAndQuantity("Ingot/A", 10), new ItemAndQuantity("Ingot/B", 10)); var blueprintBC = new Blueprint("BC", 1, new ItemAndQuantity("Ore/BC", 10), new ItemAndQuantity("Ingot/B", 10), new ItemAndQuantity("Ingot/C", 10)); var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/A", 100 }, { "Ingot/B", 100 }, { "Ingot/C", 100 } }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/A", 500 }, // Not in demand. { "Ingot/B", 50 }, { "Ingot/C", 50 } }); ingotWorklist.Initialise(); var abScore = ingotWorklist.ScoreBlueprint(blueprintAB); var bcScore = ingotWorklist.ScoreBlueprint(blueprintBC); Assert.That(bcScore, Is.GreaterThan(abScore)); }
public void SkippingLastStockpileLeavesEmptyWorklist() { var stockpiles = new IngotStockpiles(new TestIngotDefinitions { { "Ingot/A", 10 }, { "Ingot/B", 100 } }); var ingotWorklist = new IngotWorklist(stockpiles); stockpiles.UpdateQuantities(new TestIngotQuantities { { "Ingot/A", 5 }, // 50% { "Ingot/B", 10 } // 10% }); ingotWorklist.Initialise(); ingotWorklist.UpdateStockpileEstimates(Util.DefaultRefinery, Util.DefaultBlueprintProducing("Ingot/B"), 100); IngotStockpile preferred; Assume.That(ingotWorklist.TryGetPreferred(out preferred)); ingotWorklist.Skip(); Assume.That(ingotWorklist.TryGetPreferred(out preferred)); ingotWorklist.Skip(); Assert.That(ingotWorklist.TryGetPreferred(out preferred), Is.False); }