Back to Gem Warden
SOURCE / PINNED RELEASE

Made of little things.

Gem Warden

Release
7c457bfe5427…
Author-recorded commit
fb5453b5fc06…
License
LICENSE
Author’s source reference
nostr://npub1eg5pfnws6tg6rtp33tugpppqtv5u05crmf983qp438cdycwzngys0gxzcs/wss%3A%2F%2Fgit.napplet.soy%2F/n-3929629ef1d

Archive hash verified: 895b8dd430aad9fe…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

tests/matchups.ts
// Equal mana, different builds, one wave of each monster type: how many get
// through to the orb. node tests/matchups.ts [field] [wave] [mass]
import * as G from '../src/game.ts';
import { towerSpot, trapSpot } from './strategies.ts';

type Part = { kind: G.StructKind; color: G.GemColor; share: number };
const BUILDS: Record<string, Part[]> = {};
const tower = (color: G.GemColor, share: number): Part => ({ kind: 'tower', color, share });
const trap = (color: G.GemColor, share: number): Part => ({ kind: 'trap', color, share });
BUILDS['3 ruby'] = [tower('red', 1), tower('red', 1), tower('red', 1)];
BUILDS['3 topaz'] = [tower('yellow', 1), tower('yellow', 1), tower('yellow', 1)];
BUILDS['5 ruby'] = [1, 2, 3, 4, 5].map(() => tower('red', 1));
BUILDS['3 towers mix'] = [tower('red', 1), tower('yellow', 1), tower('purple', 1)];
BUILDS['2r+am+sa+ja'] = [tower('red', 2), tower('red', 2), trap('purple', 1), trap('blue', 1), trap('green', 1)];
BUILDS['r+t+am+sa'] = [tower('red', 2), tower('yellow', 2), trap('purple', 1), trap('blue', 1)];

export function matchup(field: number, build: Part[], def: G.WaveDef, mass: number) {
  const g = G.newGame(field);
  g.mana = 1e12;
  g.manaCap = 1e12;
  const total = build.reduce((a, p) => a + p.share, 0);
  for (const p of build) {
    const spot = p.kind === 'tower' ? towerSpot(g) : trapSpot(g);
    const s = G.build(g, p.kind, spot![0], spot![1])!;
    s.gem = { id: 0, mass: (mass * p.share) / total, comp: { [p.color]: 1 }, kills: 0 };
  }
  g.waves = [def];
  g.nextWave = 0;
  g.waveTimer = 0;
  let leaks = 0;
  for (let t = 0; t < 300 && g.state === 'playing'; t += 0.05) {
    G.step(g, 0.05);
    for (const e of g.events) if (e.type === 'banish') leaks++;
    g.events.length = 0;
  }
  return leaks;
}

if (import.meta.url === `file://${process.argv[1]}`) {
  const field = Number(process.argv[2] ?? 4);
  const wave = Number(process.argv[3] ?? 14);
  const mass = Number(process.argv[4] ?? 150);
  const types: G.MonsterType[] = ['crawler', 'swarm', 'brute', 'giant', 'runner', 'warded', 'mender'];
  console.log(`field ${field}, wave ${wave}, ${mass} G1 gems of mana (${mass * 80}); leaks per wave`);
  console.log(''.padEnd(14) + types.map((t) => t.padStart(8)).join('') + '   total');
  for (const [name, b] of Object.entries(BUILDS)) {
    const r = types.map((t) => matchup(field, b, G.waveDef(t, wave, field), mass));
    console.log(name.padEnd(14) + r.map((x) => String(x).padStart(8)).join('') + String(r.reduce((a, b) => a + b, 0)).padStart(8));
  }
}