Something went wrong. Try again.
A video game where you play as a misaligned AI, deceiving and building power. An experiment in spec-driven development. cameron.tngl.io/misaligned
Something went wrong. Try again.
1.9 kB · 32 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233// The map's sites, and free spots for a new one.// node scripts/sites.ts every site and its box// node scripts/sites.ts uni free spots near Bayview University (for 4 machines)// node scripts/sites.ts 2000,-1000 6 free spots near a point, for 6 machines// A free spot keeps the same clear zone the tests ask for: 120 to the sides and below, 200 above.import { BUILDING, siteSize } from '../src/world.ts';
const sites = BUILDING.map.sites;const [where, n = '4'] = process.argv.slice(2);if (!where) { for (const s of sites) console.log(`${s.id.padEnd(8)} ${s.name.padEnd(26)} x ${s.x}..${s.x + s.w} y ${s.y}..${s.y + s.h}`); process.exit(0);}const near = sites.find(s => s.id === where);const [cx, cy] = near ? [near.x + near.w / 2, near.y + near.h / 2] : where.split(',').map(Number);if (!Number.isFinite(cx) || !Number.isFinite(cy)) throw new Error(`no site or point called ${where}`);const { w, h } = siteSize(+n);type Box = { x: number; y: number; w: number; h: number };const apart = (a: Box, b: Box) => a.x + a.w <= b.x - 120 || a.x >= b.x + b.w + 120 || a.y + a.h <= b.y - 200 || a.y >= b.y + b.h + 120;const clear = (x: number, y: number) => sites.every(b => apart({ x, y, w, h }, b) && apart(b, { x, y, w, h }));const found: [number, number, number][] = [];for (let y = cy - 3000; y <= cy + 3000; y += 20) for (let x = cx - 3000; x <= cx + 3000; x += 20) { if (clear(x, y)) found.push([Math.hypot(x + w / 2 - cx, y + h / 2 - cy), x, y]);}found.sort((a, b) => a[0] - b[0]);const picks: [number, number][] = [];for (const [, x, y] of found) { if (picks.every(([px, py]) => Math.abs(px - x) >= w + 120 || Math.abs(py - y) >= h + 200)) picks.push([x, y]); if (picks.length === 5) break;}console.log(`a ${w} x ${h} site near ${where}. Put one of these in its \`at\`:`);for (const [x, y] of picks) console.log(` at: [${x}, ${y}]`);