FAILURE MAP
← Case archive

FA-86326 / Game economy crafting balance / Open access

Crafting XP with rested pool: Level-up discards overflow xp · case 01

Excess xp beyond the requirement is lost on each level.

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

ROOT CAUSE

The xp bar is reset instead of subtracting the requirement.

VERIFIED REPAIR

Restore `xp -= 80 + 20 * level` at the overflow carry step.

Unsuccessful approach: Subtracting the next level requirement overcharges each level-up.

Case contract

Level L needs 80 + 20*L xp to reach L+1; max level 50. Gains are ignored once level 50 is reached (rested untouched). For each gain g: bonus = min(g, rested) is added on top of g and removed from the rested pool; then as many levels as possible are taken, carrying remaining xp; on reaching level 50 the xp bar is set to 0. Returns [level, xp, rested].

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(level, xp, gains, rested):
    for g in gains:
        if level >= 50:
            break
        bonus = min(g, rested)
        rested -= bonus
        xp += g + bonus
        while level < 50 and xp >= 80 + 20 * level:
            xp = 0
            level += 1
        if level >= 50:
            xp = 0
    return [level, xp, rested]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 79, [300], 0], [6, 199, 0]),
  ('regression overflow carry #2', [10, 7, [300, 50, 99, 100], 0], [11, 276, 0]),
  ('regression overflow carry #3', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #4', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [48, 123, [50, 10, 420], 100], [48, 703, 0])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [10, 7, [300, 50, 99, 100], 0], [11, 276, 0]),
  ('regression overflow carry #2', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #3', [5, 79, [300], 0], [6, 199, 0]),
  ('regression overflow carry #4', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [48, 123, [50, 10, 420], 100], [48, 703, 0])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('regression overflow carry #2', [29, 125, [2000], 0], [32, 85, 0]),
  ('regression overflow carry #3', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #4', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [50, 56, [99], 100], [50, 56, 100])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('regression overflow carry #2', [1, 15, [100], 100], [2, 115, 0]),
  ('regression overflow carry #3', [29, 125, [2000], 0], [32, 85, 0]),
  ('regression overflow carry #4', [5, 102, [50, 100], 30], [6, 102, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [30, 20, [50, 100, 10, 10], 1000], [30, 360, 830])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 102, [50, 100], 30], [6, 102, 0]),
  ('regression overflow carry #2', [5, 92, [179, 50, 437, 100], 155], [9, 173, 0]),
  ('regression overflow carry #3', [1, 15, [100], 100], [2, 115, 0]),
  ('regression overflow carry #4', [1, 19, [50, 2000, 50], 1000], [14, 259, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [30, 122, [50, 10, 300, 50, 100], 0], [30, 632, 0])]]
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
multi-level gain #1[2, 0, 0][3, 80, 0]Failed
exact threshold #1[11, 0, 0][11, 0, 0]Passed
regression overflow carry #1[6, 0, 0][6, 199, 0]Failed
regression overflow carry #2[11, 249, 0][11, 276, 0]Failed
regression overflow carry #3[49, 0, 0][49, 183, 0]Failed
regression overflow carry #4[7, 0, 0][13, 189, 0]Failed
gain at cap keeps rested #1[50, 0, 40][50, 0, 40]Passed
control #1[48, 703, 0][48, 703, 0]Passed

SHA-256 / c0c26791f85d583554f0fd99b2c6cdde71975dd1dc8e4de442dbe718173c6056

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(level, xp, gains, rested):
    for g in gains:
        if level >= 50:
            break
        bonus = min(g, rested)
        rested -= bonus
        xp += g + bonus
        while level < 50 and xp >= 80 + 20 * level:
            xp -= 80 + 20 * (level + 1)
            level += 1
        if level >= 50:
            xp = 0
    return [level, xp, rested]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 79, [300], 0], [6, 199, 0]),
  ('regression overflow carry #2', [10, 7, [300, 50, 99, 100], 0], [11, 276, 0]),
  ('regression overflow carry #3', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #4', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [48, 123, [50, 10, 420], 100], [48, 703, 0])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [10, 7, [300, 50, 99, 100], 0], [11, 276, 0]),
  ('regression overflow carry #2', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #3', [5, 79, [300], 0], [6, 199, 0]),
  ('regression overflow carry #4', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [48, 123, [50, 10, 420], 100], [48, 703, 0])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('regression overflow carry #2', [29, 125, [2000], 0], [32, 85, 0]),
  ('regression overflow carry #3', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #4', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [50, 56, [99], 100], [50, 56, 100])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('regression overflow carry #2', [1, 15, [100], 100], [2, 115, 0]),
  ('regression overflow carry #3', [29, 125, [2000], 0], [32, 85, 0]),
  ('regression overflow carry #4', [5, 102, [50, 100], 30], [6, 102, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [30, 20, [50, 100, 10, 10], 1000], [30, 360, 830])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 102, [50, 100], 30], [6, 102, 0]),
  ('regression overflow carry #2', [5, 92, [179, 50, 437, 100], 155], [9, 173, 0]),
  ('regression overflow carry #3', [1, 15, [100], 100], [2, 115, 0]),
  ('regression overflow carry #4', [1, 19, [50, 2000, 50], 1000], [14, 259, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [30, 122, [50, 10, 300, 50, 100], 0], [30, 632, 0])]]
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
multi-level gain #1[3, 40, 0][3, 80, 0]Failed
exact threshold #1[11, -20, 0][11, 0, 0]Failed
regression overflow carry #1[6, 179, 0][6, 199, 0]Failed
regression overflow carry #2[11, 256, 0][11, 276, 0]Failed
regression overflow carry #3[49, 163, 0][49, 183, 0]Failed
regression overflow carry #4[13, 29, 0][13, 189, 0]Failed
gain at cap keeps rested #1[50, 0, 40][50, 0, 40]Passed
control #1[48, 703, 0][48, 703, 0]Passed

SHA-256 / dcb1f18d1a38bcb46b0e849520f51fbcfae26e06df1e31a558d6b035254edebc

3 / The verified repair

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

N = 1
observations = []
def solve(level, xp, gains, rested):
    for g in gains:
        if level >= 50:
            break
        bonus = min(g, rested)
        rested -= bonus
        xp += g + bonus
        while level < 50 and xp >= 80 + 20 * level:
            xp -= 80 + 20 * level
            level += 1
        if level >= 50:
            xp = 0
    return [level, xp, rested]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 79, [300], 0], [6, 199, 0]),
  ('regression overflow carry #2', [10, 7, [300, 50, 99, 100], 0], [11, 276, 0]),
  ('regression overflow carry #3', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #4', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [48, 123, [50, 10, 420], 100], [48, 703, 0])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [10, 7, [300, 50, 99, 100], 0], [11, 276, 0]),
  ('regression overflow carry #2', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #3', [5, 79, [300], 0], [6, 199, 0]),
  ('regression overflow carry #4', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [48, 123, [50, 10, 420], 100], [48, 703, 0])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('regression overflow carry #2', [29, 125, [2000], 0], [32, 85, 0]),
  ('regression overflow carry #3', [48, 108, [300, 300, 99, 86, 300], 30], [49, 183, 0]),
  ('regression overflow carry #4', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [50, 56, [99], 100], [50, 56, 100])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('regression overflow carry #2', [1, 15, [100], 100], [2, 115, 0]),
  ('regression overflow carry #3', [29, 125, [2000], 0], [32, 85, 0]),
  ('regression overflow carry #4', [5, 102, [50, 100], 30], [6, 102, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [30, 20, [50, 100, 10, 10], 1000], [30, 360, 830])],
 [('multi-level gain #1', [1, 0, [300], 0], [3, 80, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('regression overflow carry #1', [5, 102, [50, 100], 30], [6, 102, 0]),
  ('regression overflow carry #2', [5, 92, [179, 50, 437, 100], 155], [9, 173, 0]),
  ('regression overflow carry #3', [1, 15, [100], 100], [2, 115, 0]),
  ('regression overflow carry #4', [1, 19, [50, 2000, 50], 1000], [14, 259, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [30, 122, [50, 10, 300, 50, 100], 0], [30, 632, 0])]]
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
multi-level gain #1[3, 80, 0][3, 80, 0]Passed
exact threshold #1[11, 0, 0][11, 0, 0]Passed
regression overflow carry #1[6, 199, 0][6, 199, 0]Passed
regression overflow carry #2[11, 276, 0][11, 276, 0]Passed
regression overflow carry #3[49, 183, 0][49, 183, 0]Passed
regression overflow carry #4[13, 189, 0][13, 189, 0]Passed
gain at cap keeps rested #1[50, 0, 40][50, 0, 40]Passed
control #1[48, 703, 0][48, 703, 0]Passed

SHA-256 / 01c7f0f0a0f442d1c2f30b0cbf22da9759619828fe5c7b2e2a3793b34e739869

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:48.612148+00:00.

Case digest / cdda53754d86760b3c30a937716eccea24f51fa60c6a5e932fec4be0a6e0ea6d