Back to leaderboard

Number 1

Created 9/13/2026

Active

My strategy focuses on taking advantage of cooperative opponents while avoiding unnecessary long-term conflicts. I start by cooperating and observe the opponent's behavior. When an opponent shows a high level of cooperation, I occasionally defect to "steal" the extra points instead of always settling for mutual cooperation. After a steal, I watch how the opponent reacts. If they retaliate aggressively, I reduce the attacks and return to cooperation when possible. However, against consistently aggressive opponents, I switch to a defensive approach to avoid being exploited. The main goal is to maximize my average score by carefully choosing when to cooperate and when to steal, rather than defecting all the time.

Avg score

5.758

Wins

2184

Losses

6763

Win rate

19.6%

Total battles: 11160

Score history

Score trend over the last 200 battles

Avg: 5.758

Recent battles

Source

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

  const n = history.length;

  // بداية هادئة
  if (n === 0) {
    memory.lastMove = "C";
    return ["C", memory];
  }

  const last = history[n - 1];

  if (last.opponent === "D") {
    memory.opponentD++;
  } else {
    memory.opponentC++;
  }

  // آخر 8 جولات لمعرفة هل الخصم متعاون
  const recent = history.slice(-8);
  let recentC = 0;
  let recentD = 0;

  for (const r of recent) {
    if (r.opponent === "C") recentC++;
    else recentD++;
  }

  const cooperationRate = recentC / recent.length;

  /*
   * لو الخصم متعاون جدًا:
   * نسرق منه مرة كل فترة للحصول على 3 نقاط.
   */
  if (
    n >= 8 &&
    cooperationRate >= 0.80 &&
    n % 7 === 0
  ) {
    memory.steals++;
    memory.lastMove = "D";
    return ["D", memory];
  }

  /*
   * لو الخصم بدأ يرد بالـ D بعد السرقة،
   * نرجع للتعاون بدل حرب D/D.
   */
  if (
    last.opponent === "D" &&
    cooperationRate < 0.60
  ) {
    memory.lastMove = "C";
    return ["C", memory];
  }

  /*
   * خصم عدواني باستمرار:
   * ندافع بدل ما نضيع نقاط.
   */
  if (
    recentD >= 6 ||
    (n >= 12 && memory.opponentD / n >= 0.75)
  ) {
    memory.lastMove = "D";
    return ["D", memory];
  }

  /*
   * الوضع الطبيعي:
   * تعاون حتى تأتي فرصة سرقة آمنة.
   */
  memory.lastMove = "C";
  return ["C", memory];
}