diff --git a/ANALYSIS.md b/ANALYSIS.md index 52d282b9..8261b309 100644 --- a/ANALYSIS.md +++ b/ANALYSIS.md @@ -10,7 +10,9 @@ must use that sanitized state. The export throws for unsupported positions. `canLaunchAnalysisMode(data)` allows finished games through the existing path, and permits ongoing ordinary play, civilization selection and movement when there is no pending event. Pending event stacks, Great Seer assignments and -remembered Spy information are currently excluded. These hold private choices +remembered Spy information are currently excluded. Positions after an Action +Card or Events pile reshuffle are also excluded: the engine keeps lifetime +discard archives, which no longer describe the current deck cycle. These hold private choices or knowledge that require specific reconstruction rules; copying or dropping them would be unsafe or change the position's legal continuation. @@ -28,7 +30,8 @@ be reconciled with the catalogue are rejected. Public facts needed for objective rules survive in a reduced current-round log: completed objectives, played wonders and combat statistics without private card -fields. Original actions, free text, private origin/modifier payloads, undo and +fields. Minimal typed observed-hand facts also survive, preserving known +opponent cards when the platform rerolls the sanitized original snapshot. Original actions, free text, private origin/modifier payloads, undo and redo are removed. The scenario cannot undo before the branch. Player listeners are rebuilt for simulated hands. Source seed, random state, queued dice results, messages, custom UI and dropped-seat automation are replaced or cleared. diff --git a/server/src/analysis.rs b/server/src/analysis.rs index 8a29dc7c..3eb6ee26 100644 --- a/server/src/analysis.rs +++ b/server/src/analysis.rs @@ -20,6 +20,12 @@ pub fn can_create(game: &Game) -> bool { && !game.permanent_effects.iter().any(|e| matches!(e, PermanentEffect::GreatSeer(_))) // Spy's prose records cannot reliably be mapped back to card identities. && game.players.iter().all(|p| p.secrets.is_empty()) + // These discard arrays are lifetime archives, not current-cycle piles. + // Once a pile has refilled, their exclusions are no longer sufficient. + && !game.log.iter().flat_map(|a| &a.rounds).flat_map(|r| &r.turns) + .flat_map(|t| &t.actions).flat_map(|a| &a.log).any(|text| { + text == "Reshuffling Action Card pile" || text == "Reshuffling Events pile" + }) } /// Build from public facts and the requesting seat's hand, never from the @@ -32,7 +38,7 @@ pub fn create(mut game: Game, seat: Option, seed: &str) -> Result, seed: &str) -> Result= crate::content::incidents::great_persons::GREAT_PERSON_OFFSET { + incidents.retain(|i| { + *i != *card - crate::content::incidents::great_persons::GREAT_PERSON_OFFSET + }); + } + } + } game.incidents_left = incidents; // Subtract the publicly revealed blocks from the published catalogue. Their // two legal orientations are equivalent; exhaustion retains base terrain. @@ -119,11 +134,36 @@ pub fn create(mut game: Game, seat: Option, seed: &str) -> Result]) { + // Keep only observed hand constraints at the branch, so a reroll of this + // sanitized snapshot retains the same knowledge without source history. + if known.iter().any(|cards| !cards.is_empty()) { + crate::log::add_log_action(game, Action::StartTurn); + for (player, cards) in known.iter().enumerate() { + for card in cards { + crate::log::add_action_log_item( + game, + player, + crate::log::ActionLogEntry::HandCard { + card: card.clone(), + from: HandCardLocation::Public, + to: HandCardLocation::Hand(player), + }, + EventOrigin::Ability("Analysis known card".into()), + vec![], + ); + } + } + game.undo_limit = game.log_index; + } +} + fn remaining_blocks(game: &Game) -> Result, String> { fn original(t: &Terrain) -> &Terrain { if let Terrain::Exhausted(inner) = t { @@ -456,6 +496,10 @@ mod tests { let game = create(copy(&source), seat, "fake").unwrap(); assert_eq!(game.players[1].action_cards, vec![id]); assert!(!game.action_cards_left.contains(&id)); + let rerolled = create(game, seat, "second simulation seed").unwrap(); + assert_eq!(rerolled.players[1].action_cards, vec![id]); + assert!(!rerolled.action_cards_left.contains(&id)); + assert!(!rerolled.can_undo()); } } @@ -485,4 +529,19 @@ mod tests { remaining.remove(i); } } + + #[test] + fn fails_closed_after_action_pile_refill() { + let mut game = game_api::init(2, "source".into(), GameOptions::default()); + crate::log::add_start_turn_action_if_needed(&mut game); + game.action_cards_left.clear(); + game.action_cards_discarded = game.cache.get_action_cards().iter().map(|c| c.id).collect(); + let p = game.active_player(); + let player = + crate::events::EventPlayer::from_player(p, &game, EventOrigin::Ability("test".into())); + crate::action_card::gain_action_card_from_pile(&mut game, &player); + assert!(!game.action_cards_left.is_empty()); + assert!(!can_create(&game)); + assert!(create(game, None, "fake").is_err()); + } }