Prune State-Space: Don't identify blocks based on IDs, just use their positions

This commit is contained in:
2025-08-30 16:58:48 +02:00
parent 478fa10afd
commit 847d61ecca
6 changed files with 78 additions and 231 deletions

View File

@ -9,10 +9,7 @@ import { cross_three } from "./initial_states/cross_three.js";
import {
get_moves,
block_is_movable,
index_of_state,
remove_block,
move_block,
insert_block,
move_state_block,
arrays_are_equal,
} from "./state.js";
@ -112,53 +109,27 @@ const move = (states, data, state, block, direction) => {
return [null, null];
}
// let new_state = remove_block(state, block);
// let new_block = move_block(block, direction);
// insert_block(new_state, block);
let new_state = structuredClone(state);
delete new_state.name;
let new_block = move_block(block, direction);
move_state_block(new_state, block, direction);
let new_link = null;
const new_link = {
source: key_of(state), // We're coming from this state...
target: key_of(new_state), // ...and ended up here, at a previous state.
};
let new_node = null;
if (states.has(new_state)) {
// We already had this state, just generate a link
new_link = {
source: key_of(state), // We're coming from this state...
target: key_of(new_state), // ...and ended up here, at a previous state.
};
} else {
if (!states.has(new_state)) {
states.add(new_state);
new_node = {
id: key_of(new_state),
};
new_link = {
source: key_of(state), // We're coming from this state...
target: key_of(new_state), // ...and ended up here, at a new state.
};
}
// TODO: Faster without this?
const has_link = (data, link) => {
// for (let l of data.links) {
// if (l.source.id === link.source && l.target.id === link.target) {
// return true;
// }
// if (l.source.id === link.target && l.target.id === link.source) {
// return true;
// }
// }
return false;
};
data.links.push(new_link);
if (new_node !== null) {
data.nodes.push(new_node);
data.links.push(new_link);
} else if (!has_link(data, new_link)) {
data.links.push(new_link);
}
return [new_state, new_block];