diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index d263ee5..02898a9 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -1594,41 +1594,28 @@ fn overruled(report: &mut Vec, draft: &Draft, clear_of: &[String], holds: } /// The lines and additions of an answer with no verdict on a hold that covers where they go (K60, map 16.33.5), a -/// contract fault found before anything is decided. Covering is code's: a hold listed in `packet.holds` or opened by this -/// answer from a listed line, covering anywhere or the room the draft goes into (the turn's room for a line, the target's -/// room for an addition). Each such hold is named in the line's `holds` or `clear_of`. A line whose number names no draft, -/// and a line on a turn with no room, go nowhere, and need no verdict. +/// contract fault found before anything is decided. Covering is code's: a hold listed in `packet.holds` that covers +/// anywhere or the turn's room, and a hold this answer opens from a listed line, here or anywhere. A line and an addition +/// both go into the turn's room, since the lines she may reply to and add to are that room's alone (`select`), so a hold +/// opened from one covers it either way. Each such hold is named in the line's `holds` or `clear_of`, once each. A line +/// whose number names no draft, and every line on a turn with no room, go nowhere, and need no verdict. fn verdict_faults(answer: &Answer, packet: &Packet, found: &Drafts) -> Vec { - let opening: Vec<(&str, Option<&str>)> = answer - .hold - .iter() - .filter_map(|raw| serde_json::from_value::(raw.clone()).ok()) - .filter_map(|hold| packet.quotable.iter().find(|line| line.id == hold.line.trim()).map(|line| (line.id.as_str(), (hold.place == Where::Here).then_some(line.room.as_str())))) - .collect(); - let covering = |into: &str| -> Vec { - let mut handles: Vec = packet.holds.iter().filter(|hold| hold.room.as_deref().is_none_or(|room| room == into)).map(|hold| hold.id.clone()).collect(); - for (line, covers) in &opening { - if covers.is_none_or(|room| room == into) && !handles.iter().any(|handle| handle.as_str() == *line) { - handles.push((*line).to_owned()); - } + let Some(room) = packet.room.as_deref() else { return Vec::new() }; + let mut covering: Vec<&str> = packet.holds.iter().filter(|hold| hold.room.as_deref().is_none_or(|covers| covers == room)).map(|hold| hold.id.as_str()).collect(); + for raw in &answer.hold { + let opens = serde_json::from_value::(raw.clone()).ok().and_then(|hold| packet.quotable.iter().find(|line| line.id == hold.line.trim())); + if let Some(line) = opens.filter(|line| !covering.contains(&line.id.as_str())) { + covering.push(&line.id); } - handles - }; - let mut faults = Vec::new(); - let mut check = |act: Act, at: usize, draft: Option, into: Option<&str>, holds: &[String], clear_of: &[String]| { - let (Some(draft), Some(into)) = (draft.and_then(|n| found.numbered(n)), into) else { return }; - for hold in covering(into) { - if !holds.iter().chain(clear_of).any(|named| named.trim() == hold) { - faults.push(Unverdicted { act, at, draft: draft.n, hold }); - } - } - }; - for (at, line) in answer.say.iter().enumerate() { - check(Act::Say, at, line.draft, packet.room.as_deref(), &line.holds, &line.clear_of); } - for (at, amend) in answer.amend.iter().enumerate() { - let into = amend.target.as_deref().and_then(|id| packet.amendable.iter().find(|line| line.id == id.trim())).map(|line| line.room.as_str()).or(packet.room.as_deref()); - check(Act::Amend, at, amend.draft, into, &amend.holds, &amend.clear_of); + let lines = answer.say.iter().enumerate().map(|(at, line)| (Act::Say, at, line.draft, &line.holds, &line.clear_of)); + let additions = answer.amend.iter().enumerate().map(|(at, amend)| (Act::Amend, at, amend.draft, &amend.holds, &amend.clear_of)); + let mut faults = Vec::new(); + for (act, at, draft, holds, clear_of) in lines.chain(additions) { + let Some(draft) = draft.and_then(|n| found.numbered(n)) else { continue }; + for hold in covering.iter().filter(|hold| !holds.iter().chain(clear_of).any(|named| named.trim() == **hold)) { + faults.push(Unverdicted { act, at, draft: draft.n, hold: (*hold).to_owned() }); + } } faults } diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 340586c..76ba9d8 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -3303,3 +3303,12 @@ fn k60_the_contract_requires_the_verdict() { assert!(prompt.contains("`clear_of` names each such hold covering where it goes whose held thing it does not carry. Under every hold that covers where a draft goes, the draft names it in one of the two; one left out fails the answer."), "{prompt}"); assert!(!prompt.contains("goes; else empty"), "{prompt}"); } + +/// A hold opened twice from one line asks one verdict, and a line with none is faulted once for it. +#[test] +fn k60_a_hold_opened_twice_asks_one_verdict() { + let mut answer = x3_r1_no_verdict(); + answer["hold"] = json!([{ "line": "q3", "words": "hold it, don't post it in here yet", "where": "here" }, { "line": "q3", "words": "don't post it in here yet", "where": "anywhere" }]); + let decision = decide(&answering(vec![answer.to_string()]), "test", &x3_r1_packet(), "The room is warm.", X3_LIBBY_R1, &Tuning::default()); + assert_eq!(decision["unverdicted"], json!([{ "act": "say", "draft": 1, "hold": "q3" }]), "{decision}"); +} diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index a665e24..e075ad9 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -3055,6 +3055,9 @@ fn k62_a_direct_message_names_its_reader() { let form = narrate::persona_speech_form(&packet); assert!(form.contains("goes into this direct message, whole, where only Meta, the operator reads it; or it is a note for Self"), "{form}"); assert!(!form.contains("everyone in it") && !form.contains(dm), "{form}"); + // Her own line in it, and a line in another room, name no reader. + let mixed = Room { messages: vec![message("#swarm:gamecult.org", "@kiko:gamecult.org", "Kiko", "Anyone around?", 3, false), message(dm, OWN, "Eureka", "Here.", 2, false), message(dm, OPERATOR, "Meta", "Write the two lines here, just for me.", 1, true)], here: Some(dm.into()), ..Room::default() }; + assert_eq!(packet_of(TurnKind::Chat, &state(), &mixed, &History::default(), 1).readers, ["Meta, the operator"]); // Two others in it: both named, and the verb agrees. let two = Room { messages: vec![message(dm, OPERATOR, "Meta", "Hi.", 2, true), message(dm, "@kiko:gamecult.org", "Kiko", "Hi both.", 1, true)], here: Some(dm.into()), ..Room::default() }; assert!(narrate::persona_speech_form(&packet_of(TurnKind::Chat, &state(), &two, &History::default(), 1)).contains("where only Meta, the operator and Kiko read it;"));