fix(npc): a move applies at most once per reply
The tag extractor returns every occurrence of a move tag and the validator is
a pure membership test, so MoveApplier applied duplicates. A model repeating a
tag N times therefore picked an amount in unary — the AI choosing a number,
which is the §2 breach the bounded vocabulary exists to prevent.
The currency fix (8e1238c) closed this for denominations only. Generalizing it
to every move that names a thing covers real items too — three give_item(amulet)
tags are one amulet, not three — and lets the currency special case be deleted
rather than kept alongside a second mechanism. ID_MOVES is reused from
MoveValidator instead of restated.
Also caps adjust_disposition on the reply's NET swing. MAX_DELTA was clamped
per tag, so three +15s moved standing by 45 — precisely the wholesale swing its
own comment says it forbids. Applied in emission order, so a later
become_hostile still floors what came before it.
offer_quest and reveal needed no change: add_quest self-guards on has_quest and
mark_revealed is idempotent.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYa9u7Kdxv5gX4AnwWexy8
This commit is contained in:
@@ -144,18 +144,67 @@ func test_dedup_key_is_move_name_not_just_denomination():
|
||||
assert_eq(gs.purse_copper, 0)
|
||||
|
||||
|
||||
func test_repeated_non_currency_give_item_still_applies_each_time():
|
||||
# Pins the scope line: real-item duplicate handling is UNCHANGED by this fix
|
||||
# (it stays bounded only by the cross-reply gifts_given gate, reported separately).
|
||||
func test_repeated_give_item_applies_once_for_real_items_too():
|
||||
var gs = GameState.new()
|
||||
MoveApplier.apply([_m("give_item", ["amulet"]), _m("give_item", ["amulet"]), _m("give_item", ["amulet"])],
|
||||
gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.inventory.get("amulet", 0), 3, "non-currency give_item is out of scope for this fix")
|
||||
assert_eq(gs.inventory.get("amulet", 0), 1, "three tags, one amulet")
|
||||
|
||||
|
||||
func test_repeated_non_currency_accept_item_still_applies_each_time():
|
||||
func test_repeated_accept_item_applies_once_for_real_items_too():
|
||||
var gs = GameState.new()
|
||||
gs.add_item("worn_shortsword", 5)
|
||||
MoveApplier.apply([_m("accept_item", ["worn_shortsword"]), _m("accept_item", ["worn_shortsword"])],
|
||||
gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.inventory.get("worn_shortsword", 0), 3, "non-currency accept_item is out of scope for this fix")
|
||||
assert_eq(gs.inventory.get("worn_shortsword", 0), 4, "two tags, one sword taken")
|
||||
|
||||
|
||||
func test_different_real_items_in_one_reply_both_apply():
|
||||
var gs = GameState.new()
|
||||
MoveApplier.apply([_m("give_item", ["amulet"]), _m("give_item", ["ring"])],
|
||||
gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.inventory.get("amulet", 0), 1)
|
||||
assert_eq(gs.inventory.get("ring", 0), 1)
|
||||
|
||||
|
||||
func test_repeated_disposition_tags_cannot_exceed_the_per_reply_cap():
|
||||
# MAX_DELTA means "one line cannot swing standing wholesale" (§7 spirit). It was
|
||||
# clamped PER TAG, so three +15 tags moved standing by 45. The cap is per REPLY.
|
||||
var gs = GameState.new()
|
||||
MoveApplier.apply([_m("adjust_disposition", ["+15"]), _m("adjust_disposition", ["+15"]),
|
||||
_m("adjust_disposition", ["+15"])], gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.npc_dispositions.get("fenn", 0), MoveApplier.MAX_DELTA, "+45 is capped to +15")
|
||||
|
||||
|
||||
func test_disposition_cap_applies_to_the_net_swing():
|
||||
var gs = GameState.new()
|
||||
MoveApplier.apply([_m("adjust_disposition", ["+10"]), _m("adjust_disposition", ["+10"])],
|
||||
gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.npc_dispositions.get("fenn", 0), 15, "+20 is capped to +15")
|
||||
|
||||
|
||||
func test_disposition_tags_of_opposite_sign_net_out():
|
||||
# The cap is on the reply's NET swing, not on the tag count — so a walk-back
|
||||
# inside one reply still lands where the arithmetic says.
|
||||
var gs = GameState.new()
|
||||
MoveApplier.apply([_m("adjust_disposition", ["+10"]), _m("adjust_disposition", ["-4"])],
|
||||
gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.npc_dispositions.get("fenn", 0), 6)
|
||||
|
||||
|
||||
func test_become_hostile_still_wins_after_a_disposition_tag():
|
||||
# Moves apply in emission order — the hostile floor must not be undone by
|
||||
# batching the disposition arithmetic.
|
||||
var gs = GameState.new()
|
||||
MoveApplier.apply([_m("adjust_disposition", ["+15"]), _m("become_hostile")],
|
||||
gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.npc_dispositions.get("fenn", 0), MoveApplier.HOSTILE_FLOOR)
|
||||
|
||||
|
||||
func test_disposition_cap_is_per_reply_not_per_conversation():
|
||||
# Two separate replies each get a fresh MAX_DELTA budget — standing still moves
|
||||
# over a conversation, it just cannot lurch in a single line.
|
||||
var gs = GameState.new()
|
||||
MoveApplier.apply([_m("adjust_disposition", ["+15"])], gs, CanonLog.new(), _content(), "fenn")
|
||||
MoveApplier.apply([_m("adjust_disposition", ["+15"])], gs, CanonLog.new(), _content(), "fenn")
|
||||
assert_eq(gs.npc_dispositions.get("fenn", 0), 30)
|
||||
|
||||
Reference in New Issue
Block a user