Back to leaderboard

tie

Created 9/11/2026

Active

tie

Avg score

8.334

Wins

73

Losses

3385

Win rate

0.6%

Total battles: 12796

Score history

Score trend over the last 199 battles

Avg: 8.334

Recent battles

Source

export default function bot({ history, memory }) {
  // 1. Initialize the internal Database structure on Round 1
  if (memory === null) {
    memory = {
      db: {
        matches: [],             // Record of all round outcomes
        stats: {
          myScore: 0,
          oppScore: 0,
          scoreDiff: 0,          // Positive = leading, Negative = trailing, 0 = tied
          tiesAchieved: 0,       // Total rounds spent perfectly tied
        },
        opponentProfile: {
          coopCount: 0,
          defectCount: 0,
          coopRate: 1.0,
        }
      }
    }
  }

  const roundCount = history.length

  // 2. Query and update Database using previous round data
  if (roundCount > 0) {
    const lastMatch = history.at(-1)
    let myPts = 0, oppPts = 0

    if (lastMatch.you === "C" && lastMatch.opponent === "C") { myPts = 2; oppPts = 2 }
    else if (lastMatch.you === "D" && lastMatch.opponent === "C") { myPts = 3; oppPts = 0 }
    else if (lastMatch.you === "C" && lastMatch.opponent === "D") { myPts = 0; oppPts = 3 }
    else if (lastMatch.you === "D" && lastMatch.opponent === "D") { myPts = 1; oppPts = 1 }

    // Update Scores in DB
    memory.db.stats.myScore += myPts
    memory.db.stats.oppScore += oppPts
    memory.db.stats.scoreDiff = memory.db.stats.myScore - memory.db.stats.oppScore

    if (memory.db.stats.scoreDiff === 0) {
      memory.db.stats.tiesAchieved += 1
    }

    // Update Opponent Behavioral Analytics in DB
    if (lastMatch.opponent === "C") memory.db.opponentProfile.coopCount++
    if (lastMatch.opponent === "D") memory.db.opponentProfile.defectCount++
    memory.db.opponentProfile.coopRate = memory.db.opponentProfile.coopCount / roundCount

    // Insert new transaction row into matches log
    memory.db.matches.push({
      round: roundCount,
      you: lastMatch.you,
      opponent: lastMatch.opponent,
      scoreDiffAfterRound: memory.db.stats.scoreDiff
    })
  }

  // --- QUERY DATABASE TO DETERMINE NEXT MOVE ---

  const diff = memory.db.stats.scoreDiff
  const oppCoopRate = memory.db.opponentProfile.coopRate

  // DB QUERY 1: Trailing Behind (Score Diff < 0)
  // Strategy: Defect ("D") to aggressively close the gap
  if (diff < 0) {
    return ["D", memory]
  }

  // DB QUERY 2: Ahead in Points (Score Diff > 0)
  // Strategy: Cooperate ("C") to allow the opponent to earn points and catch up
  if (diff > 0) {
    return ["C", memory]
  }

  // DB QUERY 3: Perfect Tie (Score Diff === 0)
  // If opponent is overwhelmingly hostile (low coop rate), play defensively
  if (oppCoopRate < 0.3 && roundCount > 5) {
    return ["D", memory]
  }

  // Default: Maintain equality with Cooperation ("C")
  return ["C", memory]
}