old_z: &'o ZCoord,
new_z: &'n ZCoord,
target: bool,
- bottom: bool,
+ heavy: bool,
updated: bool,
}
let new_z = new_z.unwrap_or(&start.z);
PieceCollated {
id, new_z, old_z, updated,
- bottom: start.bottom(),
+ heavy: start.heavy(),
target: self.targets.contains(&id),
}
}).collect_vec();
print!(" {:5} {}{}{} ",
p.id.to_string(),
if p.target { "T" } else { "_" },
- if p.bottom { "B" } else { "_" },
+ if p.heavy { "H" } else { "_" },
if p.updated { "U" } else { "_" });
};
pr(o);
println!("{}" , n.new_z.as_str());
}
- // non-bottom targets are in same stacking order as before
- // bottom targets are in same stacking order as before
+ // light targets are in same stacking order as before
+ // heavy targets are in same stacking order as before
{
- for &want_bottom in &[false, true] {
+ for &want_heavy in &[false, true] {
for (o, n) in izip!(
- old.iter().filter(|p| p.target && p.bottom == want_bottom),
- new.iter().filter(|p| p.target && p.bottom == want_bottom),
+ old.iter().filter(|p| p.target && p.heavy == want_heavy),
+ new.iter().filter(|p| p.target && p.heavy == want_heavy),
) {
assert_eq!(o.id, n.id);
}
}
}
- // no bottom are newly above non-bottom
+ // no heavy are newly above light
{
- let misbottom = |on: &[&PieceCollated]| {
- let mut misbottom = HashSet::new();
+ let misheavy = |on: &[&PieceCollated]| {
+ let mut misheavy = HashSet::new();
for i in 0..on.len() {
for j in i+1..on.len() {
// j is above i
- if on[j].bottom && ! on[i].bottom {
- // bottom above non-bottom
- misbottom.insert((on[j].id, on[i].id));
+ if on[j].heavy && ! on[i].heavy {
+ // heavy above light
+ misheavy.insert((on[j].id, on[i].id));
}
}
}
- misbottom
+ misheavy
};
- let old = misbottom(&old);
- let new = misbottom(&new);
+ let old = misheavy(&old);
+ let new = misheavy(&new);
let newly = new.difference(&old).collect_vec();
assert!( newly.is_empty(), "{:?}", &newly );
}
- // no non-bottom non-targets moved
+ // no light non-targets moved
{
for n in &new {
- if ! n.bottom && ! n.target {
+ if ! n.heavy && ! n.target {
assert!( ! n.updated, "{:?}", n );
}
}
}
- // z coords (at least of bottom) in updates all decrease
+ // z coords (at least of heavy) in updates all decrease
{
for n in &new {
- if n.bottom && n.updated {
+ if n.heavy && n.updated {
assert!( n.new_z < n.old_z, "{:?}", &n );
}
}
}
- // all targets now below all non-bottom non-targets
+ // all targets now below all light non-targets
{
- let mut had_nonbottom_nontarget = None;
+ let mut had_light_nontarget = None;
for n in &new {
- if ! n.bottom && ! n.target {
- had_nonbottom_nontarget = Some(n);
+ if ! n.heavy && ! n.target {
+ had_light_nontarget = Some(n);
}
if n.target {
- assert!( had_nonbottom_nontarget.is_none(),
- "{:?} {:?}", &n, had_nonbottom_nontarget);
+ assert!( had_light_nontarget.is_none(),
+ "{:?} {:?}", &n, had_light_nontarget);
}
}
}
- // all bottom targets now below all non-targets
+ // all heavy targets now below all non-targets
{
let mut had_nontarget = None;
for n in &new {
if ! n.target {
had_nontarget = Some(n);
}
- if n.bottom && n.target {
+ if n.heavy && n.target {
assert!( had_nontarget.is_none(),
"{:?} {:?}", &n, had_nontarget);
}
}
impl StartPiece {
- pub fn bottom(&self) -> bool {
+ pub fn heavy(&self) -> bool {
use PieceMoveable::*;
match (self.pinned, self.moveable) {
(true , _ ) => true,
println!(" {:5} {}{} {}",
id.to_string(),
if targets.contains(id) { "T" } else { "_" },
- if p.bottom() { "B" } else { "_" },
+ if p.heavy() { "H" } else { "_" },
p.z.as_str());
}
type LowerTodoItem = {
piece: PieceId,
p: PieceInfo,
- bottom: boolean,
+ heavy: boolean,
};
type LowerTodoList = { [piece: string]: LowerTodoItem };
keyops_local['lower'] = function (uo: UoRecord) { lower_targets(uo); }
-function lower_treat_bottom(p: PieceInfo): boolean {
+function lower_heavy(p: PieceInfo): boolean {
return wresting || p.pinned || p.moveable == "No";
}
for (let piece of uo.targets!) {
let p = pieces[piece]!;
- let bottom = lower_treat_bottom(p);
- targets_todo[piece] = { p, piece, bottom, };
+ let heavy = lower_heavy(p);
+ targets_todo[piece] = { p, piece, heavy, };
}
let problem = lower_pieces(targets_todo);
if (problem !== null) {
function lower_pieces(targets_todo: LowerTodoList):
string | null
{
- // This is a bit subtle. We don't want to lower below bottom pieces
- // (unless we are bottom too, or the user is wresting). But maybe
- // the bottom pieces aren't already at the bottom. For now we will
- // declare that all bottom pieces "should" be below all non-bottom
+ // This is a bit subtle. We don't want to lower below heavy pieces
+ // (unless we are heavy too, or the user is wresting). But maybe
+ // the heavy pieces aren't already at the bottom. For now we will
+ // declare that all heavy pieces "should" be below all light
// ones. Not as an invariant, but as a thing we will do here to try
// to make a sensible result. We implement this as follows: if we
- // find bottom pieces above non-bottom pieces, we move those bottom
+ // find heavy pieces above light pieces, we move those heavy
// pieces to the bottom too, just below us, preserving their
// relative order.
//
- // Disregarding bottom targets:
+ // Disregarding heavy targets:
//
- // Z <some stuff not including any unbottom targets>
+ // Z <some stuff not including any unheavy targets>
// Z
- // topmost unbottom target *
+ // topmost unheavy target *
// B (
- // B unbottom non-target
- // B | unbottom target *
- // B | bottom non-target, mis-stacked *
+ // B light non-target
+ // B | light target *
+ // B | heavy non-target, mis-stacked *
// B )*
// B
- // bottommost unbottom non-target
- // if that is below topmost unbottom target
- // <- tomove_unbottom: insert targets from * here Q ->
- // <- tomove_misstacked: insert non-targets from * here Q->
+ // bottommost light non-target
+ // if that is below topmost light target
+ // <- tomove_light: insert targets from * here Q ->
+ // <- tomove_misstacked: insert non-targets from * here Q ->
// A
- // A bottom things (nomove_bottom)
- // <- tomove_bottom: insert all bottom targets here P ->
+ // A heavy things (nomove_heavy)
+ // <- tomove_heavy: insert all heavy targets here P ->
//
- // When wresting, treat all targets as bottom.
+ // When wresting, treat all targets as heavy.
type Entry = {
piece: PieceId,
p: PieceInfo,
};
// bottom of the stack order first
- let tomove_unbottom : Entry[] = [];
- let tomove_misstacked : Entry[] = [];
- let nomove_bottom : Entry[] = [];
- let tomove_bottom : Entry[] = [];
- let bottommost_unbottom : Entry | null = null;
+ let tomove_light : Entry[] = [];
+ let tomove_misstacked : Entry[] = [];
+ let nomove_heavy : Entry[] = [];
+ let tomove_heavy : Entry[] = [];
+ let bottommost_light : Entry | null = null;
- let n_targets_todo_unbottom = 0;
+ let n_targets_todo_light = 0;
let any_targets = false;
for (const piece of Object.keys(targets_todo)) {
any_targets = true;
let p = targets_todo[piece];
- if (!p.bottom) n_targets_todo_unbottom++;
+ if (!p.heavy) n_targets_todo_light++;
}
if (!any_targets) return 'Nothing to lower!';
let walk = pieces_marker;
for (;;) { // starting at the bottom of the stack order
- if (n_targets_todo_unbottom == 0
- && bottommost_unbottom !== null) {
- // no unbottom targets left, state Z, we can stop now
+ if (n_targets_todo_light == 0
+ && bottommost_light !== null) {
+ // no light targets left, state Z, we can stop now
console.log('LOWER STATE Z FINISHED');
break;
}
if (Object.keys(targets_todo).length == 0 &&
- bottommost_unbottom !== null) {
- console.log('LOWER NO TARGETS BUT UNBOTTOM!', n_targets_todo_unbottom);
+ bottommost_light !== null) {
+ console.log('LOWER NO TARGETS BUT LIGHT!', n_targets_todo_light);
break;
}
let todo = targets_todo[piece];
if (todo) {
- console.log('LOWER WALK', piece, 'TODO', todo.bottom ? "B" : "_");
+ console.log('LOWER WALK', piece, 'TODO', todo.heavy ? "B" : "_");
delete targets_todo[piece];
- if (!todo.bottom) n_targets_todo_unbottom--;
- (todo.bottom ? tomove_bottom : tomove_unbottom).push(todo);
+ if (!todo.heavy) n_targets_todo_light--;
+ (todo.heavy ? tomove_heavy : tomove_light).push(todo);
continue;
}
let p = pieces[piece]!;
- let p_bottom = lower_treat_bottom(p);
- if (bottommost_unbottom === null) { // state A
- if (!p_bottom) {
+ let p_heavy = lower_heavy(p);
+ if (bottommost_light === null) { // state A
+ if (!p_heavy) {
console.log('LOWER WALK', piece, 'STATE A -> Z');
- bottommost_unbottom = { p, piece };
+ bottommost_light = { p, piece };
} else {
console.log('LOWER WALK', piece, 'STATE A');
- nomove_bottom.push({ p, piece });
+ nomove_heavy.push({ p, piece });
}
continue;
}
// state B
- if (p_bottom) {
+ if (p_heavy) {
console.log('LOWER WALK', piece, 'STATE B MIS-STACKED');
tomove_misstacked.push({ p, piece });
} else {
}
let z_top =
- bottommost_unbottom ? bottommost_unbottom.p.z :
+ bottommost_light ? bottommost_light.p.z :
walk.dataset.piece != null ? pieces[walk.dataset.piece!].z :
// rather a lack of things we are not adjusting!
wasm_bindgen.def_zcoord();
let plan : PlanEntry[] = [];
- let partQ = tomove_misstacked.concat(tomove_unbottom);
- let partP = tomove_bottom;
+ let partQ = tomove_misstacked.concat(tomove_light);
+ let partP = tomove_heavy;
- if (nomove_bottom.length == 0) {
+ if (nomove_heavy.length == 0) {
plan.push({
content: partQ.concat(partP),
z_top,
plan.push({
content: partQ,
z_top,
- z_bot: nomove_bottom[nomove_bottom.length-1].p.z,
+ z_bot: nomove_heavy[nomove_heavy.length-1].p.z,
}, {
content: partP,
- z_top: nomove_bottom[0].p.z,
+ z_top: nomove_heavy[0].p.z,
z_bot: null,
});
}