First Game With Achievements? Activision's Patches from 1980
The earliest achievements we can document were not inside a game but in the post. From 1980, Activision asked players to photograph a high score on their television and send it in, starting with Dragster, and sent back a patch. Achievements as one score across all of a console's games began with the Xbox 360 in 2005, so the answer depends on whether the reward has to live inside the machine.
Who claims what?
| Source | Claim |
|---|---|
| Game Informer (Kyle Hilliard, 2013) | Activision's patches "are the original, tangible equivalent of today's digital Achievements and Trophies", offered "from the very first games Activision published for the Atari 2600, and until around 1983" |
| Atari Archive (Kevin Bunch, 2025) | Dragster, August 1980, "is the first of Activision's games to offer up a commemorative patch", for a time under 6 seconds |
| Wikipedia, Achievement (video games) | Dates the idea to 1982 with Activision's patches, and calls Xbox 360's Gamerscore the first easily accessible, multi-game system |
| Microsoft at E3, 16 May 2005 | J Allard: "We've also a new concept called Achievements", "a record of everything you've accomplished across your library of games" |
| Game Developer (Mary Jane Irwin, 2009) | Badges appeared on casual game websites as a daily reason to visit, "before Microsoft co-opted them for Xbox Live" |
The sources agree on the patches and differ on the year. Wikipedia's 1982 does not appear in the Game Informer article, one of the two it cites, which says the patches came with Activision's very first games, and the Atari Archive dates Dragster to August 1980. The Dragster manual itself, marked 1980, offers to enrol a player who beats 6 seconds in the "World Class Dragster Club"; it does not name the patch.
What came before the patches?
Before designers set goals, machines kept high scores. Ben Medler's 2009 history of game analytics names Sea Wolf, a Midway arcade game from 1976, as "the first instance of a high score being recorded in a video game". It kept the score but not who made it; names came in 1979 with Star Fire. A high score is a record to beat, not a goal set by the designer, so it is a precursor.
How did achievements change over the years?
| When | Game or system | What changed | Source |
|---|---|---|---|
| 1976 | Sea Wolf | A precursor: the machine shows the best score so far | Medler (2009) |
| August 1980 | Dragster | A goal set by the designer, a time under 6 seconds, proved with a photo and rewarded by post | Atari Archive, Dragster manual |
| Until around 1983 | Activision's games | More than 40 patches across several consoles, each for a target such as 20,000 points in Pitfall! | Game Informer |
| 1990 | E-Motion | Wikipedia calls it one of the earliest games with "some form of achievements", five secret bonuses inside the game. Its source could not be checked | Wikipedia |
| 16 May 2005, on sale 22 November | Xbox 360 | Achievements and a Gamerscore across every game on the console, shown on the player's profile | Microsoft, Wikipedia |
| 2007 | Steam | Wikipedia calls Valve the second company with a multi-game achievement system. Game Developer's 2009 feature notes that casual game websites had badges before both | Wikipedia, Game Developer |
| 2 July 2008 | PlayStation 3 trophies | Trophies in bronze, silver and gold, and a platinum trophy for earning all of a game's trophies. At first, developers chose whether to include them | PlayStation Blog, Engadget |
| 7 May 2009 | Steam | Each achievement shows what percentage of players have unlocked it | Steam news |
| 12 June 2013 | Xbox One | Achievements can be added after a game is released, and new "challenges" that give no Gamerscore. Microsoft writes that "Xbox blazed the trail back in 2005" | Xbox Wire |
| 10 November 2016 | Xbox | A rare achievement gets its own notification and a diamond icon | Xbox Wire |
What counts as an achievement?
- A record to beat. A high score, 1976. The machine keeps it, but nobody set it as a goal.
- A goal set by the designer, rewarded outside the game. Activision's patches, from 1980.
- A goal kept inside one game. E-Motion, 1990, is the earliest claim we found, on a source we could not check.
- Goals kept by the platform across all games. Xbox 360, 2005.
A 2011 paper by Juho Hamari and Veikko Eranti defines achievements as goals in a reward system that is "different system than the core game", and notes that the name became an industry standard because Xbox Live and Steam adopted it. By that definition the platform systems fit best, and the patches are a system outside the game in the most literal way.
What can we say with confidence?
Activision's mail-in patches are the earliest designer-set achievements we can document, from Dragster in 1980 according to the Atari Archive, though Wikipedia says 1982. The Xbox 360, announced at E3 in May 2005 and sold from November, is the earliest documented system that kept achievements for every game on a platform, and the word "achievements" took hold with it. Both answers are sound, for different definitions.
Build it today
Our achievements blueprint keeps what this history learned to keep apart. The list of unlocked goals is the truth and only grows: a goal unlocks once, when a counter reaches its target or when a group of other goals is done, which is how a platinum trophy works. Counters only go up, and a best-of counter keeps the highest value instead of adding, as a high score would. The pop-up is only decoration: it shows one at a time, and when an old save unlocks many at once the rest fold into one "and more" message, so no unlock is lost. Steam's percentages and Xbox's rarity notice need numbers from all players, which a game alone cannot know, so they are not in it.
- 25 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
- Checked with TLA+, Z3 and Lean, with what the tools printed
Add "Achievements" to my game.
What it should do: Achievements give the player extra goals beside the main one and a reason to try things the story never asks for. The pop-up makes a small win feel seen, and the list of goals shows what is still left to do.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> quiet
quiet: Quiet
showing: Pop-up showing
backlog: Pop-ups waiting
complete: All done
quiet --> showing: a goal unlocks
quiet --> backlog: several unlock at once
showing --> backlog: another unlocks
showing --> quiet: pop-up ends
showing --> complete: last pop-up ends
backlog --> showing: pop-up ends, next shows
complete --> [*]
```
Use these starting values:
- toastTime: 3 s
- queueLimit: 5 items
Watch out for these common mistakes:
- It unlocks every time the goal is true: Tell your AI: only unlock goals that are not in the unlocked list yet, and add a goal to the list in the same step.
- A negative or broken count takes progress away: Tell your AI: counters only go up. Ignore any count that is zero, below zero, or not a real number.
- An old save floods the screen: Tell your AI: when the game loads, check all goals once, show a few pop-ups, and fold the rest into one 'and more' pop-up.
- A dropped pop-up loses the unlock: Tell your AI: the list of unlocked goals is the truth. Write it first and treat the pop-up as decoration that may be left out.
- A secret goal shows its progress: Tell your AI: for a hidden goal that is still locked, send no counter value, no target and no progress to the screen.
- A best-of counter is added up: Tell your AI: say for each counter whether it adds up or keeps the best value, and keep the higher one for best-of counters.
- A goal with a target of zero or less: Tell your AI: a goal with a target of zero or less counts as already met, and its progress is shown as full.
- A collect-them-all goal names a goal that does not exist: Tell your AI: when the game starts, check that every goal named in a collect-them-all goal exists, and report any that does not.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.
The code, from https://spielerando.com/en/mechanics/achievements (TypeScript, tested):
```ts
/* Achievements: goals that unlock once, when a counter the game keeps reaches a target, or when a
group of other achievements is done. Two things are kept apart on purpose. The list of unlocked
achievements is the truth and only ever grows. The pop-up that tells the player is decoration: it
shows one at a time, waits in a short line, and when too many pile up the rest are folded into one
"and more" pop-up. Dropping a pop-up never drops an unlock.
Counters only go up. A "total" counter adds what it is given, a "best" counter keeps the highest
value it has seen. Time comes in as a value (`dt`). */
export interface Params {
/** How long one pop-up stays on screen, s. */
toastTime: number;
/** How many pop-ups may wait behind the one on screen; more are folded into one summary. */
queueLimit: number;
}
export const DEFAULT_PARAMS: Params = { toastTime: 3, queueLimit: 5 };
/** A timer counts as run out below this: summing dt leaves rounding error. */
const TIMER_EPSILON = 1e-9;
/** The id of the summary pop-up. */
export const MORE = "more";
export type Condition = { kind: "stat"; stat: string; target: number } | { kind: "all"; of: string[] };
export interface Achievement {
id: string;
/** Shown as a mystery until it is unlocked. */
hidden?: boolean;
when: Condition;
}
export interface Defs {
/** Every counter and how it grows. */
stats: Record<string, "total" | "best">;
achievements: Achievement[];
}
export const EXAMPLE_DEFS: Defs = {
stats: { jumps: "total", coins: "total", "best-combo": "best" },
achievements: [
{ id: "first-jump", when: { kind: "stat", stat: "jumps", target: 1 } },
{ id: "jumper", when: { kind: "stat", stat: "jumps", target: 100 } },
{ id: "combo-5", hidden: true, when: { kind: "stat", stat: "best-combo", target: 5 } },
{ id: "rich", when: { kind: "stat", stat: "coins", target: 500 } },
{ id: "all-rounder", when: { kind: "all", of: ["first-jump", "jumper", "combo-5", "rich"] } },
],
};
export type Outcome = "ok" | "ignored";
export interface State {
defs: Defs;
stats: Record<string, number>;
/** Unlocked achievements, in the order they unlocked, each once. */
unlocked: string[];
/** The pop-up on screen, or null. */
toast: string | null;
/** Seconds the pop-up has left. */
left: number;
/** Pop-ups waiting behind it. */
queue: string[];
/** Unlocks that did not fit in the line and wait to be folded into one summary. */
more: number;
outcome: Outcome;
}
export type Action = { type: "record"; stat: string; value: number } | { type: "check" } | { type: "tick"; dt: number };
export function initialState(_params: Params = DEFAULT_PARAMS, defs: Defs = EXAMPLE_DEFS, stats: Record<string, number> = {}): State {
return { defs, stats: { ...stats }, unlocked: [], toast: null, left: 0, queue: [], more: 0, outcome: "ok" };
}
export const valueOf = (state: Pick<State, "stats">, stat: string) => state.stats[stat] ?? 0;
function met(a: Achievement, state: Pick<State, "stats" | "unlocked">): boolean {
if (a.when.kind === "stat") return valueOf(state, a.when.stat) >= a.when.target;
return a.when.of.every((id) => state.unlocked.includes(id));
}
/** Puts one unlock on screen, in the line, or in the summary. */
function announce(state: State, id: string, params: Params): State {
if (state.toast === null) return { ...state, toast: id, left: params.toastTime };
if (state.queue.length < Math.max(1, Math.floor(params.queueLimit))) return { ...state, queue: [...state.queue, id] };
return { ...state, more: state.more + 1 };
}
/** Unlocks everything whose condition holds, again and again, so a "collect them all" goal unlocks in
the same moment as the last goal it waits for. */
export function unlockWhatIsMet(state: State, params: Params): State {
let s = state;
for (let pass = 0; pass <= s.defs.achievements.length; pass++) {
const next = s.defs.achievements.find((a) => !s.unlocked.includes(a.id) && met(a, s));
if (!next) break;
s = announce({ ...s, unlocked: [...s.unlocked, next.id] }, next.id, params);
}
return s;
}
export interface Progress {
id: string;
/** False while a hidden goal is still locked: the screen shows a mystery. */
revealed: boolean;
unlocked: boolean;
have: number;
target: number;
/** From 0 to 1. */
fraction: number;
}
/** What the achievements screen shows for each goal. */
export function view(state: State): Progress[] {
return state.defs.achievements.map((a) => {
const unlocked = state.unlocked.includes(a.id);
const revealed = unlocked || !a.hidden;
const target = a.when.kind === "stat" ? a.when.target : a.when.of.length;
const have = a.when.kind === "stat" ? valueOf(state, a.when.stat) : a.when.of.filter((id) => state.unlocked.includes(id)).length;
const fraction = unlocked ? 1 : target <= 0 ? 1 : Math.min(1, Math.max(0, have / target));
return { id: a.id, revealed, unlocked, have: revealed ? Math.min(have, target) : 0, target: revealed ? target : 0, fraction: revealed ? fraction : 0 };
});
}
/** Which state of the diagram the pop-ups are in. */
export function phase(state: State): "quiet" | "showing" | "backlog" | "complete" {
if (state.toast === null) return state.unlocked.length === state.defs.achievements.length ? "complete" : "quiet";
return state.queue.length > 0 || (state.more > 0 && state.toast !== MORE) ? "backlog" : "showing";
}
export function reduce(state: State, action: Action, params: Params): State {
switch (action.type) {
case "record": {
const kind = state.defs.stats[action.stat];
// A counter never goes down and a broken number counts for nothing.
if (kind === undefined || !Number.isFinite(action.value) || (kind === "total" && action.value <= 0)) return { ...state, outcome: "ignored" };
const now = valueOf(state, action.stat);
const value = kind === "total" ? now + action.value : Math.max(now, action.value);
if (!Number.isFinite(value)) return { ...state, outcome: "ignored" };
return { ...unlockWhatIsMet({ ...state, stats: { ...state.stats, [action.stat]: value } }, params), outcome: value === now ? "ignored" : "ok" };
}
case "check":
return { ...unlockWhatIsMet(state, params), outcome: "ok" };
case "tick": {
if (state.toast === null) return { ...state, outcome: "ignored" };
const left = state.left - (Number.isFinite(action.dt) ? Math.max(0, action.dt) : 0);
if (left > TIMER_EPSILON) return { ...state, left, outcome: "ok" };
// The pop-up is done. Next in line comes up with a full time of its own. A summary that ends
// has told all it held, those folded in while it showed included, so its count goes.
const more = state.toast === MORE ? 0 : state.more;
if (state.queue.length > 0) return { ...state, toast: state.queue[0], queue: state.queue.slice(1), left: params.toastTime, more, outcome: "ok" };
if (more > 0) return { ...state, toast: MORE, left: params.toastTime, outcome: "ok" };
return { ...state, toast: null, left: 0, more: 0, outcome: "ok" };
}
}
}
```
Add "Achievements" to my game.
What it should do: Achievements give the player extra goals beside the main one and a reason to try things the story never asks for. The pop-up makes a small win feel seen, and the list of goals shows what is still left to do.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> quiet
quiet: Quiet
showing: Pop-up showing
backlog: Pop-ups waiting
complete: All done
quiet --> showing: a goal unlocks
quiet --> backlog: several unlock at once
showing --> backlog: another unlocks
showing --> quiet: pop-up ends
showing --> complete: last pop-up ends
backlog --> showing: pop-up ends, next shows
complete --> [*]
```
Use these starting values:
- toastTime: 3 s
- queueLimit: 5 items
Watch out for these common mistakes:
- It unlocks every time the goal is true: Tell your AI: only unlock goals that are not in the unlocked list yet, and add a goal to the list in the same step.
- A negative or broken count takes progress away: Tell your AI: counters only go up. Ignore any count that is zero, below zero, or not a real number.
- An old save floods the screen: Tell your AI: when the game loads, check all goals once, show a few pop-ups, and fold the rest into one 'and more' pop-up.
- A dropped pop-up loses the unlock: Tell your AI: the list of unlocked goals is the truth. Write it first and treat the pop-up as decoration that may be left out.
- A secret goal shows its progress: Tell your AI: for a hidden goal that is still locked, send no counter value, no target and no progress to the screen.
- A best-of counter is added up: Tell your AI: say for each counter whether it adds up or keeps the best value, and keep the higher one for best-of counters.
- A goal with a target of zero or less: Tell your AI: a goal with a target of zero or less counts as already met, and its progress is shown as full.
- A collect-them-all goal names a goal that does not exist: Tell your AI: when the game starts, check that every goal named in a collect-them-all goal exists, and report any that does not.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.The tested code (TypeScript)
/* Achievements: goals that unlock once, when a counter the game keeps reaches a target, or when a
group of other achievements is done. Two things are kept apart on purpose. The list of unlocked
achievements is the truth and only ever grows. The pop-up that tells the player is decoration: it
shows one at a time, waits in a short line, and when too many pile up the rest are folded into one
"and more" pop-up. Dropping a pop-up never drops an unlock.
Counters only go up. A "total" counter adds what it is given, a "best" counter keeps the highest
value it has seen. Time comes in as a value (`dt`). */
export interface Params {
/** How long one pop-up stays on screen, s. */
toastTime: number;
/** How many pop-ups may wait behind the one on screen; more are folded into one summary. */
queueLimit: number;
}
export const DEFAULT_PARAMS: Params = { toastTime: 3, queueLimit: 5 };
/** A timer counts as run out below this: summing dt leaves rounding error. */
const TIMER_EPSILON = 1e-9;
/** The id of the summary pop-up. */
export const MORE = "more";
export type Condition = { kind: "stat"; stat: string; target: number } | { kind: "all"; of: string[] };
export interface Achievement {
id: string;
/** Shown as a mystery until it is unlocked. */
hidden?: boolean;
when: Condition;
}
export interface Defs {
/** Every counter and how it grows. */
stats: Record<string, "total" | "best">;
achievements: Achievement[];
}
export const EXAMPLE_DEFS: Defs = {
stats: { jumps: "total", coins: "total", "best-combo": "best" },
achievements: [
{ id: "first-jump", when: { kind: "stat", stat: "jumps", target: 1 } },
{ id: "jumper", when: { kind: "stat", stat: "jumps", target: 100 } },
{ id: "combo-5", hidden: true, when: { kind: "stat", stat: "best-combo", target: 5 } },
{ id: "rich", when: { kind: "stat", stat: "coins", target: 500 } },
{ id: "all-rounder", when: { kind: "all", of: ["first-jump", "jumper", "combo-5", "rich"] } },
],
};
export type Outcome = "ok" | "ignored";
export interface State {
defs: Defs;
stats: Record<string, number>;
/** Unlocked achievements, in the order they unlocked, each once. */
unlocked: string[];
/** The pop-up on screen, or null. */
toast: string | null;
/** Seconds the pop-up has left. */
left: number;
/** Pop-ups waiting behind it. */
queue: string[];
/** Unlocks that did not fit in the line and wait to be folded into one summary. */
more: number;
outcome: Outcome;
}
export type Action = { type: "record"; stat: string; value: number } | { type: "check" } | { type: "tick"; dt: number };
export function initialState(_params: Params = DEFAULT_PARAMS, defs: Defs = EXAMPLE_DEFS, stats: Record<string, number> = {}): State {
return { defs, stats: { ...stats }, unlocked: [], toast: null, left: 0, queue: [], more: 0, outcome: "ok" };
}
export const valueOf = (state: Pick<State, "stats">, stat: string) => state.stats[stat] ?? 0;
function met(a: Achievement, state: Pick<State, "stats" | "unlocked">): boolean {
if (a.when.kind === "stat") return valueOf(state, a.when.stat) >= a.when.target;
return a.when.of.every((id) => state.unlocked.includes(id));
}
/** Puts one unlock on screen, in the line, or in the summary. */
function announce(state: State, id: string, params: Params): State {
if (state.toast === null) return { ...state, toast: id, left: params.toastTime };
if (state.queue.length < Math.max(1, Math.floor(params.queueLimit))) return { ...state, queue: [...state.queue, id] };
return { ...state, more: state.more + 1 };
}
/** Unlocks everything whose condition holds, again and again, so a "collect them all" goal unlocks in
the same moment as the last goal it waits for. */
export function unlockWhatIsMet(state: State, params: Params): State {
let s = state;
for (let pass = 0; pass <= s.defs.achievements.length; pass++) {
const next = s.defs.achievements.find((a) => !s.unlocked.includes(a.id) && met(a, s));
if (!next) break;
s = announce({ ...s, unlocked: [...s.unlocked, next.id] }, next.id, params);
}
return s;
}
export interface Progress {
id: string;
/** False while a hidden goal is still locked: the screen shows a mystery. */
revealed: boolean;
unlocked: boolean;
have: number;
target: number;
/** From 0 to 1. */
fraction: number;
}
/** What the achievements screen shows for each goal. */
export function view(state: State): Progress[] {
return state.defs.achievements.map((a) => {
const unlocked = state.unlocked.includes(a.id);
const revealed = unlocked || !a.hidden;
const target = a.when.kind === "stat" ? a.when.target : a.when.of.length;
const have = a.when.kind === "stat" ? valueOf(state, a.when.stat) : a.when.of.filter((id) => state.unlocked.includes(id)).length;
const fraction = unlocked ? 1 : target <= 0 ? 1 : Math.min(1, Math.max(0, have / target));
return { id: a.id, revealed, unlocked, have: revealed ? Math.min(have, target) : 0, target: revealed ? target : 0, fraction: revealed ? fraction : 0 };
});
}
/** Which state of the diagram the pop-ups are in. */
export function phase(state: State): "quiet" | "showing" | "backlog" | "complete" {
if (state.toast === null) return state.unlocked.length === state.defs.achievements.length ? "complete" : "quiet";
return state.queue.length > 0 || (state.more > 0 && state.toast !== MORE) ? "backlog" : "showing";
}
export function reduce(state: State, action: Action, params: Params): State {
switch (action.type) {
case "record": {
const kind = state.defs.stats[action.stat];
// A counter never goes down and a broken number counts for nothing.
if (kind === undefined || !Number.isFinite(action.value) || (kind === "total" && action.value <= 0)) return { ...state, outcome: "ignored" };
const now = valueOf(state, action.stat);
const value = kind === "total" ? now + action.value : Math.max(now, action.value);
if (!Number.isFinite(value)) return { ...state, outcome: "ignored" };
return { ...unlockWhatIsMet({ ...state, stats: { ...state.stats, [action.stat]: value } }, params), outcome: value === now ? "ignored" : "ok" };
}
case "check":
return { ...unlockWhatIsMet(state, params), outcome: "ok" };
case "tick": {
if (state.toast === null) return { ...state, outcome: "ignored" };
const left = state.left - (Number.isFinite(action.dt) ? Math.max(0, action.dt) : 0);
if (left > TIMER_EPSILON) return { ...state, left, outcome: "ok" };
// The pop-up is done. Next in line comes up with a full time of its own. A summary that ends
// has told all it held, those folded in while it showed included, so its count goes.
const more = state.toast === MORE ? 0 : state.more;
if (state.queue.length > 0) return { ...state, toast: state.queue[0], queue: state.queue.slice(1), left: params.toastTime, more, outcome: "ok" };
if (more > 0) return { ...state, toast: MORE, left: params.toastTime, outcome: "ok" };
return { ...state, toast: null, left: 0, more: 0, outcome: "ok" };
}
}
}
The tests the reference code passes
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { forAll, pick, real, seeded, type Rng } from "../../../proofs/property.ts";
import { type Action, DEFAULT_PARAMS, type Defs, EXAMPLE_DEFS, MORE, type Params, type State, initialState, phase, reduce, unlockWhatIsMet, valueOf, view } from "./reference.ts";
const P = DEFAULT_PARAMS;
const record = (stat: string, value: number): Action => ({ type: "record", stat, value });
const check: Action = { type: "check" };
const tick = (dt: number): Action => ({ type: "tick", dt });
const run = (s: State, ...actions: Action[]) => actions.reduce((acc, a) => reduce(acc, a, P), s);
const near = (a: number, b: number) => assert.ok(Math.abs(a - b) < 1e-9, `${a} is not ${b}`);
test("first-unlock-happens-once", () => {
let s = run(initialState(P), record("jumps", 1));
assert.deepEqual(s.unlocked, ["first-jump"]);
assert.equal(s.toast, "first-jump");
assert.equal(s.left, 3);
s = run(s, record("jumps", 1), record("jumps", 1));
assert.deepEqual(s.unlocked, ["first-jump"]);
assert.deepEqual(s.queue, []);
});
test("reaching-the-target-unlocks", () => {
let s = run(initialState(P), record("jumps", 99));
assert.deepEqual(s.unlocked, ["first-jump"]);
s = run(s, record("jumps", 1));
assert.deepEqual(s.unlocked, ["first-jump", "jumper"]);
assert.equal(valueOf(s, "jumps"), 100);
});
test("total-adds-and-best-keeps-the-highest", () => {
let s = run(initialState(P), record("coins", 30), record("coins", 20));
assert.equal(valueOf(s, "coins"), 50);
s = run(s, record("best-combo", 4), record("best-combo", 3));
assert.equal(valueOf(s, "best-combo"), 4);
s = run(s, record("best-combo", 6));
assert.equal(valueOf(s, "best-combo"), 6);
});
test("stats-never-go-down-and-bad-numbers-count-for-nothing", () => {
const base = run(initialState(P), record("coins", 40), record("best-combo", 4));
for (const bad of [-5, 0, Number.NaN, Number.POSITIVE_INFINITY]) {
const s = reduce(base, record("coins", bad), P);
assert.equal(valueOf(s, "coins"), 40);
assert.equal(s.outcome, "ignored");
}
assert.equal(reduce(base, record("best-combo", 2), P).outcome, "ignored");
assert.equal(valueOf(reduce(base, record("best-combo", Number.NaN), P), "best-combo"), 4);
});
test("several-unlock-at-once-show-one-after-another", () => {
const s = run(initialState(P), record("jumps", 100));
assert.deepEqual(s.unlocked, ["first-jump", "jumper"]);
assert.equal(s.toast, "first-jump");
assert.deepEqual(s.queue, ["jumper"]);
assert.equal(phase(s), "backlog");
});
test("toast-ends-after-its-time", () => {
let s = run(initialState(P), record("jumps", 100), tick(2.9));
assert.equal(s.toast, "first-jump");
near(s.left, 0.1);
s = run(s, tick(0.1));
assert.equal(s.toast, "jumper");
assert.equal(s.left, 3);
assert.deepEqual(s.queue, []);
s = run(s, tick(3));
assert.equal(s.toast, null);
assert.equal(phase(s), "quiet");
});
test("too-many-toasts-become-a-summary", () => {
const one = { ...P, queueLimit: 1 };
let s = reduce(initialState(one, EXAMPLE_DEFS, { jumps: 100, coins: 500, "best-combo": 5 }), check, one);
assert.equal(s.unlocked.length, 5);
assert.equal(s.toast, "first-jump");
assert.deepEqual(s.queue, ["jumper"]);
assert.equal(s.more, 3);
s = reduce(s, tick(3), one);
assert.equal(s.toast, "jumper");
s = reduce(s, tick(3), one);
assert.equal(s.toast, MORE);
assert.equal(s.more, 3);
assert.equal(phase(s), "showing");
s = reduce(s, tick(3), one);
assert.equal(s.toast, null);
assert.equal(s.more, 0);
assert.equal(phase(s), "complete");
});
test("collect-them-all-unlocks-in-the-same-moment", () => {
let s = run(initialState(P), record("jumps", 100), record("best-combo", 5));
assert.ok(!s.unlocked.includes("all-rounder"));
s = run(s, record("coins", 500));
assert.deepEqual(s.unlocked.slice(-2), ["rich", "all-rounder"]);
});
test("hidden-stays-hidden-until-unlocked", () => {
const before = view(initialState(P)).find((p) => p.id === "combo-5")!;
assert.deepEqual([before.revealed, before.target, before.have, before.fraction], [false, 0, 0, 0]);
const progressed = view(run(initialState(P), record("best-combo", 3))).find((p) => p.id === "combo-5")!;
assert.equal(progressed.revealed, false);
const after = view(run(initialState(P), record("best-combo", 5))).find((p) => p.id === "combo-5")!;
assert.deepEqual([after.revealed, after.unlocked, after.have, after.target], [true, true, 5, 5]);
});
test("progress-is-capped-at-the-goal", () => {
const jumper = (s: State) => view(s).find((p) => p.id === "jumper")!;
const part = jumper(run(initialState(P), record("jumps", 25)));
assert.deepEqual([part.have, part.target, part.fraction], [25, 100, 0.25]);
const over = jumper(run(initialState(P), record("jumps", 250)));
assert.deepEqual([over.have, over.fraction], [100, 1]);
});
test("check-unlocks-what-is-already-met", () => {
const s = reduce(initialState(P, EXAMPLE_DEFS, { coins: 500 }), check, P);
assert.deepEqual(s.unlocked, ["rich"]);
assert.equal(s.toast, "rich");
});
test("unknown-stat-is-ignored", () => {
const s = reduce(initialState(P), record("swims", 3), P);
assert.equal(s.outcome, "ignored");
assert.deepEqual(s.stats, {});
});
test("edge-it-unlocks-every-time-the-goal-is-true", () => {
let s = initialState(P);
for (let n = 0; n < 30; n++) s = run(s, record("jumps", 1), tick(5));
assert.equal(s.unlocked.filter((id) => id === "first-jump").length, 1);
assert.equal(s.unlocked.length, 1);
});
test("edge-a-negative-or-broken-count-takes-progress-away", () => {
const s = run(initialState(P), record("jumps", 10), record("jumps", -4), record("jumps", Number.NaN));
assert.equal(valueOf(s, "jumps"), 10);
});
test("edge-an-old-save-floods-the-screen", () => {
const s = reduce(initialState(P, EXAMPLE_DEFS, { jumps: 1000, coins: 1000, "best-combo": 9 }), check, P);
assert.equal(s.unlocked.length, 5);
assert.ok(s.queue.length <= P.queueLimit);
});
test("edge-a-dropped-pop-up-loses-the-unlock", () => {
const one = { ...P, queueLimit: 1 };
const s = reduce(initialState(one, EXAMPLE_DEFS, { jumps: 100, coins: 500, "best-combo": 5 }), check, one);
assert.equal(s.queue.length + 1 + s.more, s.unlocked.length);
assert.ok(s.unlocked.includes("all-rounder"));
});
test("a-summary-tells-each-unlock-once", () => {
// Found by the TLA+ check: a summary that ended while the line still had a pop-up kept its count,
// so the next summary told the same unlocks again.
const one = { ...P, queueLimit: 1 };
const defs: Defs = { stats: { n: "total" }, achievements: [1, 2, 3, 4, 5, 6].map((t) => ({ id: `g${t}`, when: { kind: "stat" as const, stat: "n", target: t } })) };
let s = reduce(initialState(one, defs), record("n", 4), one);
s = reduce(reduce(s, tick(3), one), tick(3), one);
assert.equal(s.toast, MORE);
assert.equal(s.more, 2);
s = reduce(s, record("n", 2), one);
assert.deepEqual([s.queue, s.more], [["g5"], 3]);
s = reduce(s, tick(3), one);
assert.equal(s.toast, "g5");
assert.equal(s.more, 0);
s = reduce(s, tick(3), one);
assert.equal(s.toast, null);
assert.equal(phase(s), "complete");
});
test("edge-a-secret-goal-shows-its-progress", () => {
const secret = view(run(initialState(P), record("best-combo", 4))).find((p) => p.id === "combo-5")!;
assert.equal(secret.have, 0);
assert.equal(secret.target, 0);
});
test("edge-a-best-counter-is-added-up", () => {
const s = run(initialState(P), record("best-combo", 3), record("best-combo", 3));
assert.equal(valueOf(s, "best-combo"), 3);
assert.ok(!s.unlocked.includes("combo-5"));
});
test("edge-a-goal-with-a-target-of-zero-or-less", () => {
const defs = { stats: { steps: "total" as const }, achievements: [{ id: "welcome", when: { kind: "stat" as const, stat: "steps", target: 0 } }] };
const s = unlockWhatIsMet(initialState(P, defs), P);
assert.deepEqual(s.unlocked, ["welcome"]);
assert.equal(view(s)[0].fraction, 1);
});
test("edge-a-collect-them-all-goal-that-names-a-missing-goal", () => {
const defs = { stats: {}, achievements: [{ id: "all", when: { kind: "all" as const, of: ["nothing-here"] } }] };
const s = unlockWhatIsMet(initialState(P, defs), P);
assert.deepEqual(s.unlocked, []);
});
const LISTED: { name: keyof Params; min: number; max: number }[] = JSON.parse(readFileSync(new URL("./mechanic.json", import.meta.url), "utf8")).spec.parameters;
function anyParams(r: Rng): Params {
const values = LISTED.map(({ name, min, max }) => [name, pick(r, [min, max, real(r, min, max), Math.round(real(r, min, max))])]);
return Object.fromEntries(values);
}
function anyAction(r: Rng): Action {
const stat = pick(r, ["jumps", "coins", "best-combo", "unknown"]);
const value = pick(r, [1, 3, 25, 120, 600, real(r, -5, 400), Number.NaN]);
return pick<Action>(r, [record(stat, value), record(stat, value), record(stat, value), check, tick(pick(r, [0.5, 3, 4, real(r, 0, 5), -1, Number.NaN])), tick(3), tick(3)]);
}
test("property: an unlock happens once and only when its goal holds", (t) => {
forAll(t, 141, 400, (r) => {
const params = anyParams(r);
let s = initialState(params);
for (let n = 0; n < 200; n++) {
s = reduce(s, anyAction(r), params);
assert.equal(new Set(s.unlocked).size, s.unlocked.length);
for (const id of s.unlocked) {
const a = s.defs.achievements.find((x) => x.id === id)!;
if (a.when.kind === "stat") assert.ok(valueOf(s, a.when.stat) >= a.when.target);
else for (const need of a.when.of) assert.ok(s.unlocked.indexOf(need) < s.unlocked.indexOf(id));
}
}
});
});
test("property: counters never go down and unlocks never go away", (t) => {
forAll(t, 142, 400, (r) => {
const params = anyParams(r);
let s = initialState(params);
for (let n = 0; n < 200; n++) {
const before = s;
s = reduce(s, anyAction(r), params);
for (const stat of Object.keys(before.stats)) assert.ok(valueOf(s, stat) >= valueOf(before, stat) && Number.isFinite(valueOf(s, stat)));
assert.deepEqual(s.unlocked.slice(0, before.unlocked.length), before.unlocked);
}
});
});
test("property: the line of pop-ups stays short and every unlock is accounted for", (t) => {
forAll(t, 143, 400, (r) => {
const params = anyParams(r);
let s = initialState(params);
let shown = 0;
let folded = 0;
for (let n = 0; n < 250; n++) {
const before = s;
s = reduce(s, anyAction(r), params);
assert.ok(s.queue.length <= Math.max(1, params.queueLimit));
assert.ok(s.left >= 0 && (s.toast !== null || s.left === 0));
if (s.toast !== null && s.toast !== before.toast && s.toast !== MORE) shown++;
if (s.more > before.more) folded += s.more - before.more;
if (s.toast === null) assert.deepEqual(s.queue, []);
// Every unlock was shown, waits in the line, or was folded into the summary. None is lost.
assert.equal(s.unlocked.length, shown + s.queue.length + folded);
}
});
});
/* The diagram in mechanic.json. Staying in the same state is not a move, so only changes count. */
const MODEL: { states: { id: string; start?: boolean }[]; moves: { from: string; to: string }[] } = JSON.parse(readFileSync(new URL("./mechanic.json", import.meta.url), "utf8")).model;
function observe(params: Params, seed: number): { changes: Set<string>; seen: Set<string> } {
const r = seeded(seed);
const changes = new Set<string>();
const seen = new Set<string>();
for (let episode = 0; episode < 120; episode++) {
// Some games start from a save that already meets many goals.
const stats: Record<string, number> = episode % 4 === 0 ? { jumps: 100, coins: 500, "best-combo": 5 } : episode % 4 === 1 ? { jumps: 1000 } : {};
let s = initialState(params, EXAMPLE_DEFS, stats);
if (episode % 4 < 2 && r() < 0.5) s = reduce(s, check, params);
seen.add(phase(s));
for (let n = 0; n < 60; n++) {
const before = phase(s);
s = reduce(s, anyAction(r), params);
const after = phase(s);
seen.add(after);
if (after !== before) changes.add(`${before}>${after}`);
}
}
return { changes, seen };
}
test("model-matches-code", () => {
assert.equal(phase(initialState()), MODEL.states.find((s) => s.start)?.id);
const listed = new Set(MODEL.moves.map((m) => `${m.from}>${m.to}`));
const ids = new Set(MODEL.states.map((s) => s.id));
const cases: Params[] = [P];
for (const { name, min, max } of LISTED) for (const value of [min, max]) cases.push({ ...P, [name]: value });
const allChanges = new Set<string>();
const allSeen = new Set<string>();
cases.forEach((params, i) => {
const { changes, seen } = observe(params, 700 + i);
for (const move of changes) assert.ok(listed.has(move), `the code does a move the diagram does not list: ${move} (case ${i})`);
for (const id of seen) assert.ok(ids.has(id), `the code reaches a state the diagram does not list: ${id}`);
changes.forEach((c) => allChanges.add(c));
seen.forEach((c) => allSeen.add(c));
});
for (const id of ids) assert.ok(allSeen.has(id), `the diagram lists a state the code never reaches: ${id}`);
for (const move of listed) assert.ok(allChanges.has(move), `the diagram lists a move the code never makes: ${move}`);
});
Was this page helpful?
Next step
Sources
- Kyle Hilliard, Activision Badges: The Original Gaming Achievement, Game Informer, 26 October 2013
- Kevin Bunch, Dragster: August 1980, Atari Archive, 8 October 2025
- Dragster instruction manual, Activision, 1980 (text copy, textfiles.com)
- Wikipedia, Achievement (video games)
- Ben Medler, Generations of Game Analytics, Achievements and High Scores, Eludamos 3(2), 2009
- Microsoft, Xbox 360 Ushers in the Future of Games and Entertainment, 12 May 2005
- Microsoft, Robbie Bach, J Allard and Peter Moore at E3 2005 (transcript), 16 May 2005
- Mary Jane Irwin, Unlocking Achievements: Rewarding Skill With Player Incentives, Game Developer, 1 April 2009
- Eric Lempel, Firmware v2.40 Walkthrough Part 2: Trophies, PlayStation Blog, 30 June 2008
- Andrew Yoon, Everything you need to know about firmware 2.40, Engadget, 30 June 2008
- Steam news, 7 May 2009
- Major Nelson, Xbox One Achievements, Xbox Wire, 12 June 2013
- Xbox Wire, Xbox holiday update, 10 November 2016
- Juho Hamari and Veikko Eranti, Framework for Designing and Evaluating Game Achievements, DiGRA 2011