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;
}