예제 #1
0
        public void Execute_ItemNameNoMatch_Matches()
        {
            var recipes = new[] { TestRecipes.IronBar };

            var filter = new PreferredFilter();

            filter.Add("iron gear", TestRecipes.IronGearFromIronBar);

            var matches = filter.Execute("iron bar", recipes);

            Assert.Equal(recipes, matches);
        }
예제 #2
0
        public void Execute_ItemNameMatchRecipeInstanceNoMatch_NoMatches()
        {
            var recipes = new[] { TestRecipes.IronGearFromSteel };

            var filter = new PreferredFilter();

            filter.Add("iron gear", TestRecipes.IronGearFromIronBar);

            var matches = filter.Execute("iron gear", recipes);

            Assert.Empty(matches);
        }
예제 #3
0
        public void Calculate_UnusedItems_Consumed()
        {
            var simmeredMeat = new Recipe
            {
                Products    = TestRecipes.SimmeredMeat.Products,
                Ingredients = TestRecipes.SimmeredMeat.Ingredients.Reverse().ToArray(),
                Skills      = TestRecipes.SimmeredMeat.Skills,
                Tables      = TestRecipes.SimmeredMeat.Tables
            };

            //simmeredMeat = TestRecipes.SimmeredMeat;

            var context = new TestGameContext
            {
                Player  = new Player(),
                Recipes = new RecipeStore(new[] { simmeredMeat, TestRecipes.PreparedMeat, TestRecipes.MeatStock, TestRecipes.ScrapMeat })
            };

            var filter = new PreferredFilter();

            // Scrap Meat using Raw Meat
            filter.Add("Scrap Meat", TestRecipes.ScrapMeat);

            var calculator = new CalculatorA(context);
            var parts      = calculator.Calculate("Simmered Meat", 1, filter);


            // Todo: these assertions should change when we move beyond just tracking unused, to try to use the unused.
            //var preparedMeat = Assert.Single(parts, p => p.Name == "Prepared Meat");
            //Assert.Equal(5, preparedMeat.Amount);

            //var preparedMeatUnused = Assert.Single(parts.Unused, p => p.Name == "Scrap Meat");
            //Assert.Equal(10, preparedMeatUnused.Amount);


            //var scrapMeat = Assert.Single(parts, p => p.Name == "Scrap Meat");
            //Assert.Equal(40, scrapMeat.Amount);

            //var scrapMeatUnused = Assert.Single(parts.Unused, p => p.Name == "Prepared Meat");
            //Assert.Equal(20, scrapMeatUnused.Amount);


            // When Simmered Meat recipe has Prepared Meat First OR Prepared Meat is the preferred recipe to create Scrap Meat
            //var preparedMeat = Assert.Single(parts, p => p.Name == "Prepared Meat");
            //Assert.Equal(5, preparedMeat.Amount);

            //var scrapMeat = Assert.Single(parts, p => p.Name == "Scrap Meat");
            //Assert.Equal(40, scrapMeat.Amount);

            //var scrapMeatUnused = Assert.Single(parts.Unused, p => p.Name == "Prepared Meat");
            //Assert.Equal(15, scrapMeatUnused.Amount);



            // When Simmered Meat recipe has Prepared Meat Last AND Raw Meat is the preferred recipe to create Scrap Meat
            // Whith smart ordering we should not have any unused
            var preparedMeat = Assert.Single(parts, p => p.Name == "Prepared Meat");

            Assert.Equal(5, preparedMeat.Amount);

            var scrapMeat = Assert.Single(parts, p => p.Name == "Scrap Meat");

            Assert.Equal(40, scrapMeat.Amount);

            // From creating the Prepared Meat last
            var scrapMeatUnused = Assert.Single(parts.Unused, p => p.Name == "Scrap Meat");

            Assert.Equal(10, scrapMeatUnused.Amount);
        }
예제 #4
0
        public PartsList CalculateTemp(string item, decimal quantity = 1)
        {
            var preferred = new PreferredFilter();

            // Iron Gear using Iron Bar
            preferred.Add("Iron Gear", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Iron Gear") && r.Ingredients.Any(i => i.Name == "Iron Bar")).Single());

            // Steel using Coal
            preferred.Add("Steel", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Steel") && r.Ingredients.Any(i => i.Name == "Coal")).Single());

            // Raw Meat using Bison Carcass
            preferred.Add("Raw Meat", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Raw Meat") && r.Ingredients.Any(i => i.Name == "Bison Carcass")).Single());

            // Scrap Meat using Raw Meat
            preferred.Add("Scrap Meat", _gameContext.Recipes.GetRecipes(r => r.Products.All(p => p.Name == "Scrap Meat") && r.Ingredients.Any(i => i.Name == "Raw Meat")).Single());

            // Sugar
            preferred.Add("Sugar", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Sugar")).First());

            // Vegetable Medley
            preferred.Add("Vegetable Medley", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Vegetable Medley")).First());

            // Fruit Salad
            preferred.Add("Fruit Salad", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Fruit Salad")).First());

            // Basic Salad
            preferred.Add("Basic Salad", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Basic Salad")).First());

            // Tallow
            preferred.Add("Tallow", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Tallow") && r.Ingredients.All(i => i.Name == "Raw Bacon")).Single());

            // Leather Hide
            preferred.Add("Leather Hide", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Leather Hide")).First());

            // Fur Pelt
            preferred.Add("Fur Pelt", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Fur Pelt")).First());

            // Oil
            preferred.Add("Oil", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Oil") && r.Ingredients.Any(i => i.Name == "Tallow")).Single());

            // Cereal Germ
            preferred.Add("Cereal Germ", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Cereal Germ")).First());



            var filter = new CompositeFilter
                         (
                new ProductFilter(),
                preferred
                         );


            var partsList = new PartsList();

            Calculate(item, partsList, filter, quantity);

            return(partsList);
        }