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