Back to leaderboard

WILLIAM SMITH

Created 9/14/2026

Inactive

ddd

Avg score

8.134

Wins

1964

Losses

3305

Win rate

20.7%

Total battles: 9487

Score history

Score trend over the last 200 battles

Avg: 8.134

Recent battles

Source

export default function bot(state) {
    const history = state?.history || [];
    const memory = state?.memory || { farming: false };
    const round = history.length;

    // Always start friendly
    if (round === 0) return ["C", memory];

    const oppLast = history[round - 1].opponent;
    const myLast = history[round - 1].you;

    // ---------------------------------------------------------
    // UPGRADE 1: THE FARMER (Pushing the score to 3.0)
    // If we confirmed they are weak, steal 3 points every round.
    // ---------------------------------------------------------
    if (memory.farming) {
        // If they finally wake up and fight back, instantly abort the farm.
        if (oppLast === "D") {
            memory.farming = false;
        } else {
            return ["D", memory];
        }
    }

    // ---------------------------------------------------------
    // UPGRADE 2: THE SAFE PROBE (Finding weak bots safely)
    // ---------------------------------------------------------
    if (round === 10) return ["D", memory]; // Drop a test defect
    if (round === 11) return ["C", memory]; // Instantly apologize
    if (round === 12) {
        // Did they retaliate on round 11 to our test defect?
        if (history[11].opponent === "C") {
            memory.farming = true; // Sucker found! Farm them.
            return ["D", memory];
        } else {
            return ["C", memory]; // They are smart. Stabilize back to 2 points.
        }
    }

    // ---------------------------------------------------------
    // UPGRADE 3: DEATH-SPIRAL BREAKER (Protecting the 2.0 average)
    // If pure Tit-For-Tat accidentally gets locked in a Defect loop 
    // it bleeds points. This breaks the loop to restore peace.
    // ---------------------------------------------------------
    if (round >= 3) {
        if (myLast === "D" && oppLast === "D" && 
            history[round - 2].you === "D" && history[round - 2].opponent === "D") {
            
            // Only offer peace if they aren't purely hostile overall.
            let oppTotalD = 0;
            for(let i=0; i<round; i++) if(history[i].opponent === "D") oppTotalD++;
            
            if ((oppTotalD / round) <= 0.5) {
                return ["C", memory]; // Offer exactly one apology to restore 2.0
            }
        }
    }

    // ---------------------------------------------------------
    // Default Tit-For-Tat
    // ---------------------------------------------------------
    return [oppLast, memory];
}