/** Chebyshev distance between tile centres (0 = same tile). */ export function chebyshevTileDistance (ax, ay, bx, by) { return Math.max(Math.abs(ax - bx), Math.abs(ay - by)); } /** Orthogonal or diagonal neighbour — not the same tile. Block interaction range. */ export function isAdjacentTile (ax, ay, bx, by) { return chebyshevTileDistance(ax, ay, bx, by) === 1; } export function isSameTile (ax, ay, bx, by) { return ax === bx && ay === by; } /** True when blockType exists on a tile adjacent to (tileX, tileY), not on that tile. */ export function hasAdjacentBlockType (getBlockTypeAt, tileX, tileY, blockType) { for (let dy = -1; dy <= 1; dy++) { for (let dx = -1; dx <= 1; dx++) { if (dx === 0 && dy === 0) { continue; } if (getBlockTypeAt(tileX + dx, tileY + dy) === blockType) { return true; } } } return false; }