From e2115dcd04f6a50a616ec86ca04769ed00caf10b Mon Sep 17 00:00:00 2001 From: Restart2008 Date: Fri, 24 Oct 2025 21:08:59 -0700 Subject: [PATCH] NukeWars: prefer spawn tiles farther from already-assigned team tiles to reduce clumping --- src/core/execution/SpawnExecution.ts | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index 709f2dab3..2a7303e09 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -78,7 +78,36 @@ export class SpawnExecution implements Execution { // team's half and avoid tight clumps near the border. const biasFactor = -0.5; const centerDistance = Math.abs(xt - midpoint); - const score = d + centerDistance * biasFactor; + // Compute distance to existing team-owned tiles (if any) so we prefer + // tiles that are farther away from already-assigned spawns. This + // helps avoid clustering near the midpoint or other crowded areas. + let minDistToTeam = Infinity; + try { + const team = player.team(); + if (team) { + for (const p of this.mg.players()) { + if (p.team() !== team) continue; + // skip the current player + if (p === player) continue; + for (const owned of p.tiles()) { + const dd = this.mg.manhattanDist(owned, t); + if (dd < minDistToTeam) minDistToTeam = dd; + if (minDistToTeam === 0) break; + } + if (minDistToTeam === 0) break; + } + } + } catch (e) { + // defensive: if anything goes wrong, fall back to no team-distance bias + minDistToTeam = Infinity; + } + + const spreadFactor = 0.9; + const teamDistanceScore = isFinite(minDistToTeam) + ? -minDistToTeam * spreadFactor + : 0; + + const score = d + centerDistance * biasFactor + teamDistanceScore; if (score < bestScore) { bestScore = score; best = t;