public MaterialQualityAnalyzer(Material[] recipe_materials)
 {
     _Amount = (from m in recipe_materials select m.Count).Sum();
     _Materials = (from m in recipe_materials
                       let p = m.Count / (float)_Amount
                       select new MaterialInfomation { Proportion = p, Material = m }).ToArray();
 }
Example #2
0
        public Item Get(Material[] materials)
        {
            var quality = _Analyzer.GetQuality(materials);

            var effectBuilder = _EffectBuilder;
            /*var effects = effectBuilder.Get(quality);

            return _Make(_ItemId , effects);*/

            return new Item();
        }
        public void GetQualityTest1()
        {
            var materials = new Material[] { new Material { Id = 1 , Count = 5},
                                            new Material { Id = 2 , Count = 4},
                                            new Material { Id = 3 , Count = 1}};
            var recipeMaterials = new Material[] { new Material { Id = 1 , Count = 5},
                                            new Material { Id = 2 , Count = 4},
                                            new Material { Id = 3 , Count = 1}};
            var recipe = new MaterialQualityAnalyzer(recipeMaterials);
            var quality = recipe.GetQuality(materials);
            var eQuality = 1.0f;

            Assert.AreEqual(quality, eQuality);
        }
        public void GetQualityTest()
        {
            var materials = new Material[] { new Material { Id = 1 , Count = 1},
                                            new Material { Id = 2 , Count = 7},
                                            new Material { Id = 3 , Count = 2}};
            var recipeMaterials = new Material[] { new Material { Id = 1 , Count = 5},
                                            new Material { Id = 2 , Count = 4},
                                            new Material { Id = 3 , Count = 1}};
            var recipe = new MaterialQualityAnalyzer(recipeMaterials);
            var quality = recipe.GetQuality(materials);
            var eQuality = (0.1f / 0.7f) * 0.4f + (0.7f / 0.7f) * 0.4f + (0.2f / 0.7f) * 0.4f;

            Assert.AreEqual(quality, eQuality);
        }
        public float GetQuality(Material[] materials)
        {
            var amount = _Amount;
            var proportions = _Materials;

            var amount2 = (from m in materials select m.Count).Sum();

            var proportions2 = from m in materials
                               let p = m.Count / (float)amount2
                               orderby m.Count descending
                               select new { Proportion = p, Materials = m };

            var benchmark = proportions2.FirstOrDefault();
            var baseQuality = (from p in proportions where benchmark.Materials.Id == p.Material.Id select p.Proportion).SingleOrDefault();

            float quality = 0.0f;
            foreach(var proportion in proportions2)
            {
                quality += (proportion.Proportion / benchmark.Proportion) * baseQuality;
            }

            return quality;
        }