Changes
This commit is contained in:
parent
0c2d27be18
commit
1d160659d4
1 changed files with 9 additions and 29 deletions
|
|
@ -282,35 +282,15 @@ const defendAttack = (guards: Set<string>, attack: Position): {
|
||||||
shiftBorderToFillGap(newGuards, movements, currentGap);
|
shiftBorderToFillGap(newGuards, movements, currentGap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 3: Check if we need a second chain (Figure 10 shows two chains)
|
// NOTE: The paper's strategy restores the original configuration via the border "patchwork"
|
||||||
// This happens when the attack disrupts multiple domination lines
|
// (complementary paths) rather than ad-hoc re-domination fixes.
|
||||||
|
//
|
||||||
// Find interior positions that are now undominated and need filling
|
// The previous implementation included an extra "scan for undominated vertices and move a nearby guard"
|
||||||
for (let x = 1; x < COLS - 1; x++) {
|
// step, which can look like guards "manifest" and is not part of the Figure 10 defense.
|
||||||
for (let y = 2; y < ROWS - 2; y++) {
|
|
||||||
if (!isDominated(x, y, newGuards)) {
|
// Safety: guards are never created/destroyed—only moved.
|
||||||
// Need to get a guard here
|
if (newGuards.size !== guards.size) return null;
|
||||||
const nbs = getHexNeighbors(x, y);
|
|
||||||
const nearbyGuard = nbs.find(n => newGuards.has(posKey(n)) && isInterior(n.x, n.y));
|
|
||||||
|
|
||||||
if (nearbyGuard) {
|
|
||||||
newGuards.delete(posKey(nearbyGuard));
|
|
||||||
newGuards.add(posKey({ x, y }));
|
|
||||||
movements.push({ from: nearbyGuard, to: { x, y }, type: 'interior' });
|
|
||||||
} else {
|
|
||||||
// Use border guard
|
|
||||||
const borderGuard = nbs.find(n => newGuards.has(posKey(n)) && isBorder(n.x, n.y));
|
|
||||||
if (borderGuard) {
|
|
||||||
newGuards.delete(posKey(borderGuard));
|
|
||||||
newGuards.add(posKey({ x, y }));
|
|
||||||
movements.push({ from: borderGuard, to: { x, y }, type: 'toInterior' });
|
|
||||||
shiftBorderToFillGap(newGuards, movements, borderGuard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { newGuards, movements };
|
return { newGuards, movements };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue