Sub topic 3
Dynamic difficulty adjustment and its limits
This chapter assumes you know how a game records player outcomes, and that you can read TypeScript functions and object types.
Dynamic difficulty adjustment (DDA) changes enemy strength during play based on how the player is doing. It can rescue a player who keeps failing. It can also hide real skill gains, and players who notice it may feel the game is cheating. Treat DDA as a small, bounded nudge around the player's chosen preset.
Implementing a bounded adjuster
The function below moves a scale value toward a target fail rate in small steps and keeps it inside a fixed range.
const clamp = (value: number, min: number, max: number): number =>
Math.min(max, Math.max(min, value));
const TARGET_FAIL_RATE = 0.3;
const MIN_SCALE = 0.7;
const MAX_SCALE = 1.3;
const MAX_STEP = 0.05;
// scale multiplies enemy strength; outcomes holds recent attempts (true = success).
function adjustScale(scale: number, outcomes: boolean[]): number {
if (outcomes.length < 5) return scale; // not enough evidence yet
const failRate = outcomes.filter((ok) => !ok).length / outcomes.length;
const delta = clamp((TARGET_FAIL_RATE - failRate) * 0.2, -MAX_STEP, MAX_STEP);
return clamp(scale + delta, MIN_SCALE, MAX_SCALE);
}Limits to design around
- Range: The clamp keeps DDA within a band around the preset. The preset still defines the player's baseline.
- Evidence: The adjuster waits for enough attempts, so one bad streak does not move the scale.
- Visibility: Tell players when DDA is active. Hidden adjustment that players later discover damages trust.
Naming and describing options without shaming players
Use neutral preset names such as "Story," "Standard," and "Challenge." Describe the effect, not the player. Write "Enemies deal half damage," not "For players who struggle."
Defaults and first-run choices
Ask once at first launch and pre-select the most common path, such as "Standard." Let players change the choice at any time. Avoid a skill quiz that labels the player.
Changing settings mid-game
Apply changes at a checkpoint or menu, and start them with the next encounter, not the current fight. Log each change for telemetry.
Assists, leaderboards, achievements, and multiplayer fairness
Assists change the rules of a run. Mark assisted runs on leaderboards, exclude them from ranked modes, and note assist use on difficulty-based achievements. In multiplayer, match assist settings across players or limit assists to solo modes.
Testing and measuring across skill levels
Playtest with players at several skill levels. Track fail rate, quit points, preset choices, and mid-game switches for each group. If a preset's fail rate sits far from its target, adjust the numbers before you add more options.
Exercise
Exercise
The player's fail rate over the last 10 attempts is 0.6, and the current scale is 1.0. What does adjustScale return?
Show answer
The delta is (0.3 - 0.6) * 0.2 = -0.06. The clamp limits it to -0.05, so the function returns 0.95.