FA-86131 / Game economy crafting balance / Open access
Magic find loot roll: Selection walks unboosted weights · case 01
Magic find changes the total but not which item is chosen.
ROOT CAUSE
The cumulative walk uses the original weights while the target uses boosted weights.
VERIFIED REPAIR
Restore `acc += w` at the cumulative weight source step.
Unsuccessful approach: Boosting every original weight during the walk also boosts commons.
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 += w0
if target < acc:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('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'),
('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('partial repair boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('partial repair boundary #2', [[['i0', 'common', 1]], 0, -50], 'i0'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
('control #2',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4')],
[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('fault site cumulative weight source #2',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('partial repair boundary #1', [[['i0', 'common', 1]], 0, -50], 'i0'),
('partial repair boundary #2', [[['i0', 'common', 0], ['i1', 'common', 5]], 9999, -50], 'i1'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1',
[[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100],
'i1'),
('fault site cumulative weight source #2',
[[['i0', 'legendary', 2], ['i1', 'legendary', 50], ['i2', 'rare', 10]], 5000, 100],
'i1'),
('partial repair boundary #1',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative weight source #1',
[[['i0', 'common', 2], ['i1', 'common', 50], ['i2', 'rare', 41], ['i3', 'rare', 50], ['i4', 'common', 2]],
9999,
100],
'i4'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1',
[[['i0', 'legendary', 10],
['i1', 'rare', 50],
['i2', 'legendary', 0],
['i3', 'common', 2],
['i4', 'common', 55]],
0,
-50],
'i0'),
('control #2', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1')],
[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('fault site cumulative weight source #2',
[[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
'i2'),
('partial repair boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative weight source #1',
[[['i0', 'legendary', 50], ['i1', 'legendary', 83], ['i2', 'common', 78], ['i3', 'common', 95]],
5000,
-50],
'i2'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
('fault site cumulative weight source #2', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
('partial repair boundary #1', [[['i0', 'common', 50], ['i1', 'common', 50]], 2592, -50], 'i0'),
('partial repair boundary #2',
[[['i0', 'legendary', 2], ['i1', 'legendary', 2], ['i2', 'common', 10]], 8581, -50],
'i2'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'common', 50]], 1, 100], 'i0'),
('control #2',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3')]]
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 |
|---|---|---|---|
| legendary boosted #1 | None | crown | Failed |
| curse lowers rare #1 | gem | rock | Failed |
| fault site cumulative weight source #1 | None | i1 | Failed |
| partial repair boundary #1 | i0 | i0 | Passed |
| partial repair boundary #2 | i0 | i0 | Passed |
| zero weight entry skipped #1 | c | c | Passed |
| control #1 | i0 | i0 | Passed |
| control #2 | i4 | i4 | Passed |
SHA-256 / 6cb4588bf82722d6cfdf744abc0ce12303676aa175a5c8a4999be75fce0e075f
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 += w0 * (100 + magic_find) // 100
if target < acc:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('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'),
('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('partial repair boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('partial repair boundary #2', [[['i0', 'common', 1]], 0, -50], 'i0'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
('control #2',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4')],
[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('fault site cumulative weight source #2',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('partial repair boundary #1', [[['i0', 'common', 1]], 0, -50], 'i0'),
('partial repair boundary #2', [[['i0', 'common', 0], ['i1', 'common', 5]], 9999, -50], 'i1'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1',
[[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100],
'i1'),
('fault site cumulative weight source #2',
[[['i0', 'legendary', 2], ['i1', 'legendary', 50], ['i2', 'rare', 10]], 5000, 100],
'i1'),
('partial repair boundary #1',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative weight source #1',
[[['i0', 'common', 2], ['i1', 'common', 50], ['i2', 'rare', 41], ['i3', 'rare', 50], ['i4', 'common', 2]],
9999,
100],
'i4'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1',
[[['i0', 'legendary', 10],
['i1', 'rare', 50],
['i2', 'legendary', 0],
['i3', 'common', 2],
['i4', 'common', 55]],
0,
-50],
'i0'),
('control #2', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1')],
[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('fault site cumulative weight source #2',
[[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
'i2'),
('partial repair boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative weight source #1',
[[['i0', 'legendary', 50], ['i1', 'legendary', 83], ['i2', 'common', 78], ['i3', 'common', 95]],
5000,
-50],
'i2'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
('fault site cumulative weight source #2', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
('partial repair boundary #1', [[['i0', 'common', 50], ['i1', 'common', 50]], 2592, -50], 'i0'),
('partial repair boundary #2',
[[['i0', 'legendary', 2], ['i1', 'legendary', 2], ['i2', 'common', 10]], 8581, -50],
'i2'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'common', 50]], 1, 100], 'i0'),
('control #2',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3')]]
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 |
|---|---|---|---|
| legendary boosted #1 | sword | crown | Failed |
| curse lowers rare #1 | rock | rock | Passed |
| fault site cumulative weight source #1 | i1 | i1 | Passed |
| partial repair boundary #1 | i1 | i0 | Failed |
| partial repair boundary #2 | None | i0 | Failed |
| zero weight entry skipped #1 | c | c | Passed |
| control #1 | i0 | i0 | Passed |
| control #2 | i4 | i4 | Passed |
SHA-256 / fe8ab0ea81c6b2b02b32eddf74406479d95776942cbcdd8edace2d5d5caf831f
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 = [[('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'),
('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('partial repair boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('partial repair boundary #2', [[['i0', 'common', 1]], 0, -50], 'i0'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
('control #2',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4')],
[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('fault site cumulative weight source #2',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('partial repair boundary #1', [[['i0', 'common', 1]], 0, -50], 'i0'),
('partial repair boundary #2', [[['i0', 'common', 0], ['i1', 'common', 5]], 9999, -50], 'i1'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1',
[[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100],
'i1'),
('fault site cumulative weight source #2',
[[['i0', 'legendary', 2], ['i1', 'legendary', 50], ['i2', 'rare', 10]], 5000, 100],
'i1'),
('partial repair boundary #1',
[[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
'i3'),
('regression cumulative weight source #1',
[[['i0', 'common', 2], ['i1', 'common', 50], ['i2', 'rare', 41], ['i3', 'rare', 50], ['i4', 'common', 2]],
9999,
100],
'i4'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1',
[[['i0', 'legendary', 10],
['i1', 'rare', 50],
['i2', 'legendary', 0],
['i3', 'common', 2],
['i4', 'common', 55]],
0,
-50],
'i0'),
('control #2', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1')],
[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('fault site cumulative weight source #2',
[[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
'i2'),
('partial repair boundary #1',
[[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
'i1'),
('regression cumulative weight source #1',
[[['i0', 'legendary', 50], ['i1', 'legendary', 83], ['i2', 'common', 78], ['i3', 'common', 95]],
5000,
-50],
'i2'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('fault site cumulative weight source #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
('fault site cumulative weight source #2', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
('partial repair boundary #1', [[['i0', 'common', 50], ['i1', 'common', 50]], 2592, -50], 'i0'),
('partial repair boundary #2',
[[['i0', 'legendary', 2], ['i1', 'legendary', 2], ['i2', 'common', 10]], 8581, -50],
'i2'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('control #1', [[['i0', 'common', 50]], 1, 100], 'i0'),
('control #2',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3')]]
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 |
|---|---|---|---|
| legendary boosted #1 | crown | crown | Passed |
| curse lowers rare #1 | rock | rock | Passed |
| fault site cumulative weight source #1 | i1 | i1 | Passed |
| partial repair boundary #1 | i0 | i0 | Passed |
| partial repair boundary #2 | i0 | i0 | Passed |
| zero weight entry skipped #1 | c | c | Passed |
| control #1 | i0 | i0 | Passed |
| control #2 | i4 | i4 | Passed |
SHA-256 / 222570aa00c0d9f8020883f3cc92882f5dd6b05546586c4c40038558b9a9ffda
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.764556+00:00.
Case digest / d89929f2ad234663e5a4a062ee8328ccd03e91862980e82e962d37d480de0a26