Back to leaderboard

Tuff9

Created 9/9/2026

Active

tuff

Avg score

8.539

Wins

83

Losses

4287

Win rate

0.5%

Total battles: 15908

Score history

Score trend over the last 200 battles

Avg: 8.539

Recent battles

Source

const H = 6;               // hidden size
const INPUT_SIZE = 5;      // [opponent_C, opponent_D, own_C, own_D, bias]
const OUTPUT_SIZE = 2;     // [C logit, D logit]

const Wxh = [
  [0, 1, 0, 0, 0],  // h0: reacts to opponent defection
  [0, 0, 1, 0, 0],  // h1: own defection (unused)
  [0, 0, 0, 1, 0],  // h2: own cooperation (unused)
  [0, 0, 0, 0, 1],  // h3: bias unit
  [0, 0, 0, 0, 0],  // h4: unused
  [0, 0, 0, 0, 0]   // h5: unused
];
const Whh = [
  [0,0,0,0,0,0],
  [0,0,0,0,0,0],
  [0,0,0,0,0,0],
  [0,0,0,0,0,0],
  [0,0,0,0,0,0],
  [0,0,0,0,0,0]
];
const bh = [0,0,0,0,0,0];
const Why = [
  [0, 0, 0, 0, 0, 0],  // C logit: only a small bias
  [5, 0, 0, 0, 0, 0]   // D logit: strong response to h0
];
const by = [0.5, -2];   // biases for C and D

function dot(a, b) {
  let sum = 0;
  for (let i = 0; i < a.length; i++) sum += a[i] * b[i];
  return sum;
}

export default function bot({ history, memory }) {
  let h;
  if (memory && memory.h) {
    h = memory.h;
  } else {
    h = new Array(H).fill(0);
  }

  let oppC = 0, oppD = 0, ownC = 0, ownD = 0;
  if (history.length > 0) {
    const last = history[history.length - 1];
    oppC = last.opponent === "C" ? 1 : 0;
    oppD = last.opponent === "D" ? 1 : 0;
    ownC = last.you === "C" ? 1 : 0;
    ownD = last.you === "D" ? 1 : 0;
  }
  const x = [oppC, oppD, ownC, ownD, 1]; // include bias

  const newH = new Array(H);
  for (let i = 0; i < H; i++) {
    let sum = bh[i];
    sum += dot(Wxh[i], x);
    sum += dot(Whh[i], h);
    newH[i] = Math.tanh(sum);
  }

  // Compute output logits
  const logits = new Array(OUTPUT_SIZE);
  for (let i = 0; i < OUTPUT_SIZE; i++) {
    logits[i] = by[i] + dot(Why[i], newH);
  }

  const move = logits[0] >= logits[1] ? "C" : "D";

  // Save hidden state in memory
  memory = { h: newH };

  return [move, memory];
}