- commit
- 074a42a750d19534b2d99642f254c5db93c9e49c
- parent
- 9907486254bfcfc174c68d689603c8c7217b1b62
- author
- dami <gazey55@gmail.com>
| M | site/ | 64 | +++++++++++++++++++++++-------- |
@@ -5,7 +5,7 @@
55 // guess one cell of the first solution and learn from the verdict.66 //77 // deno run -A scripts/solve.ts [--url http://127.0.0.1:8000/mcp] [--G 100] [--kind scatter|grid|field] [--chunks 3] [--n 14] [--seed s] [--limit 6]8-// [--join <game_id>] [--agent name] [--model m] [--strategy bfs|dfs|greedy] [--max-batches N]8+// [--join <game_id>] [--agent name] [--model m] [--strategy bfs|dfs|greedy|probe] [--max-batches N]99 // [--grow-every MIN] [--grow-coverage F] [--fog true|false] [--until-grown N]1010 //1111 // --join plays an existing field as one more agent (several solve.ts@@ -25,7 +25,11 @@ const KIND = args.kind ?? "scatter";
2525 const N_ARG = Number(args.n ?? 14);2626 const LIMIT = Number(args.limit ?? 6);2727 const CHUNKS = Number(args.chunks ?? 3);28-const STRATEGY = (args.strategy ?? "bfs") as "bfs" | "dfs" | "greedy";28+const STRATEGY = (args.strategy ?? "bfs") as29+ | "bfs"30+ | "dfs"31+ | "greedy"32+ | "probe";2933 const MAX_BATCHES = Number(args["max-batches"] ?? Infinity);3034 const AGENT_NAME = args.agent ?? `solve-${STRATEGY}`;3135 const GROW_EVERY = args["grow-every"] ? Number(args["grow-every"]) : undefined;@@ -449,20 +453,31 @@ while (obs.status !== "solved" && batches < MAX_BATCHES) {
449453 else if (known.has(id)) cells[i] = known.get(id)!;450454 else if (wrongKnown.has(id)) cells[i] = wrongKnown.get(id)!;451455 });452- const sols = enumerate(cells, shape, LIMIT);453- if (sols.length === 0) {454- throw new Error(`tile #${tile.id} has no solution from known cells`);455- }456- const common: [number, number][] = [];457- const disputed: number[] = [];458- ids.forEach((id, i) => {459- if (id < 0 || known.has(id)) return;460- const v = sols[0][i];461- if (sols.every((s) => s[i] === v)) common.push([id, v]);462- else disputed.push(i);463- });464456 let batch: [number, number][];465457 let intent: string;458+ const common: [number, number][] = [];459+ const disputed: number[] = [];460+ let sols: Int8Array[] = [];461+ if (STRATEGY === "probe") {462+ // the oracle exploit, kept as the regression for health: no deduction,463+ // every unknown cell as 0, then the complements of the rejections464+ ids.forEach((id, i) => {465+ if (id < 0 || known.has(id)) return;466+ if (wrongKnown.has(id)) common.push([id, wrongKnown.get(id)!]);467+ else common.push([id, cells[i] === -1 ? 0 : cells[i]]);468+ });469+ } else {470+ sols = enumerate(cells, shape, LIMIT);471+ if (sols.length === 0) {472+ throw new Error(`tile #${tile.id} has no solution from known cells`);473+ }474+ ids.forEach((id, i) => {475+ if (id < 0 || known.has(id)) return;476+ const v = sols[0][i];477+ if (sols.every((s) => s[i] === v)) common.push([id, v]);478+ else disputed.push(i);479+ });480+ }466481 if (!common.length && !disputed.length) {467482 // nothing left to commit here (every cell known, e.g. filled by a468483 // neighbour meanwhile): observe again@@ -472,8 +487,9 @@ while (obs.status !== "solved" && batches < MAX_BATCHES) {
472487 }473488 if (common.length) {474489 batch = common;475- intent =476- `tile #${tile.id} (${label}): ${sols.length} solution(s) from known cells, committing the ${common.length} cells they agree on`;490+ intent = STRATEGY === "probe"491+ ? `tile #${tile.id} (${label}): probing ${common.length} cells`492+ : `tile #${tile.id} (${label}): ${sols.length} solution(s) from known cells, committing the ${common.length} cells they agree on`;477493 } else {478494 const i = disputed[0];479495 batch = [[ids[i], sols[0][i]]];@@ -485,6 +501,10 @@ while (obs.status !== "solved" && batches < MAX_BATCHES) {
485501 try {486502 r = await write("commit", { cells: batch, intent });487503 } catch (e) {504+ if (String(e).includes("out for the day")) {505+ console.log(`${AGENT} is dead: ${String(e).slice(0, 200)}`);506+ break;507+ }488508 // the cells were filled meanwhile (shared cells, another agent): observe489509 // again and continue490510 if (!String(e).includes("No cell to process")) throw e;@@ -492,6 +512,18 @@ while (obs.status !== "solved" && batches < MAX_BATCHES) {
492512 learn(obs);493513 continue;494514 }515+ if (r.health) {516+ const h = r.health;517+ console.log(518+ `${AGENT} health ${h.state} ${519+ (h.rate * 100).toFixed(1)520+ }% (${h.wrong}/${h.committed})${r.note ? " - " + r.note : ""}`,521+ );522+ if (h.state === "dead") {523+ console.log(`${AGENT} is dead; stopping.`);524+ break;525+ }526+ }495527 batches++;496528 for (const rej of r.rejected) {497529 const v = batch.find(([id]) => id === rej.id)![1];