FAILURE MAP
← Case archive

FA-86321 / Game economy crafting balance / Open access

Crafting XP with rested pool: Only one level per gain · case 01

A huge gain leaves an overfull xp bar.

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

ROOT CAUSE

Level-up is checked once per gain instead of looping.

VERIFIED REPAIR

Restore `while level < 50 and xp >= 80 + 20 * level:` at the multi-level carry step.

Unsuccessful approach: Stopping the loop at level 49 makes the level cap unreachable.

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
        if 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]),
  ('fault site multi-level carry #1', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('fault site multi-level carry #2', [29, 125, [2000], 0], [32, 85, 0]),
  ('partial repair boundary #1', [49, 56, [516, 2000], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 57, [300, 2000, 274], 0], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [29, 125, [2000], 0], [32, 85, 0]),
  ('fault site multi-level carry #2', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('partial repair boundary #1', [49, 101, [300, 300, 100, 99, 100], 1000], [50, 0, 400]),
  ('partial repair boundary #2', [49, 62, [99, 10, 2000, 99], 0], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [1, 19, [50, 2000, 50], 1000], [14, 259, 0]),
  ('fault site multi-level carry #2', [5, 125, [82, 2000, 10, 10, 2000], 0], [18, 327, 0]),
  ('partial repair boundary #1', [49, 90, [2000, 89], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 126, [2000, 99], 345], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [30, 136, [2000, 100], 1000], [34, 396, 0]),
  ('fault site multi-level carry #2', [5, 48, [2000, 2000, 50, 100], 310], [19, 168, 0]),
  ('partial repair boundary #1', [49, 62, [300, 393, 300, 300], 0], [50, 0, 0]),
  ('partial repair boundary #2', [49, 50, [2000, 50], 1000], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [1, 68, [2000], 30], [11, 198, 0]),
  ('fault site multi-level carry #2', [1, 130, [300, 99], 1000], [7, 28, 601]),
  ('partial repair boundary #1', [49, 47, [100, 10, 2000, 99], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 132, [300, 50, 99, 99], 1000], [50, 0, 452]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [5, 79, [300], 0], [6, 199, 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, 200, 0][3, 80, 0]Failed
fault site multi-level carry #1[7, 1809, 0][13, 189, 0]Failed
fault site multi-level carry #2[30, 1465, 0][32, 85, 0]Failed
partial repair boundary #1[50, 0, 0][50, 0, 0]Passed
partial repair boundary #2[50, 0, 0][50, 0, 0]Passed
exact threshold #1[11, 0, 0][11, 0, 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 / a325806808bc394cff9c49ff512a313c24ac1abdea099188f42d67d9526fa175

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 < 49 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]),
  ('fault site multi-level carry #1', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('fault site multi-level carry #2', [29, 125, [2000], 0], [32, 85, 0]),
  ('partial repair boundary #1', [49, 56, [516, 2000], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 57, [300, 2000, 274], 0], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [29, 125, [2000], 0], [32, 85, 0]),
  ('fault site multi-level carry #2', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('partial repair boundary #1', [49, 101, [300, 300, 100, 99, 100], 1000], [50, 0, 400]),
  ('partial repair boundary #2', [49, 62, [99, 10, 2000, 99], 0], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [1, 19, [50, 2000, 50], 1000], [14, 259, 0]),
  ('fault site multi-level carry #2', [5, 125, [82, 2000, 10, 10, 2000], 0], [18, 327, 0]),
  ('partial repair boundary #1', [49, 90, [2000, 89], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 126, [2000, 99], 345], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [30, 136, [2000, 100], 1000], [34, 396, 0]),
  ('fault site multi-level carry #2', [5, 48, [2000, 2000, 50, 100], 310], [19, 168, 0]),
  ('partial repair boundary #1', [49, 62, [300, 393, 300, 300], 0], [50, 0, 0]),
  ('partial repair boundary #2', [49, 50, [2000, 50], 1000], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [1, 68, [2000], 30], [11, 198, 0]),
  ('fault site multi-level carry #2', [1, 130, [300, 99], 1000], [7, 28, 601]),
  ('partial repair boundary #1', [49, 47, [100, 10, 2000, 99], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 132, [300, 50, 99, 99], 1000], [50, 0, 452]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [5, 79, [300], 0], [6, 199, 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
fault site multi-level carry #1[13, 189, 0][13, 189, 0]Passed
fault site multi-level carry #2[32, 85, 0][32, 85, 0]Passed
partial repair boundary #1[49, 2672, 0][50, 0, 0]Failed
partial repair boundary #2[49, 2631, 0][50, 0, 0]Failed
exact threshold #1[11, 0, 0][11, 0, 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 / 823177b2dbd3c14a3109bd84370d61f55cd458eb9a17698c45b123dcf0540672

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]),
  ('fault site multi-level carry #1', [5, 79, [100, 10, 2000], 0], [13, 189, 0]),
  ('fault site multi-level carry #2', [29, 125, [2000], 0], [32, 85, 0]),
  ('partial repair boundary #1', [49, 56, [516, 2000], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 57, [300, 2000, 274], 0], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [29, 125, [2000], 0], [32, 85, 0]),
  ('fault site multi-level carry #2', [1, 37, [100, 100, 2000], 1000], [15, 17, 0]),
  ('partial repair boundary #1', [49, 101, [300, 300, 100, 99, 100], 1000], [50, 0, 400]),
  ('partial repair boundary #2', [49, 62, [99, 10, 2000, 99], 0], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [1, 19, [50, 2000, 50], 1000], [14, 259, 0]),
  ('fault site multi-level carry #2', [5, 125, [82, 2000, 10, 10, 2000], 0], [18, 327, 0]),
  ('partial repair boundary #1', [49, 90, [2000, 89], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 126, [2000, 99], 345], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [30, 136, [2000, 100], 1000], [34, 396, 0]),
  ('fault site multi-level carry #2', [5, 48, [2000, 2000, 50, 100], 310], [19, 168, 0]),
  ('partial repair boundary #1', [49, 62, [300, 393, 300, 300], 0], [50, 0, 0]),
  ('partial repair boundary #2', [49, 50, [2000, 50], 1000], [50, 0, 0]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 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]),
  ('fault site multi-level carry #1', [1, 68, [2000], 30], [11, 198, 0]),
  ('fault site multi-level carry #2', [1, 130, [300, 99], 1000], [7, 28, 601]),
  ('partial repair boundary #1', [49, 47, [100, 10, 2000, 99], 100], [50, 0, 0]),
  ('partial repair boundary #2', [49, 132, [300, 50, 99, 99], 1000], [50, 0, 452]),
  ('exact threshold #1', [10, 0, [280], 0], [11, 0, 0]),
  ('gain at cap keeps rested #1', [50, 0, [100], 40], [50, 0, 40]),
  ('control #1', [5, 79, [300], 0], [6, 199, 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
fault site multi-level carry #1[13, 189, 0][13, 189, 0]Passed
fault site multi-level carry #2[32, 85, 0][32, 85, 0]Passed
partial repair boundary #1[50, 0, 0][50, 0, 0]Passed
partial repair boundary #2[50, 0, 0][50, 0, 0]Passed
exact threshold #1[11, 0, 0][11, 0, 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 / d2f9c7946b5dc69e5c1eba615879b2020edea7509e395f8c18a0bbfa9a0088cf

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

Case digest / 94b761be50b55ea5d917a7456c1971591edea554db5a14ddc9e2a855ccfe27d7