FAILURE MAP
← Case archive

FA-86076 / Game economy crafting balance / Open access

Stamina regeneration: Partial regen progress is discarded · case 01

Stamina regenerates slower whenever an event lands between ticks.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The anchor jumps to the event time instead of advancing by whole periods.

VERIFIED REPAIR

Restore `t += gained * 300` at the anchor advance step.

Unsuccessful approach: Aligning to the original last_tick ignores anchor moves caused by capping or spending.

Case contract

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

Why this case matters

Game economies leak or destroy currency when one crafting or pricing rule is off by one boundary, rounding stage or state update; the defect is observable in exact integer outcomes.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stamina, cap, last_tick, now, refills):
    events = sorted(refills) + [[now, 0]]
    t = last_tick
    s = stamina
    for at, amount in events:
        if s < cap:
            gained = (at - t) // 300
            if s + gained >= cap:
                s = cap
                t = at
            else:
                s += gained
                t = at
        else:
            t = at
        if s + amount >= 0:
            s = min(999, s + amount)
    return [s, t]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression anchor advance #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
  ('fault site anchor advance #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
  ('regression anchor advance #2', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('regression anchor advance #3', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
  ('regression anchor advance #1', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('regression anchor advance #2', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('regression anchor advance #3', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
  ('fault site anchor advance #2', [0, 10, 347, 646, [[390, -10], [479, -9]]], [0, 347]),
  ('regression anchor advance #1', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('regression anchor advance #2', [18, 15, 804, 1404, [[1122, -11], [838, -10], [1325, -15]]], [9, 1138]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
  ('regression anchor advance #1', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('regression anchor advance #2', [18, 15, 245, 845, [[385, -15]]], [4, 685]),
  ('regression anchor advance #3', [21, 18, 351, 650, [[484, -18]]], [3, 484]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [2, 19, 442, 741, [[703, -19]]], [2, 442]),
  ('regression anchor advance #1', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('regression anchor advance #2', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
  ('regression anchor advance #3', [12, 13, 487, 4020, [[1176, -13], [3667, -7]]], [2, 3876]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
spend from full restarts timer #1[8, 1000][8, 1000]Passed
regression anchor advance #1[3, 1572][3, 1315]Failed
fault site anchor advance #1[15, 1773][15, 1583]Failed
regression anchor advance #2[3, 1520][4, 1313]Failed
regression anchor advance #3[9, 2485][9, 2240]Failed
exact refill to cap #1[5, 600][5, 600]Passed
overflow potion persists #1[15, 1200][15, 1200]Passed
control #1[0, 266][0, 266]Passed

SHA-256 / 98043a8484b7ada76f5b97b2afc479da758d1f5eca36ac41ee3d104c650d31dd

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stamina, cap, last_tick, now, refills):
    events = sorted(refills) + [[now, 0]]
    t = last_tick
    s = stamina
    for at, amount in events:
        if s < cap:
            gained = (at - t) // 300
            if s + gained >= cap:
                s = cap
                t = at
            else:
                s += gained
                t = at - (at - last_tick) % 300
        else:
            t = at
        if s + amount >= 0:
            s = min(999, s + amount)
    return [s, t]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression anchor advance #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
  ('fault site anchor advance #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
  ('regression anchor advance #2', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('regression anchor advance #3', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
  ('regression anchor advance #1', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('regression anchor advance #2', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('regression anchor advance #3', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
  ('fault site anchor advance #2', [0, 10, 347, 646, [[390, -10], [479, -9]]], [0, 347]),
  ('regression anchor advance #1', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('regression anchor advance #2', [18, 15, 804, 1404, [[1122, -11], [838, -10], [1325, -15]]], [9, 1138]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
  ('regression anchor advance #1', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('regression anchor advance #2', [18, 15, 245, 845, [[385, -15]]], [4, 685]),
  ('regression anchor advance #3', [21, 18, 351, 650, [[484, -18]]], [3, 484]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [2, 19, 442, 741, [[703, -19]]], [2, 442]),
  ('regression anchor advance #1', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('regression anchor advance #2', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
  ('regression anchor advance #3', [12, 13, 487, 4020, [[1176, -13], [3667, -7]]], [2, 3876]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
spend from full restarts timer #1[8, 900][8, 1000]Failed
regression anchor advance #1[3, 1572][3, 1315]Failed
fault site anchor advance #1[15, 1583][15, 1583]Passed
regression anchor advance #2[5, 1520][4, 1313]Failed
regression anchor advance #3[9, 2250][9, 2240]Failed
exact refill to cap #1[5, 600][5, 600]Passed
overflow potion persists #1[15, 1200][15, 1200]Passed
control #1[0, 266][0, 266]Passed

SHA-256 / b14e34270ad9ef9ef1ab1e91873483a9f2f0fdfe76897845fbadbc7242004fda

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stamina, cap, last_tick, now, refills):
    events = sorted(refills) + [[now, 0]]
    t = last_tick
    s = stamina
    for at, amount in events:
        if s < cap:
            gained = (at - t) // 300
            if s + gained >= cap:
                s = cap
                t = at
            else:
                s += gained
                t += gained * 300
        else:
            t = at
        if s + amount >= 0:
            s = min(999, s + amount)
    return [s, t]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression anchor advance #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
  ('fault site anchor advance #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
  ('regression anchor advance #2', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('regression anchor advance #3', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
  ('regression anchor advance #1', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('regression anchor advance #2', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('regression anchor advance #3', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
  ('fault site anchor advance #2', [0, 10, 347, 646, [[390, -10], [479, -9]]], [0, 347]),
  ('regression anchor advance #1', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('regression anchor advance #2', [18, 15, 804, 1404, [[1122, -11], [838, -10], [1325, -15]]], [9, 1138]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
  ('regression anchor advance #1', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('regression anchor advance #2', [18, 15, 245, 845, [[385, -15]]], [4, 685]),
  ('regression anchor advance #3', [21, 18, 351, 650, [[484, -18]]], [3, 484]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('fault site anchor advance #1', [2, 19, 442, 741, [[703, -19]]], [2, 442]),
  ('regression anchor advance #1', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
  ('regression anchor advance #2', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
  ('regression anchor advance #3', [12, 13, 487, 4020, [[1176, -13], [3667, -7]]], [2, 3876]),
  ('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
  ('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
  ('control #1', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
spend from full restarts timer #1[8, 1000][8, 1000]Passed
regression anchor advance #1[3, 1315][3, 1315]Passed
fault site anchor advance #1[15, 1583][15, 1583]Passed
regression anchor advance #2[4, 1313][4, 1313]Passed
regression anchor advance #3[9, 2240][9, 2240]Passed
exact refill to cap #1[5, 600][5, 600]Passed
overflow potion persists #1[15, 1200][15, 1200]Passed
control #1[0, 266][0, 266]Passed

SHA-256 / 522ff41b0a9aa8687d89380903362cdb516b678f688392ab446d3332a744a4e9

Verification & scope

Deterministic toy contract stipulated for this model; integer or exact arithmetic only, not a reproduction of any specific game engine. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:50:46.300778+00:00.

Case digest / 16a70af00e8639c6ae5da1bdab71950d6a2139bc8f55cf9eef1e14be0088bdf8