The Kill Screen at Level 256

Medium

· Frontend

Incident

SEV-2

BUG-LVL256

Priority: High · reported by a very good player

Time to fix: 20 min

Failing checks on the shipped build

  • level 256 draws seven fruits and leaves the maze alone

    level 256: expected 7 but got 256

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Pac-Man · 1980

Modelled on Pac-Man's level 256 "kill screen" (Namco, 1980): the game keeps its level counter in a single byte. On level 256 the routine that draws the fruit row at the bottom of the screen overflows — its fruit count wraps to zero, the loop that counts down to zero runs 256 times, and it writes garbage over the right half of the maze, leaving the level impossible to finish.

FruitRow.java reconstructs that routine against a small screen model (MazeScreen.java): slots 0–6 are the fruit row, and any other slot lands on maze tiles.

Fix FruitRow so every level draws at most seven fruits and nothing ever touches the maze.

Code map

class FruitRow {
    // levelIndex is the game's level counter: 0 on level 1, kept in one byte.
    static int fruitCount(int levelIndex) {
        int n = (levelIndex + 1) & 0xFF;
        return n < MazeScreen.FRUIT_SLOTS ? n : MazeScreen.FRUIT_SLOTS;
    }

    static int draw(MazeScreen screen, int levelIndex) {
        int n = fruitCount(levelIndex);
        int slot = 0;
        do {
            screen.putFruit(slot, levelIndex - slot);
            slot++;
            n = (n - 1) & 0xFF;
        } while (n != 0);
        return slot;
    }
}

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Kill Screen at Level 256 — Java Bug Hunt

Modelled on Pac-Man's level 256 "kill screen" (Namco, 1980): the game keeps its level counter in a single byte.

  • Language: Java
  • Layer: Frontend
  • Difficulty: Medium
  • Concepts: Overflow, Rendering
  • Modelled on: Pac-Man · 1980
  • Visible tests: level 1 draws one fruit; level 256 draws seven fruits and leaves the maze alone
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-LVL256
  • Reported by: a very good player
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • level 256 draws seven fruits and leaves the maze alone — level 256: expected 7 but got 256

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Modelled on Pac-Man's level 256 "kill screen" (Namco, 1980): the game keeps its level counter in a single byte. On level 256 the routine that draws the fruit row at the bottom of the screen overflows — its fruit count wraps to zero, the loop that counts down to zero runs 256 times, and it writes garbage over the right half of the maze, leaving the level impossible to finish.

FruitRow.java reconstructs that routine against a small screen model (MazeScreen.java): slots 0–6 are the fruit row, and any other slot lands on maze tiles.

Fix FruitRow so every level draws at most seven fruits and nothing ever touches the maze.

Bug report

BUG-LVL256 · Priority: High · Reported by: a very good player

levelIndex is 0 on level 1 (level 256 is levelIndex 255; levels past 256 must work too).

  • fruitCount(levelIndex) = min(levelIndex + 1, 7), for every levelIndex >= 0
  • draw(screen, levelIndex) puts exactly fruitCount(levelIndex) fruits into slots 0 .. count-1 and returns that count; screen.corruptedTiles stays 0

Observed: on level 256 draw() returned 256 and 249 maze tiles were overwritten.

Logs

[game] level 256 start
[render] fruit row: 256 sprites drawn
[render] maze tiles overwritten: 249

The code as shipped

src/game/FruitRow.java (editable)

class FruitRow {
    // levelIndex is the game's level counter: 0 on level 1, kept in one byte.
    static int fruitCount(int levelIndex) {
        int n = (levelIndex + 1) & 0xFF;
        return n < MazeScreen.FRUIT_SLOTS ? n : MazeScreen.FRUIT_SLOTS;
    }

    static int draw(MazeScreen screen, int levelIndex) {
        int n = fruitCount(levelIndex);
        int slot = 0;
        do {
            screen.putFruit(slot, levelIndex - slot);
            slot++;
            n = (n - 1) & 0xFF;
        } while (n != 0);
        return slot;
    }
}

Read-only context: src/game/MazeScreen.java.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.