about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-10-30 11:57:44 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-10-30 11:57:44 -0700
commit761a3036e76b796a304e855b0676f5ca128120e1 (patch)
treee81c85b892de40c15bb1635d1d8fa6b8937aed89
parentc610aec051c1ca6220fefc0a7255a97702fe828d (diff)
downloadmu-761a3036e76b796a304e855b0676f5ca128120e1.tar.gz
4094
-rw-r--r--056shape_shifting_recipe.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/056shape_shifting_recipe.cc b/056shape_shifting_recipe.cc
index 8714a5e9..fceb6672 100644
--- a/056shape_shifting_recipe.cc
+++ b/056shape_shifting_recipe.cc
@@ -133,9 +133,7 @@ recipe_ordinal best_shape_shifting_variant(const instruction& inst, vector<recip
     int score1 = number_of_concrete_type_names(candidates.at(i));
     assert(score1 <= max_score);
     if (score1 != max_score) continue;
-    const recipe& candidate = get(Recipe, candidates.at(i));
-    int score2 = (SIZE(candidate.products)-SIZE(inst.products))
-                           + (SIZE(inst.ingredients)-SIZE(candidate.ingredients));
+    int score2 = shape_shifting_tiebreak_heuristic(inst, candidates.at(i));
     assert(score2 < 999);
     if (score2 < min_score2) {
       min_score2 = score2;
@@ -145,6 +143,12 @@ recipe_ordinal best_shape_shifting_variant(const instruction& inst, vector<recip
   return candidates.at(best_index);
 }
 
+int shape_shifting_tiebreak_heuristic(const instruction& inst, const recipe_ordinal candidate) {
+  const recipe& r = get(Recipe, candidate);
+  return (SIZE(r.products) - SIZE(inst.products))
+       + (SIZE(inst.ingredients) - SIZE(r.ingredients));
+}
+
 bool any_type_ingredient_in_header(recipe_ordinal variant) {
   const recipe& caller = get(Recipe, variant);
   for (int i = 0;  i < SIZE(caller.ingredients);  ++i) {