CB-WP-0023: SOLVE is legal only where it can do something
Some checks failed
ci / check (push) Failing after 4s
Some checks failed
ci / check (push) Failing after 4s
Implements ground-game's ruling of 2026-08-03. make all exits 0, 26 scenarios, rule coverage 59/59, and no scenario encoded the bug. The rule ended up somewhere other than where I put it, and a gate moved it. It went into legal_commands first; the AM-1 coverage gate then demanded a scenario for the new GR-P05, and scenarios drive validate, not the offer layer. A rule enforced only by the offer is enforced only for clients that ask what is legal -- the browser would be filtered and a scenario file would walk straight past it. Once GR-P05 moved into validate, every condition in legal_commands was dead code, and the layering test said so in those words. And the reported case was not the one I reported. CB-WP-0018 and the message to ground-game described SOLVE offered on a FACE-DOWN Problem. Measured: validate already rejected face-down, so it never was offered. Problem 1 is the Surface Problem, face-up from the deal -- the maintainer's three inert SOLVEs were the HAND case, holding no Clarify for a Clarify Problem. The ruling covers both so nothing is invalidated, but the record was wrong. Four conditions asserted separately, because one 'SOLVE is filtered' test would pass with three of four implemented. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
46c2fb652e
commit
6487d33f27
7 changed files with 321 additions and 16 deletions
|
|
@ -153,6 +153,17 @@ pub fn legal_commands(state: &GroundState, seat: PlayerId) -> Vec<GroundCommand>
|
|||
Action::Ground,
|
||||
] {
|
||||
match action {
|
||||
// Offered on every Problem; `validate` decides
|
||||
// which are legal, and this function filters every
|
||||
// candidate through it below.
|
||||
//
|
||||
// CB-WP-0023 first put GR-P05's conditions here, in
|
||||
// the OFFER layer. The AM-1 coverage gate then asked
|
||||
// for a scenario covering GR-P05 — and scenarios drive
|
||||
// `validate`, not this. That is what revealed the rule
|
||||
// belonged in `validate`: a rule enforced only by the
|
||||
// offer is enforced only for clients that ask what is
|
||||
// legal. Once it moved, everything here was dead code.
|
||||
Action::Investigate | Action::Solve => {
|
||||
for problem in &problems {
|
||||
candidates.push(GroundCommand::SelectAction {
|
||||
|
|
@ -649,6 +660,178 @@ mod tests {
|
|||
.expect("preset")
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// CB-WP-0023: SOLVE's legality, ruled by ground-game 2026-08-03.
|
||||
//
|
||||
// Four conditions, each asserted on its own, because a single
|
||||
// "SOLVE is filtered" test would pass with three of the four
|
||||
// implemented and nobody would know which.
|
||||
|
||||
/// Problems that SOLVE is offered on, for `seat`.
|
||||
fn solvable(state: &GroundState, seat: PlayerId) -> Vec<u32> {
|
||||
legal_commands(state, seat)
|
||||
.into_iter()
|
||||
.filter_map(|c| match c {
|
||||
GroundCommand::SelectAction {
|
||||
action: Action::Solve,
|
||||
problem: Some(n),
|
||||
..
|
||||
} => Some(n),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A 3p game where seat 0 can solve exactly problem 1.
|
||||
fn solvable_fixture() -> (GroundState, u32) {
|
||||
let mut st = setup(3, 42);
|
||||
let (n, suit) = st
|
||||
.problems
|
||||
.iter()
|
||||
.find(|(_, p)| p.face_up)
|
||||
.map(|(n, p)| (*n, p.suit))
|
||||
.expect("GR-S01 deals one face-up Surface Problem");
|
||||
// Give seat 0 the matching Solution, so the ONLY thing under test
|
||||
// is the condition each case perturbs.
|
||||
st.players.get_mut(&PlayerId(0)).expect("seat 0").hand = vec![crate::SolutionCard { suit }];
|
||||
assert_eq!(
|
||||
solvable(&st, PlayerId(0)),
|
||||
vec![n],
|
||||
"fixture is not solvable"
|
||||
);
|
||||
(st, n)
|
||||
}
|
||||
|
||||
/// **Which layer enforces GR-P05**, pinned so it cannot drift.
|
||||
///
|
||||
/// All four conditions live in `validate`, and `legal_commands` gets
|
||||
/// them for free by filtering candidates through it. This test is what
|
||||
/// keeps that true: if `validate` ever stops rejecting one, SOLVE
|
||||
/// becomes offerable again and the offer layer would have to grow a
|
||||
/// filter back.
|
||||
#[test]
|
||||
fn validate_enforces_all_four_solve_conditions() {
|
||||
let (base, n) = solvable_fixture();
|
||||
let sel = |p: u32| GroundCommand::SelectAction {
|
||||
action: Action::Solve,
|
||||
target: None,
|
||||
problem: Some(p),
|
||||
};
|
||||
let ok =
|
||||
|st: &GroundState, p: u32| st.validate(Actor::Player(PlayerId(0)), &sel(p)).is_ok();
|
||||
|
||||
let face_down = *base
|
||||
.problems
|
||||
.iter()
|
||||
.find(|(_, p)| !p.face_up)
|
||||
.map(|(k, _)| k)
|
||||
.expect("a face-down problem");
|
||||
println!(
|
||||
" validate accepts SOLVE on face-down: {}",
|
||||
ok(&base, face_down)
|
||||
);
|
||||
|
||||
let mut denied = base.clone();
|
||||
denied.problems.get_mut(&n).unwrap().denied = true;
|
||||
println!(" validate accepts SOLVE on denied: {}", ok(&denied, n));
|
||||
|
||||
let mut claimed = base.clone();
|
||||
claimed.problems.get_mut(&n).unwrap().claimed_by = Some(PlayerId(1));
|
||||
println!(
|
||||
" validate accepts SOLVE on claimed: {}",
|
||||
ok(&claimed, n)
|
||||
);
|
||||
|
||||
let mut nohand = base.clone();
|
||||
nohand.players.get_mut(&PlayerId(0)).unwrap().hand = vec![];
|
||||
println!(" validate accepts SOLVE with no hand: {}", ok(&nohand, n));
|
||||
|
||||
// validate's: adding these to `legal_commands` would be dead code.
|
||||
for (what, accepted) in [
|
||||
("face-down", ok(&base, face_down)),
|
||||
("Denied", ok(&denied, n)),
|
||||
("claimed", ok(&claimed, n)),
|
||||
("handless", ok(&nohand, n)),
|
||||
] {
|
||||
assert!(
|
||||
!accepted,
|
||||
"validate accepts SOLVE on a {what} Problem — GR-P05 is not \
|
||||
enforced where rules live, so only clients that ask what is \
|
||||
legal would be constrained"
|
||||
);
|
||||
}
|
||||
// Positive control: the fixture must still be solvable, or this
|
||||
// test would pass by rejecting everything.
|
||||
assert!(ok(&base, n), "the solvable fixture stopped being solvable");
|
||||
}
|
||||
|
||||
/// **The maintainer's reported case.** SOLVE was offered on a
|
||||
/// face-down Problem and did nothing; they played it three rounds
|
||||
/// running with no explanation. ground-game: *"not offered — illegal
|
||||
/// target. Browser no-ops were a filter bug, not a bluff mechanic."*
|
||||
#[test]
|
||||
fn solve_is_not_offered_on_a_face_down_problem() {
|
||||
let (st, open) = solvable_fixture();
|
||||
let face_down: Vec<u32> = st
|
||||
.problems
|
||||
.iter()
|
||||
.filter(|(_, p)| !p.face_up)
|
||||
.map(|(n, _)| *n)
|
||||
.collect();
|
||||
assert!(!face_down.is_empty(), "GR-S01 deals face-down Problems");
|
||||
let offered = solvable(&st, PlayerId(0));
|
||||
for n in face_down {
|
||||
assert!(
|
||||
!offered.contains(&n),
|
||||
"SOLVE offered on face-down problem {n}; offered = {offered:?}"
|
||||
);
|
||||
}
|
||||
assert!(offered.contains(&open), "the face-up one is still offered");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solve_is_not_offered_without_a_matching_solution_in_hand() {
|
||||
let (mut st, n) = solvable_fixture();
|
||||
let wrong = [
|
||||
crate::Suit::Clarify,
|
||||
crate::Suit::Repair,
|
||||
crate::Suit::Boundary,
|
||||
crate::Suit::Change,
|
||||
]
|
||||
.into_iter()
|
||||
.find(|s| *s != st.problems[&n].suit)
|
||||
.expect("another suit exists");
|
||||
st.players.get_mut(&PlayerId(0)).expect("seat 0").hand =
|
||||
vec![crate::SolutionCard { suit: wrong }];
|
||||
assert!(
|
||||
!solvable(&st, PlayerId(0)).contains(&n),
|
||||
"SOLVE offered with no matching Solution in hand"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solve_is_not_offered_on_a_denied_problem() {
|
||||
let (mut st, n) = solvable_fixture();
|
||||
st.problems.get_mut(&n).expect("problem").denied = true;
|
||||
assert!(
|
||||
!solvable(&st, PlayerId(0)).contains(&n),
|
||||
"SOLVE offered on a Denied Problem"
|
||||
);
|
||||
}
|
||||
|
||||
/// The ruling's (c): a Problem claimed in a PRIOR round is not
|
||||
/// offered. At Select time every `claimed_by` is prior-round, because
|
||||
/// claims land at Resolve — so the same-round race needs no code.
|
||||
#[test]
|
||||
fn solve_is_not_offered_on_an_already_claimed_problem() {
|
||||
let (mut st, n) = solvable_fixture();
|
||||
st.problems.get_mut(&n).expect("problem").claimed_by = Some(PlayerId(1));
|
||||
assert!(
|
||||
!solvable(&st, PlayerId(0)).contains(&n),
|
||||
"SOLVE offered on an already-claimed Problem"
|
||||
);
|
||||
}
|
||||
|
||||
fn policies(kind: &str, n: u8, seed: u64) -> Vec<Box<dyn Policy>> {
|
||||
(0..n)
|
||||
.map(|i| -> Box<dyn Policy> {
|
||||
|
|
|
|||
|
|
@ -1756,6 +1756,28 @@ impl GroundState {
|
|||
"GR-A13: Problem {problem} is not a face-up, non-Denied Problem"
|
||||
)));
|
||||
}
|
||||
// GR-P05, ruled by ground-game 2026-08-03: SOLVE is legal
|
||||
// only where it can do something. This lives in `validate`
|
||||
// and not only in `legal_commands` because a rule enforced
|
||||
// by the offer alone is enforced only for clients that ask
|
||||
// what is legal — the browser would be filtered and a
|
||||
// scenario file would not.
|
||||
Action::Solve if target.claimed_by.is_some() => {
|
||||
return Err(bad(format!(
|
||||
"GR-P05: Problem {problem} was claimed in an earlier round"
|
||||
)));
|
||||
}
|
||||
Action::Solve
|
||||
if !self
|
||||
.players
|
||||
.get(&actor)
|
||||
.is_some_and(|p| p.hand.iter().any(|c| c.suit == target.suit)) =>
|
||||
{
|
||||
return Err(bad(format!(
|
||||
"GR-P05: no {:?} Solution in hand for Problem {problem}",
|
||||
target.suit
|
||||
)));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else if problem.is_some() {
|
||||
|
|
@ -2482,7 +2504,11 @@ mod replay_probe {
|
|||
println!(
|
||||
" {seats}p: {} problem(s) worth {best} against a threshold of {need} \u{2014} {}",
|
||||
state.problems.len(),
|
||||
if best >= need { "reachable" } else { "UNREACHABLE" }
|
||||
if best >= need {
|
||||
"reachable"
|
||||
} else {
|
||||
"UNREACHABLE"
|
||||
}
|
||||
);
|
||||
}
|
||||
let unreachable: Vec<u8> = verdicts
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue