- commit
- 0cef9c8589b2177a7178e822dbd1ba10b9ac5291
- parent
- 548926d92659c7490675ac20f7d3f22e337fbfb6
- author
- dami <gazey55@gmail.com>
| M | site/ | 19 | +++++++++++++++++-- |
| M | site/ | 5 | ++++- |
@@ -300,9 +300,14 @@ function distFromSeed(): Map<number, number> {
300300 let lastSolved: number | null = null;301301 function pickReveal(frontier: number[]): number {302302 if (STRATEGY === "dfs" && lastSolved !== null) {303+ // go deep: among the tiles touching the last solved one, the farthest304+ // from my seed303305 const adj = new Set(neighbours.get(lastSolved) ?? []);304306 const near = frontier.filter((t) => adj.has(t));305- if (near.length) return near[0];307+ if (near.length) {308+ const d = distFromSeed();309+ return near.reduce((a, b) => (d.get(b) ?? 0) > (d.get(a) ?? 0) ? b : a);310+ }306311 }307312 if (STRATEGY === "greedy") {308313 return frontier.reduce((a, b) =>@@ -377,7 +382,17 @@ while (obs.status !== "solved" && batches < MAX_BATCHES) {
377382 continue;378383 } else {379384 const id = pickReveal(frontier);380- await write("reveal", { tile: id, intent: `reveal #${id} (${STRATEGY})` });385+ try {386+ await write("reveal", {387+ tile: id,388+ intent: `reveal #${id} (${STRATEGY})`,389+ });390+ } catch (e) {391+ // another agent got there first (shared frontier after a meeting):392+ // observe again and pick anew393+ const msg = String(e);394+ if (!msg.includes("already") && !msg.includes("frontier")) throw e;395+ }381396 obs = await observe();382397 learn(obs);383398 continue;@@ -368,7 +368,10 @@ async function player(
368368 if (revealed.length) id = revealed[0];369369 else {370370 if (strategy === "dfs" && last !== null) {371- id = fr.find((t) => geo.adjacency[last!].includes(t)) ?? fr[0];371+ const near = fr.filter((t) => geo.adjacency[last!].includes(t));372+ id = near.length373+ ? near.reduce((p, q) => (dist[q] > dist[p] ? q : p))374+ : fr[0];372375 } else if (strategy === "greedy") {373376 id = fr.reduce((p, q) =>374377 ref.manifest.tiles[q].cells > ref.manifest.tiles[p].cells ? q : p