chiark / gitweb /
lowering: Get state transition right for non-heavy targets
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 19 Jul 2021 02:05:59 +0000 (03:05 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 19 Jul 2021 23:29:54 +0000 (00:29 +0100)
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 <ijackson@chiark.greenend.org.uk>
templates/script.ts

index afa0414a9c24cb196cb7889aa19878be5cff5d0c..1a898ce0fd88a36f6d69ec67943db2fdbec93d6e 100644 (file)
@@ -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 &&