AssemblyCSharp.RecipeGroups.TestMatch C# (CSharp) Method

TestMatch() public method

public TestMatch ( List groups ) : float
groups List
return float
        public float TestMatch(List<WeightedGroupItem> groups)
        {
            var result = 0.0f;
            var recipeComponents = new List<WeightedValue> (Groups);
            PSDebug.Log("TestMatch: {1} vs {0}", recipeComponents.ToDebugString(), groups.ToDebugString());
            foreach (var testItem in groups) {
                WeightedValue softMatch = null;
                foreach (var wv in recipeComponents) {
                    var match = wv.Match (testItem);
                    if (match == 2) {
                        recipeComponents.Remove (wv);
                        result += testItem.Weight * wv.Weight;
                        PSDebug.Log("Adding hard match: {0}, result = {1}, item weight = {2}, recipe weight = {3}",
                            testItem.Name, result, testItem.Weight, wv.Weight);
                        softMatch = null;
                        break;
                    } else if (match == 1) {
                        softMatch = wv;
                    }
                }

                if (softMatch != null) {
                    recipeComponents.Remove (softMatch);
                    result += testItem.Weight * softMatch.Weight;
                }
            }

            return recipeComponents.IsEmpty() ? result : 0;
        }

Usage Example

コード例 #1
0
        public float TestRecipe(IRecipe recipe)
        {
            float result = 0.0f;
            var sp = new RecipeGroups (recipe.GetGroups ());

            foreach (var permutation in _resultPermutations) {
                var match = sp.TestMatch (permutation);
                if (match > 0) {
                    result = Math.Max (result, match);
                }
            }

            return result;
        }