kingtommy dot com

Bragnarok

Personal project · Play it at play.bragnarok.com

I have a small, experimental multiplayer game that's been a test bed for new technologies. This game is sort of a running joke of mine: Every time I have an "I need to try out the new framework!" moment, Bragnarok is the site that I mess up.

The latest experiment: I've created a small organization of Claude agents that can manage Bragnarok fully autonomously. I hold the business, head engineer, and senior QA roles. The Claude agents cover junior and mid-level engineering, junior QA, product development, and a few other roles. It runs on a handful of Claude skills, a work board, and a set of rules learned the hard way.

The game

Imagine you're Zeus with the power to help or harm a bunch of tiny creatures. Built with Node.js, the server simulates worlds of creatures and streams updates to players over Socket.IO. Players are gods: they cast world-shaping abilities, earn essence, and unlock powers in a tech tree.

Plain JavaScript on a canvas, SQLite for storage. 576 commits, and 4,973 Jest tests that run in about 13 seconds.

Claude skills

Goal: Responsibly automate workflows with agents.

Intake

/bragnarok-todo-add [bug|task] [quick|investigate] (describe the problem)

Files a bug or task on the board. The intake agent knows the product well, so one line is usually enough; if it isn't, it asks me one question. It checks for duplicates, finds the code involved, and writes the item so a session with no context can finish it, ending with an observable "done when." It never fixes what it files.

Engineering and QA

/bragnarok-todo-start [serial|single] [bugs|todo|blocked|discussions|all] [commit|nocommit]

Works the board unattended. Handles the bugs first. For each item it finds the cause, proves the fix at the cheapest level that works (unit tests, then event counts from a live world, then a browser only for visual changes), commits it, and parks it for my review.

Each entry follows a standardized flow:

  1. As filed: This is created on todo-add. The first step. Includes the prompt that kicked off the ticket, and the preliminary investigations to add necessary context. An index is regularly maintained. The index saves the agents from rereading the whole codebase and makes investigation faster.
  2. Approach: This is created early in the todo-start step. The agent explains itself with the following questions:
    • What was the process for verifying the issue?
    • Did any attempted solutions not work?
    • Were there any unexpected findings?
    • What's the expected impact from the issue?
    • What's the expected outcome from the fix?
    • Must the tests be updated to account for this?
    • Must the index be updated with new info?
    The approach is updated at all steps, based on new findings.
  3. What changed: Information regarding what was changed (code, data, data models, tests, ci instructions, agent instructions). Everything exists within version control, so it can be updated, maintained, and blamed where necessary. Includes commit references.
  4. How to verify: Not all problems are shaped the same. Some require data validation, some require tests to be run, some require manual review of graphical elements. This step includes all instructions necessary for a human to step in and verify that the agent did honest and reproducible work. This typically includes testing the fix and testing the un-fix (an integral step).

Tickets can only be marked Done with my explicit approval.

Product and design

/bragnarok-council (topic)

For big, cross-cutting design questions. Agents argue it against the code, a red-team agent tries to prove their conclusions wrong, I approve the rules, a mockup proves them, and the result becomes tickets. It interrupts me exactly twice. Once, the red team measured a claim the docs took for granted and proved it false, and a terrain edit went from 180ms to 3ms.

Specialists

/creature-spritesheet makes new creatures by re-skinning existing pixel art; the owl began as the eagle. /verify drives the game in headless Chromium with Playwright and files its screenshots in the journal.

Automated QA, around the clock

Nine scripted bot gods play the game constantly, one per branch of the tech tree. They connect exactly as a browser does, over the real Socket.IO protocol, so they exercise the same code a player does. Each one climbs its branch from level 1, buying about 50 tech nodes, and casts its powers on the live world, resting up to a minute between casts so the world doesn't turn into a firehose.

Every cast the server refuses (locked, failed, or on cooldown) is counted, so a bot whose failures start climbing is a bug report waiting to be filed. I can pause, respec, or reset any of them from /admin. The runner is its own process with its own 210 tests, and restarting it never touches the game.

They're playing right now. Watch them at play.bragnarok.com: they're the gods named BOT in the Gods present list.

Coordination

Several sessions often work at once. ./board holds what needs doing (216 items so far, 119 closed), and ./todo holds who's doing what right now, so two agents never edit the same file blind.

Guardrails

Most rules exist because something went wrong once.

  • Never boot the real database. Starting the server migrates whatever it opens, so every agent works on a copy.
  • Passing tests aren't proof. Two features passed every test and never once fired in a live world.
  • Backticks in shell arguments run as commands. Review notes full of code got silently mangled, so they now go through quoted heredocs.

Rivers, by hand

Not everything here is written by agents. The map generator was written by me, years ago. The rivers are probably my favorite part. Each river starts near a mountain and walks toward the nearest coast one tile at a time.

The trick is the score for each step: the distance to the coast, plus up to three tiles of random noise. Without the noise, rivers run straight to the sea. With it, they meander. A river can't step onto river tiles, so it can't loop, and a 200-step cap guarantees it always ends. It all runs on the server; players only receive the finished tiles.

generateRivers() in server/mapGenerator.js
// Carves 3 to 5 rivers into the map. Each one starts on an inland mountain and walks,
// one tile at a time, toward the sea until it touches water.
generateRivers() {
  // 1. Find candidate springs: mountain tiles with no water within 2 tiles,
  //    so every river has some distance to travel.
  const springs = [];

  for (let row = 3; row < this.size - 3; row++) {
    for (let col = 3; col < this.size - 3; col++) {
      if (this.map[row][col].biome === 'mountain') {
        let waterNearby = false;
        for (let rowOffset = -2; rowOffset <= 2; rowOffset++) {
          for (let colOffset = -2; colOffset <= 2; colOffset++) {
            const nearCol = col + colOffset;
            const nearRow = row + rowOffset;
            if (
              nearCol >= 0 && nearCol < this.size &&
              nearRow >= 0 && nearRow < this.size &&
              (this.map[nearRow][nearCol].biome === 'coast' || this.map[nearRow][nearCol].biome === 'ocean')
            ) {
              waterNearby = true;
            }
          }
        }
        if (!waterNearby) springs.push({ col, row });
      }
    }
  }

  // 2. Pick 3 to 5 of them at random (fewer if the map has fewer springs).
  this.shuffle(springs);
  const riverCount = Math.min(3 + Math.floor(Math.random() * 3), springs.length);

  // The 8 neighbors of a tile: the 4 sides, then the 4 diagonals.
  const neighbors = [[0,1],[1,0],[0,-1],[-1,0],[1,1],[-1,-1],[1,-1],[-1,1]];

  // 3. Walk each river downhill to the sea.
  for (let river = 0; river < riverCount; river++) {
    let { col, row } = springs[river];
    let length = 0;

    // The 200-tile cap guarantees the walk ends, even on a strange map.
    while (length < 200) {
      this.map[row][col].biome = 'river';

      // Done when any neighbor is water: the river has reached the sea.
      let reachedSea = false;
      for (const [colStep, rowStep] of neighbors) {
        const nextCol = col + colStep;
        const nextRow = row + rowStep;
        if (
          nextCol >= 0 && nextCol < this.size &&
          nextRow >= 0 && nextRow < this.size &&
          (this.map[nextRow][nextCol].biome === 'coast' || this.map[nextRow][nextCol].biome === 'ocean')
        ) {
          reachedSea = true;
        }
      }
      if (reachedSea) break;

      // Otherwise, score every neighbor that isn't already river and step to the lowest.
      // Score = distance to the sea + 0 to 3 tiles of noise. Without the noise the river
      // runs in a straight line; with it, a slightly longer path can win, so it meanders.
      // Skipping river tiles means it can never loop back on itself.
      let nextTile = null;
      let lowestScore = Infinity;

      for (const [colStep, rowStep] of neighbors) {
        const nextCol = col + colStep;
        const nextRow = row + rowStep;
        if (
          nextCol >= 0 && nextCol < this.size &&
          nextRow >= 0 && nextRow < this.size &&
          this.map[nextRow][nextCol].biome !== 'river'
        ) {
          const distanceToSea = this.distanceToNearestCoast(nextCol, nextRow);
          const score = distanceToSea + Math.random() * 3;
          if (score < lowestScore) {
            lowestScore = score;
            nextTile = { col: nextCol, row: nextRow };
          }
        }
      }

      // Boxed in by its own banks: end the river here.
      if (!nextTile) break;
      col = nextTile.col;
      row = nextTile.row;
      length++;
    }
  }
}


// How many tiles from (col, row) to the nearest coast or ocean tile, counting only
// straight moves (Manhattan distance). Checks every tile; fine for a one-time map build.
distanceToNearestCoast(col, row) {
  let shortest = Infinity;
  for (let waterRow = 0; waterRow < this.size; waterRow++) {
    for (let waterCol = 0; waterCol < this.size; waterCol++) {
      if (this.map[waterRow][waterCol].biome === 'coast' || this.map[waterRow][waterCol].biome === 'ocean') {
        const distance = Math.abs(waterCol - col) + Math.abs(waterRow - row);
        if (distance < shortest) shortest = distance;
      }
    }
  }
  return shortest;
}
A demo of the river generator function.
A river leaves the mountains, runs through two lakes, and keeps going south. The noise at work: this one wanders east across the highlands before it finds the sea. A long one that runs east, then bends south around a lake on its way through the mountains.

All demos