コード例 #1
0
        public void IteratorReturnsOnlyRefineriesAbleToProduceIngotType()
        {
            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),
                Refinery.Get(Mocks.MockRefinery(), Constants.REFINERY_TYPES.Single(t => t.BlockDefinitionName.EndsWith("Blast Furnace")), 1),
                Refinery.Get(Mocks.MockRefinery(), Constants.REFINERY_TYPES.Single(t => t.BlockDefinitionName.EndsWith("LargeRefinery")), 1)
            });

            IRefineryIterator iterator;

            Assert.True(worklist.TrySelectIngot(new ItemType("Ingot/Gold"), out iterator));

            Assert.True(iterator.CanAllocate());
            Assert.That(iterator.Current.BlockDefinitionString, Does.EndWith("LargeRefinery"));

            iterator.Next();

            Assert.True(iterator.CanAllocate());
            Assert.That(iterator.Current.BlockDefinitionString, Does.EndWith("LargeRefinery"));

            iterator.Next();

            Assert.False(iterator.CanAllocate());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }