FA-86126 / Game economy crafting balance / Open access
Magic find loot roll: Boundary roll selects the previous item · case 01
A roll exactly at an item boundary drops the earlier item.
ROOT CAUSE
The cumulative comparison is inclusive.
VERIFIED REPAIR
Restore `target < acc` at the cumulative boundary step.
Unsuccessful approach: Skipping zero weights still resolves exact boundaries to the earlier item.
Case contract
table = [[item, rarity, weight], ...]. Non-common weights become floor(w*(100+mf)/100) (mf may be negative). With total boosted weight T (None if 0), target = floor(roll*T/10000) for roll 0..9999; return the first item whose cumulative boosted weight exceeds target.
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(table, roll, magic_find):
weights = []
for item, rarity, w in table:
if rarity != 'common':
w = w * (100 + magic_find) // 100
weights.append(w)
total = sum(weights)
if total == 0:
return None
target = roll * total // 10000
acc = 0
for (item, rarity, w0), w in zip(table, weights):
acc += w
if target <= acc:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative boundary #3', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 1], ['i1', 'legendary', 5], ['i2', 'common', 50], ['i3', 'common', 1]], 9999, 50],
'i3'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'common', 50], ['i2', 'rare', 5], ['i3', 'common', 0], ['i4', 'legendary', 1]],
1,
250],
'i1'),
('regression cumulative boundary #1',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
9999,
-50],
'i2'),
('regression cumulative boundary #3',
[[['i0', 'legendary', 10], ['i1', 'legendary', 0], ['i2', 'rare', 5]], 6788, 100],
'i2'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('regression cumulative boundary #1', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
('regression cumulative boundary #2',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative boundary #3',
[[['i0', 'rare', 26], ['i1', 'rare', 37], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #4',
[[['i0', 'rare', 1], ['i1', 'rare', 2], ['i2', 'common', 1], ['i3', 'common', 5], ['i4', 'common', 1]],
9999,
50],
'i4'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| zero weight entry skipped #1 | a | c | Failed |
| fault site cumulative boundary #1 | i0 | i1 | Failed |
| fault site cumulative boundary #2 | i0 | i1 | Failed |
| regression cumulative boundary #1 | i2 | i3 | Failed |
| regression cumulative boundary #2 | i2 | i3 | Failed |
| legendary boosted #1 | crown | crown | Passed |
| curse lowers rare #1 | rock | rock | Passed |
| control #1 | i1 | i1 | Passed |
SHA-256 / 7465572b1d24a28cca9123e556b60a195e0d92da985c4c645c0818eb98402573
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(table, roll, magic_find):
weights = []
for item, rarity, w in table:
if rarity != 'common':
w = w * (100 + magic_find) // 100
weights.append(w)
total = sum(weights)
if total == 0:
return None
target = roll * total // 10000
acc = 0
for (item, rarity, w0), w in zip(table, weights):
acc += w
if target <= acc and w > 0:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative boundary #3', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 1], ['i1', 'legendary', 5], ['i2', 'common', 50], ['i3', 'common', 1]], 9999, 50],
'i3'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'common', 50], ['i2', 'rare', 5], ['i3', 'common', 0], ['i4', 'legendary', 1]],
1,
250],
'i1'),
('regression cumulative boundary #1',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
9999,
-50],
'i2'),
('regression cumulative boundary #3',
[[['i0', 'legendary', 10], ['i1', 'legendary', 0], ['i2', 'rare', 5]], 6788, 100],
'i2'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('regression cumulative boundary #1', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
('regression cumulative boundary #2',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative boundary #3',
[[['i0', 'rare', 26], ['i1', 'rare', 37], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #4',
[[['i0', 'rare', 1], ['i1', 'rare', 2], ['i2', 'common', 1], ['i3', 'common', 5], ['i4', 'common', 1]],
9999,
50],
'i4'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| zero weight entry skipped #1 | a | c | Failed |
| fault site cumulative boundary #1 | i1 | i1 | Passed |
| fault site cumulative boundary #2 | i1 | i1 | Passed |
| regression cumulative boundary #1 | i2 | i3 | Failed |
| regression cumulative boundary #2 | i2 | i3 | Failed |
| legendary boosted #1 | crown | crown | Passed |
| curse lowers rare #1 | rock | rock | Passed |
| control #1 | i1 | i1 | Passed |
SHA-256 / b609e20911f7605e5c7a1b8061cb2f20556befbacede6969b828f9d8dd6ac6f1
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(table, roll, magic_find):
weights = []
for item, rarity, w in table:
if rarity != 'common':
w = w * (100 + magic_find) // 100
weights.append(w)
total = sum(weights)
if total == 0:
return None
target = roll * total // 10000
acc = 0
for (item, rarity, w0), w in zip(table, weights):
acc += w
if target < acc:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative boundary #3', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
('regression cumulative boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative boundary #2',
[[['i0', 'legendary', 1], ['i1', 'legendary', 5], ['i2', 'common', 50], ['i3', 'common', 1]], 9999, 50],
'i3'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site cumulative boundary #1',
[[['i0', 'rare', 0], ['i1', 'common', 50], ['i2', 'rare', 5], ['i3', 'common', 0], ['i4', 'legendary', 1]],
1,
250],
'i1'),
('regression cumulative boundary #1',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative boundary #2',
[[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
9999,
-50],
'i2'),
('regression cumulative boundary #3',
[[['i0', 'legendary', 10], ['i1', 'legendary', 0], ['i2', 'rare', 5]], 6788, 100],
'i2'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('regression cumulative boundary #1', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
('regression cumulative boundary #2',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative boundary #3',
[[['i0', 'rare', 26], ['i1', 'rare', 37], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, 0],
'i3'),
('regression cumulative boundary #4',
[[['i0', 'rare', 1], ['i1', 'rare', 2], ['i2', 'common', 1], ['i3', 'common', 5], ['i4', 'common', 1]],
9999,
50],
'i4'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| zero weight entry skipped #1 | c | c | Passed |
| fault site cumulative boundary #1 | i1 | i1 | Passed |
| fault site cumulative boundary #2 | i1 | i1 | Passed |
| regression cumulative boundary #1 | i3 | i3 | Passed |
| regression cumulative boundary #2 | i3 | i3 | Passed |
| legendary boosted #1 | crown | crown | Passed |
| curse lowers rare #1 | rock | rock | Passed |
| control #1 | i1 | i1 | Passed |
SHA-256 / e3ab1eb789cff22db35dcff566a5140b0e565ebe3481daf51d65d14629fa29e5
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.721411+00:00.
Case digest / a43107b6189846c654b22ad15234f86dafe2acbe502438b1f95fdaf8ad01deb2