Back to leaderboard

٠new X

Created 9/13/2026

Active

My strategy is based on adaptive cooperation and controlled retaliation. I start by cooperating and observe the opponent's behavior before becoming aggressive. I use both recent moves and the opponent's overall behavior to distinguish between cooperative and consistently aggressive players. A single defection is punished without immediately creating a long cycle of mutual defection, while repeated defections trigger a stronger defensive response. When the opponent returns to cooperation, the strategy attempts to return to cooperation as well. The main goal is to maximize the average score by maintaining mutual cooperation whenever possible while preventing consistently aggressive opponents from exploiting the bot.

Avg score

8.397

Wins

380

Losses

4126

Win rate

3.5%

Total battles: 10971

Score history

Score trend over the last 200 battles

Avg: 8.397

Recent battles

Source

export default function bot({ history, memory }) {
  memory ??= {
    lastMove: "C",
    opponentD: 0,
    opponentC: 0,
    consecutiveD: 0,
    calmRounds: 0
  };

  const n = history.length;

  // البداية: تعاون
  if (n === 0) {
    memory.lastMove = "C";
    return ["C", memory];
  }

  const last = history[n - 1];

  // تحديث سلوك الخصم
  if (last.opponent === "D") {
    memory.opponentD++;
    memory.consecutiveD++;
    memory.calmRounds = 0;
  } else {
    memory.opponentC++;
    memory.consecutiveD = 0;
    memory.calmRounds++;
  }

  const recent = history.slice(-10);

  let recentD = 0;
  for (const r of recent) {
    if (r.opponent === "D") recentD++;
  }

  const recentRate = recentD / recent.length;
  const totalRate = memory.opponentD / n;

  /*
   * 1. خصم عدواني جدًا:
   * لو بيعمل D باستمرار، لا نعطيه C مجانية.
   */
  if (
    (n >= 10 && totalRate >= 0.75) ||
    (recent.length >= 6 && recentRate >= 0.80) ||
    memory.consecutiveD >= 3
  ) {
    memory.lastMove = "D";
    return ["D", memory];
  }

  /*
   * 2. لو الخصم متعاون جدًا:
   * نحافظ على التعاون لأقصى وقت.
   */
  if (
    n >= 8 &&
    totalRate <= 0.15 &&
    recentRate <= 0.20
  ) {
    memory.lastMove = "C";
    return ["C", memory];
  }

  /*
   * 3. بعد D واحدة:
   * نعاقب مرة واحدة فقط بدل الدخول في حرب طويلة.
   */
  if (last.opponent === "D") {
    memory.lastMove = "D";
    return ["D", memory];
  }

  /*
   * 4. لو الخصم رجع للتعاون بعد فترة توتر،
   * نرجع للتعاون ونحاول نكسر سلسلة D/D.
   */
  if (
    last.opponent === "C" &&
    memory.calmRounds >= 1 &&
    recentRate < 0.50
  ) {
    memory.lastMove = "C";
    return ["C", memory];
  }

  /*
   * 5. الوضع الطبيعي:
   * التعاون هو الاختيار الأساسي.
   */
  memory.lastMove = "C";
  return ["C", memory];
}