Bad Luck Protection
Bad luck protection keeps a player from going empty-handed for ever. The chance of a rare prize starts low and stays flat for a while. After that it rises with every miss, until one last try is certain. Only a hit sets the count of misses back to zero.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Bad Luck Protection" to my game.
What it should do: A pure chance can hand some players a hundred misses in a row while others win at once. A rising chance and a certain last try give every player a fair worst case, and the rare prize still feels like luck.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> normal
normal: Base chance
rising: Chance rising
guaranteed: Next try sure
normal --> normal: hit or miss
normal --> rising: misses pile up
normal --> guaranteed: cap comes close
rising --> rising: another miss
rising --> normal: a hit
rising --> guaranteed: cap comes close
guaranteed --> normal: the sure hit
```
Use these starting values:
- baseChance: 0.02
- softStart: 40
- softStep: 0.02
- hardCap: 60
Watch out for these common mistakes:
- Any drop resets the count: Tell your AI: keep one count for each protected prize, and reset it only when that prize drops.
- The sure hit comes one try late: Tell your AI: with a cap of 60, after 59 misses in a row the next try, number 60, is the certain one.
- The chance drifts or goes past 100 percent: Tell your AI: work the chance out from the count of misses each time, and cap it at one.
- A lucky early hit does not reset the count: Tell your AI: every hit, lucky or certain, sets the count back to zero.
- The count is lost when the game closes: Tell your AI: save the count with the player's game, and load it back before the first try.
- A new cap below the old count: Tell your AI: make a try certain when the count is at or above the cap minus one, not only when it is exactly equal.
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
A pure chance can hand some players a hundred misses in a row while others win at once. A rising chance and a certain last try give every player a fair worst case, and the rare prize still feels like luck.
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
- Base chance → Base chance: hit or miss
- Base chance → Chance rising: misses pile up
- Base chance → Next try sure: cap comes close
- Chance rising → Chance rising: another miss
- Chance rising → Base chance: a hit
- Chance rising → Next try sure: cap comes close
- Next try sure → Base chance: the sure hit
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| baseChance | 0.02 | The chance of a hit on a fresh counter, as a share of one. 0.02 is 2 in 100. It is never zero, or a player with a fresh counter could not win before the rise starts. |
| softStart | 40 | How many misses in a row leave the chance at its base. Until then a miss costs nothing extra. At 40 with a base of 0.02, about 55 players in 100 have won before the rise begins. |
| softStep | 0.02 | What each further miss adds to the chance. 0.02 adds 2 points per miss. At 0 the chance never rises, and only the certain last try protects. |
| hardCap | 60 | The try number that is certain, so the longest dry spell a player can have. Choose the longest wait you would accept, and keep it above the soft start, or the rise never begins. |
What usually goes wrong
Any drop resets the count
The count is shared by every prize. A common drop resets it, so the player who is waiting for the rare prize never gets protected.
Fix: Tell your AI: keep one count for each protected prize, and reset it only when that prize drops.
The sure hit comes one try late
The code makes the try after the cap certain instead of the try at the cap. A player with a cap of 60 waits for try 61, and the promise on the box is wrong.
Fix: Tell your AI: with a cap of 60, after 59 misses in a row the next try, number 60, is the certain one.
The chance drifts or goes past 100 percent
The code adds a step to the last chance after every miss. Small rounding errors pile up, and with a big step the chance climbs past one, which can break later checks.
Fix: Tell your AI: work the chance out from the count of misses each time, and cap it at one.
A lucky early hit does not reset the count
Only the certain try resets the count. A player who wins by luck at try 5 still carries 4 misses, and gets the rising chance far too soon for the next prize.
Fix: Tell your AI: every hit, lucky or certain, sets the count back to zero.
The count is lost when the game closes
The count lives only while the game runs. A player who has missed 50 times closes the game and starts again at zero, and the protection means nothing.
Fix: Tell your AI: save the count with the player's game, and load it back before the first try.
A new cap below the old count
An update lowers the cap from 60 to 30, and a player already has 45 misses. The code looks for exactly try 30 and never finds it, so the player gets no protection at all.
Fix: Tell your AI: make a try certain when the count is at or above the cap minus one, not only when it is exactly equal.
How to check it works
- A fresh counter with a base chance of 2 percent. you roll 0.0199 and then, on another fresh counter, 0.02: the first is a hit and the second a miss.
- A base of 2 percent, a flat stretch of 40 misses and a step of 2 points. you look at the chance after 40, 41, 50 and 58 misses: it is 2, 4, 22 and 38 percent.
- The cap is 60 and you have missed 59 times in a row. you try the 60th time with the worst roll there is, 1, or not a number: it hits, and one try earlier with the same bad roll it does not.
- You have missed 45 times in a row. the next try hits: the count of misses is zero and the chance is back to 2 percent.
- You have missed 10 times in a row. the next try hits by plain luck: the count of misses is zero too.
- A fresh counter. you miss 3 times: the count is 3, with 3 tries and no hits.
- A fresh counter. the roll is not a number, or 1, or 5: it is a miss, because the chance is only 2 percent.
- A base of 50 percent and a step of 50 points. you look at the chance after 1 miss, and after 400: it is 100 percent both times, and never more.
- The starting values, where a plain 2 percent takes 50 tries on average. you work out the average wait exactly: it is between 31 and 32 tries, and about 1 player in 190 needs the certain last try.
Works well with
- Loot Table: Count a miss only for tries that could have given the prize, not for tries on a different table. Roll the table first. Then check the miss count for the protected prize, and override the result with that prize when its try is certain.
- Item Rarity: When luck and protection are both in play, protection wins. A certain try is never made less certain by luck. Protect one tier, usually the top one. The count watches that tier, and a certain try picks it without rolling.
- Crafting System: Tell the player how close they are to the sure try, or the protection feels like a secret. Count each failed upgrade attempt on the item it belongs to. A certain attempt succeeds before materials are taken.
Common questions
how does bad luck protection work in games
The game counts misses in a row. The chance stays flat for a while, then rises with every miss, and after a set number of tries the next one always wins. A win sets the count back to zero.
how many tries before a guaranteed drop
Pick the longest dry spell you would accept, usually 1.5 to 3 times the average wait without protection. With a 2 percent chance the average is 50, so a cap of 60 to 150 is a good range.
does bad luck protection change the real drop rate
Yes. With the starting values a plain 2 percent chance takes 50 tries on average, and with protection it takes about 31. Set the base chance with that in mind, or the prize becomes too common.
what do i tell my ai to add bad luck protection
Paste this: Count misses in a row for the rare prize. The chance is 2 percent for the first 40 misses, then rises 2 points per miss, and the 60th try always hits. Any hit sets the count to zero, and the count is saved with the game.
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