From 5e307b210dc13e352ba846b794d8880a404a4314 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 19 Jul 2021 03:05:59 +0100 Subject: [PATCH] lowering: Get state transition right for non-heavy targets We would go into state B if we found any target. But that's not right: the chart says to disregard heavy targets, and indeed we don't want to stack other things below them. This can lead q_z_top legitimately being null on exit from the walk loop, if there are no pieces in B or Z. We still need a q_z_top: we can't leave it open, because we want to make sure we only lower pieces, not raise them. So we choose the lowest piece in Q, or, failing that, P. Signed-off-by: Ian Jackson --- templates/script.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/script.ts b/templates/script.ts index afa0414a..1a898ce0 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -696,7 +696,7 @@ function lower_pieces(targets_todo: LowerTodoList): let todo = targets_todo[piece]; if (todo) { let xst = ''; - if (q_z_top === null) { + if (q_z_top === null && !todo.heavy) { q_z_top = p.z; xst = 'STATE -> B'; } @@ -731,7 +731,10 @@ function lower_pieces(targets_todo: LowerTodoList): if (q_z_top === null) { // Somehow we didn't find the top of Q, so we didn't meet any // targets. (In the walk loop, we always set q_z_top if todo.) - return 'Internal error! Lower with no targets!'; + q_z_top = + tomove_misstacked.length ? tomove_misstacked[0].p.z : + tomove_light .length ? tomove_light [0].p.z : + tomove_heavy [0].p.z; } while (nomove_heavy.length && -- 2.30.2