Back to Find the Invisible Cow
SOURCE / PINNED RELEASE

Made of little things.

Find the Invisible Cow

Release
e48b3dced31c…
Author-recorded commit
cf79302f143d…
License
LICENSE
Author’s source reference
nostr://npub1p8rxwea4e0l4jml0q53n5mvh3n7pywq523jk3lm336v04r8ny9jqtq7ttf/wss%3A%2F%2Fgit.napplet.soy%2F/n-3b179f1d7df

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

src/rules.ts
/**
 * Pure game rules for Find the Invisible Cow, kept free of DOM and audio so
 * tests/game-rules.test.mjs can verify the tuning without a browser.
 */

/** Distance to closeness: 0 at (or beyond) the reference radius, 1 on top of the cow. */
export function proximityFor(dist: number, ref: number): number {
  if (!Number.isFinite(dist) || !Number.isFinite(ref) || ref <= 0) return 0;
  const p = 1 - Math.max(0, dist) / ref;
  return Math.max(0, Math.min(1, p));
}

/** Moo loudness: barely audible far away, full volume on the cow's spot. */
export function volumeFor(p: number): number {
  const clamped = Math.max(0, Math.min(1, p));
  return 0.05 + 0.95 * Math.pow(clamped, 1.6);
}

/** Base milliseconds between moos: slow when far, urgent when close. Callers add jitter. */
export function intervalFor(p: number): number {
  const clamped = Math.max(0, Math.min(1, p));
  return 1150 - 800 * clamped;
}

/** Catch area: scales with the smaller frame side, clamped, widened by the assist setting. */
export function catchRadiusFor(w: number, h: number, size: 'normal' | 'large'): number {
  const base = Math.max(26, Math.min(72, Math.min(w, h) * 0.09));
  return size === 'large' ? base * 1.7 : base;
}

/** Timer text m:ss.t with tenths. */
export function formatTime(ms: number): string {
  const total = Math.max(0, ms);
  const minutes = Math.floor(total / 60000);
  const seconds = Math.floor((total % 60000) / 1000);
  const tenths = Math.floor((total % 1000) / 100);
  return `${minutes}:${String(seconds).padStart(2, '0')}.${tenths}`;
}

/** Where the cow was hiding, in plain words. */
export function spotDescription(fx: number, fy: number): string {
  const h = fx < 1 / 3 ? 'left' : fx > 2 / 3 ? 'right' : 'middle';
  const v = fy < 1 / 3 ? 'top' : fy > 2 / 3 ? 'bottom' : 'middle';
  if (h === 'middle' && v === 'middle') return 'It was hiding smack in the middle of the pasture.';
  if (v === 'middle') return `It was hiding along the ${h} side.`;
  if (h === 'middle') return `It was hiding along the ${v} edge.`;
  return `It was hiding near the ${v}-${h} corner.`;
}