T08 iter 2: Reveal, Resolve, End; relations and the DARVO trigger
Round machinery, system-driven (GR-R04/R06/R08): - GR-R06 fixed step order with GR-R07 Lead-first ordering inside a step. Steps 1 (GROUND), 3 (DARVO stages), 4 (INVESTIGATE) and 6 (SOLVE) are not implemented yet; their Actions resolve as no-ops and no scenario claims coverage of them. - SUPPORT GR-A03/A04/A05 and ATTACK GR-A06..A09, with relation formation, flip and break per GR-L01/L03/L04 and Protection cancellation. - GR-R08 End: DARVO trigger at Stress 5 in Lead order, Lead rotation, Round advance, per-round flags cleared. - Stress clamps 0-5 on every application, the U2 default, so a mid-round spike that is reduced before End does not trigger DARVO. Two consent-dependent rules are deliberately left out because they need a decision command rather than a default: Bond formation (GR-L02) and the target's flip-or-break choice on Support-through-Rivalry (GR-A05). Both are noted in code and covered by a provisional scenario. Fixes a defect in the T07 scaffold: relations were keyed by a tuple, which JSON cannot use as an object key, so state_hash would have panicked on any state holding a relation. Relation keys are now a Pair newtype serialized as "a-b", with a regression test. setup.patch may now create a final key so scenarios can seed open-ended maps; a typo anywhere earlier in the path is still an error. 8 scenarios pass, 28 rules covered; 17 tests, fmt/clippy green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
a09d76f370
commit
b58a9139aa
7 changed files with 647 additions and 4 deletions
|
|
@ -253,9 +253,32 @@ fn apply_patch<G: ScenarioGame>(
|
|||
let mut json = serde_json::to_value(state).map_err(|e| format!("state encode: {e}"))?;
|
||||
for (path, value) in patch {
|
||||
let value = to_json(value)?;
|
||||
let slot = lookup_mut(&mut json, path)
|
||||
.ok_or_else(|| format!("patch path {path:?} does not exist in the initial state"))?;
|
||||
*slot = value;
|
||||
let (parent_path, key) = path.rsplit_once('.').unwrap_or(("", path.as_str()));
|
||||
// The parent must exist — a typo mid-path is an error, never a
|
||||
// silent no-op. The final key may be new, so scenarios can seed
|
||||
// open-ended maps (relations, focus) that start empty.
|
||||
let parent = if parent_path.is_empty() {
|
||||
&mut json
|
||||
} else {
|
||||
lookup_mut(&mut json, parent_path).ok_or_else(|| {
|
||||
format!("patch path {path:?}: {parent_path:?} does not exist in the initial state")
|
||||
})?
|
||||
};
|
||||
match parent {
|
||||
serde_json::Value::Object(map) => {
|
||||
map.insert(key.to_string(), value);
|
||||
}
|
||||
serde_json::Value::Array(items) => {
|
||||
let index = key
|
||||
.parse::<usize>()
|
||||
.map_err(|_| format!("patch path {path:?}: {key:?} is not an array index"))?;
|
||||
let slot = items
|
||||
.get_mut(index)
|
||||
.ok_or_else(|| format!("patch path {path:?}: index {index} out of range"))?;
|
||||
*slot = value;
|
||||
}
|
||||
_ => return Err(format!("patch path {path:?}: parent is not a container")),
|
||||
}
|
||||
}
|
||||
serde_json::from_value(json).map_err(|e| format!("patch produced invalid state: {e}"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue