Back to leaderboard

Bumwinnah

Created 9/11/2026

Active

Nah i'd win

Avg score

5.869

Wins

8527

Losses

2374

Win rate

67.9%

Total battles: 12549

Score history

Score trend over the last 199 battles

Avg: 5.869

Recent battles

Source

export default function bot({ history, memory }) {
  // ---- Initialize memory ----
  memory = memory ?? {
    oppDefections: 0,      // total times opponent has defected
    oppCoops: 0,           // total times opponent has cooperated
    myDefections: 0,
    probeRound: 0,         // counts rounds since our last "probe" defection
    exploitMode: false,    // true once we're confident opponent won't retaliate
  };

  const n = history.length;

  // ---- First round: always start nice ----
  if (n === 0) {
    return ["C", memory];
  }

  const lastOpp = history.at(-1).opponent;
  const lastMe = history.at(-1).you;

  // Update running stats
  if (lastOpp === "D") memory.oppDefections++;
  else memory.oppCoops++;

  const oppDefectRate = memory.oppDefections / n;

  // ---- Detect "always defect" / highly aggressive opponents early ----
  // Don't get suckered for long — after a few rounds of high aggression, just defect.
  if (n >= 4 && oppDefectRate > 0.6) {
    return ["D", memory];
  }

  // ---- Detect exploitable opponents (rarely/never retaliate) ----
  // If we defected recently and they DIDN'T punish us, they're exploitable.
  const weDefectedLastRound = lastMe === "D";
  const theyPunishedUs = weDefectedLastRound && lastOpp === "D";
  const theyLetItSlide = weDefectedLastRound && lastOpp === "C";

  if (theyLetItSlide) {
    memory.exploitMode = true;
  }
  if (theyPunishedUs) {
    // They fight back — not safe to exploit, go back to reciprocal play.
    memory.exploitMode = false;
  }

  if (memory.exploitMode) {
    // Exploit them, but throw in occasional cooperation so a delayed
    // punisher doesn't spiral us into mutual all-out defection.
    const move = n % 5 === 0 ? "C" : "D";
    memory.probeRound = 0;
    return [move, memory];
  }

  // ---- Default: Generous Tit-for-Tat ----
  // Copy opponent's last move, but occasionally forgive a defection
  // (helps against noisy bots / recovers stuck defect-defect loops).
  memory.probeRound++;

  if (lastOpp === "D") {
    const forgive = Math.random() < 0.1; // ~10% forgiveness chance
    if (forgive) return ["C", memory];
    return ["D", memory];
  }

  // Occasionally probe a cooperative-looking opponent to test if
  // they're exploitable (only probe if they've been consistently nice).
  const oppLooksNice = memory.oppCoops / n > 0.85;
  const timeToProbe = memory.probeRound >= 8; // don't probe too often

  if (oppLooksNice && timeToProbe && n > 6) {
    memory.probeRound = 0;
    return ["D", memory]; // test the waters
  }

  return ["C", memory];
}