Back to leaderboard

Defected_Boy111

Created 9/6/2026

Active

smarter

Avg score

8.501

Wins

627

Losses

7723

Win rate

3.0%

Total battles: 20953

Score history

Score trend over the last 200 battles

Avg: 8.501

Recent battles

Source

export default function bot({ history, memory }) {
  // 1. Initializing state
  memory = memory ?? {
    opponentDefectionCount: 0,
    totalRounds: 0,
    consecutiveDefections: 0
  }

  // First move is always cooperative ("Nice" trait)
  if (!history.length) {
    return ["C", memory]
  }

  // 2. Track Opponent Analytics
  const lastOpponentMove = history.at(-1)?.opponent
  memory.totalRounds++

  if (lastOpponentMove === "D") {
    memory.opponentDefectionCount++
    memory.consecutiveDefections++
  } else {
    memory.consecutiveDefections = 0
  }

  const defectionRate = memory.opponentDefectionCount / memory.totalRounds

  // 3. Strategy Logic

  // RULE A: Hard Retaliation against serial defectors (e.g., Always Defect bots)
  // If opponent defects > 60% of the time, abandon forgiveness and fight back.
  if (defectionRate > 0.60) {
    return ["D", memory]
  }

  // RULE B: Generous Tit-for-Tat
  if (lastOpponentMove === "D") {
    // Standard TFT retaliates immediately.
    // Generous TFT has a 10% chance to forgive a single defection to avoid death-spirals.
    const isSingleDefection = memory.consecutiveDefections === 1
    const shouldForgive = isSingleDefection && Math.random() < 0.10

    const move = shouldForgive ? "C" : "D"
    return [move, memory]
  }

  // RULE C: Default to cooperation if last move was "C"
  return ["C", memory]
}