Dynamic Difficulty
Dynamic difficulty watches how the player is doing and moves the game one small step easier or harder, aiming for a steady win rate. It judges only after enough results, waits after every change, stays inside a floor and a ceiling, and leaves a gap where a player who is doing fine is left alone.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Dynamic Difficulty" to my game.
What it should do: Players struggle and coast at different times. Nudging the challenge toward what each player can handle keeps a stuck player in the game and a strong player interested, without asking them to pick a setting.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> settling
settling: Gathering results
watching: Watching
easiest: At the easiest
hardest: At the hardest
settling --> watching: enough results
settling --> easiest: enough, at the floor
settling --> hardest: enough, at the ceiling
watching --> settling: changes, or returns
easiest --> settling: toughens, or returns
hardest --> settling: eases, or returns
```
Use these starting values:
- target: 0.7
- tolerance: 0.2
- alpha: 0.2
- minResults: 6 results
- maxEase: 3 steps
- maxToughen: 2 steps
- stepSize: 0.1 x
Watch out for these common mistakes:
- The game swings up and down: Tell your AI: after a change, set the average back to the target and wait for several new results before judging again.
- Easing off with no floor: Tell your AI: set an easiest level that still has some danger, and stop easing there.
- One bad night remembered forever: Tell your AI: when the player returns, keep the level but wipe the recent results, so the game starts watching afresh.
- Unfair deaths count as lost fights: Tell your AI: only report a result for fights that were fair, and leave out ones that ended for outside reasons.
- A quiet zone is missing: Tell your AI: only react beyond a band on each side of the target, and do nothing inside it.
- The change hits in the middle of a fight: Tell your AI: read the strength once when an encounter starts and keep it until the encounter ends.
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.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
Players struggle and coast at different times. Nudging the challenge toward what each player can handle keeps a stuck player in the game and a strong player interested, without asking them to pick a setting.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Gathering results → Watching: enough results
- Gathering results → At the easiest: enough, at the floor
- Gathering results → At the hardest: enough, at the ceiling
- Watching → Gathering results: changes, or returns
- At the easiest → Gathering results: toughens, or returns
- At the hardest → Gathering results: eases, or returns
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| target | 0.7 | The share of encounters the player should win. Seven in ten feels like a challenge that can be beaten. Much above three quarters leaves too little room for the high band. |
| tolerance | 0.2 | How far the average may stray from the target before the game reacts. The gap on both sides is the quiet zone where it leaves the player alone, and a narrow one makes the game twitchy. |
| alpha | 0.2 | How much each new result counts. At 0.2 the last five or so results matter most. A higher number reacts faster and also to luck. |
| minResults | 6 results | Results needed after a change before the game judges again. Too few and a lucky or unlucky streak moves the game back and forth. |
| maxEase | 3 steps | How far the game may ease off. The floor keeps a player who is truly stuck from getting an empty game. |
| maxToughen | 2 steps | How far the game may push back. Smaller than the way down, because a skilled player is better served by a harder fixed setting they choose. |
| stepSize | 0.1 x | How much stronger the enemies get with each step up. Ten in a hundred is small enough that one step is not noticed on its own. |
What usually goes wrong
The game swings up and down
If the game judges after every result and the average is not reset, a bad fight makes it easier, the next easy fight makes it harder, and the player feels the difficulty jump around.
Fix: Tell your AI: after a change, set the average back to the target and wait for several new results before judging again.
Easing off with no floor
Some games ease off without limit, so a player who keeps failing ends up in an empty game that no longer feels like a game.
Fix: Tell your AI: set an easiest level that still has some danger, and stop easing there.
One bad night remembered forever
A player who had a terrible evening comes back a week later to a game still on the easiest setting, or still counting that streak against them.
Fix: Tell your AI: when the player returns, keep the level but wipe the recent results, so the game starts watching afresh.
Unfair deaths count as lost fights
A death from a crash, a bug or a scripted trap is counted as a lost fight, and the game eases off for a player who did nothing wrong.
Fix: Tell your AI: only report a result for fights that were fair, and leave out ones that ended for outside reasons.
A quiet zone is missing
If the game reacts to any move away from the target, a player who is doing fine still sees the difficulty changing, because no player hits exactly seven in ten.
Fix: Tell your AI: only react beyond a band on each side of the target, and do nothing inside it.
The change hits in the middle of a fight
An enemy that suddenly gets tougher while the player is fighting it feels like a cheat.
Fix: Tell your AI: read the strength once when an encounter starts and keep it until the encounter ends.
How to check it works
- A new game with the starting values. The player loses 5 fights in a row: The difficulty has not changed yet.
- A new game with the starting values. The player loses 6 fights in a row: The difficulty goes one step down.
- A new game with the starting values. The player wins 6 fights in a row: The difficulty goes one step up.
- The difficulty has just gone one step down. The player loses 5 more fights, then a sixth: It holds for the first five and goes another step down on the sixth.
- A player who wins seven fights in ten, over 300 fights. You follow the difficulty: It never leaves normal, and the average stays between 0.5 and 0.9.
- A player who loses every fight. 200 fights have passed: The difficulty sits at the easiest level and goes no lower.
- A player who wins every fight. 200 fights have passed: The difficulty sits at the hardest level and goes no higher.
- A game that has eased down to the easiest level. The player then wins 30 fights: The difficulty comes back up from the floor.
- A game one step down and 4 losses into the next stretch. The player comes back to the game: The level is still one step down and the streak is wiped.
- A step size of 0.1. You ask for the enemy strength at levels 0, 1, -1 and 2: It is 1, 1.1, a little over 0.909 and 1.21.
Works well with
- Health and Damage: Scale the enemies' damage and health by the strength, read once when the encounter starts.
- Bad Luck Protection: Both smooth out what the player feels. Keep them on different things, the fights for one and the drops for the other.
Clashes with Difficulty Settings: A player who chose hard may find the game quietly easing off, and a player who chose relaxed may find it toughening up. Let the adaptive part work only inside the chosen setting, and tell the player when it is on.
Clashes with Meta-Progression: Upgrades earned over many runs make the player stronger, and an adaptive game answers by making the game harder, so the upgrades seem to do nothing. Pick one to lead. Base the adaptive steps on a level that already includes the upgrades, or keep the steps small.
Common questions
what do i tell my ai to add dynamic difficulty
Paste this: Add dynamic difficulty: keep a running average of wins and losses, judge only after at least 6 results since the last change, move one step easier below a win rate of 50 percent and one step harder above 90 percent, reset the average after every change, and stay between a floor and a ceiling.
does dynamic difficulty annoy players
It can, when it is obvious. Small steps, a quiet zone where nothing changes and a pause after every change keep it unnoticed. Some players dislike it on principle, so let them switch it off.
what should dynamic difficulty measure
Fair encounter results are the simplest: won or lost. Hits taken and time to finish also work, but each extra number is one more thing to tune and to get wrong.
how is dynamic difficulty different from difficulty settings
Difficulty settings are a choice the player makes once and can see. Dynamic difficulty is decided by the game from how the player plays. The two can live together if the adaptive steps stay inside the chosen setting.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 15 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.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it