-
-
Notifications
You must be signed in to change notification settings - Fork 154
fix(engine): require distinct players for a multi-target player requirement #6572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matthewevans
merged 4 commits into
phase-rs:main
from
rsnetworkinginc:fix-scheming-symmetry-6459
Jul 29, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e87a2d
fix(engine): require distinct players for a multi-target player requi…
rsnetworkinginc b1bd781
Merge origin/main into fix-scheming-symmetry-6459
matthewevans b2f8472
fix(engine): widen per-instance target distinctness to players
rsnetworkinginc a0c5313
Merge remote-tracking branch 'origin/main' into handler/pr-6572
matthewevans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
crates/engine/tests/integration/issue_6459_scheming_symmetry.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| //! Scheming Symmetry — "Choose two target players." must require TWO DIFFERENT | ||
| //! players (CR 115.1b + CR 601.2c: the same player can't be chosen to fill more | ||
| //! than one of a single instruction's target slots). | ||
| //! | ||
| //! Regression for issue #6459: in a multiplayer game the same player could be | ||
| //! chosen for both slots. A modal "each mode must target a different player" | ||
| //! card already carries `DifferentTargetPlayers`, but a plain multi-target | ||
| //! player requirement had no constraint attached, so the runtime distinctness | ||
| //! authority never saw one to enforce. | ||
| //! | ||
| //! Two layers of proof: | ||
| //! * parser — the parsed ability carries `DifferentTargetPlayers`; | ||
| //! * runtime — after the first player is chosen, choosing that SAME player for | ||
| //! the second slot is rejected, while a DIFFERENT player is accepted (the | ||
| //! discriminating end-to-end behaviour). | ||
|
|
||
| use engine::game::scenario::GameScenario; | ||
| use engine::types::ability::TargetRef; | ||
| use engine::types::actions::GameAction; | ||
| use engine::types::game_state::{CastPaymentMode, WaitingFor}; | ||
| use engine::types::mana::ManaCost; | ||
| use engine::types::phase::Phase; | ||
| use engine::types::player::PlayerId; | ||
|
|
||
| const P0: PlayerId = PlayerId(0); | ||
| const P1: PlayerId = PlayerId(1); | ||
| const P2: PlayerId = PlayerId(2); | ||
|
|
||
| const SCHEMING: &str = | ||
| "Choose two target players. Each of them searches their library for a card, \ | ||
| then shuffles and puts that card on top."; | ||
|
|
||
| #[test] | ||
| fn scheming_symmetry_parses_distinct_player_constraint() { | ||
| use engine::types::game_state::TargetSelectionConstraint; | ||
|
|
||
| let parsed = engine::parser::parse_oracle_text( | ||
| SCHEMING, | ||
| "Scheming Symmetry", | ||
| &[], | ||
| &["Sorcery".to_string()], | ||
| &[], | ||
| ); | ||
| let ability = parsed | ||
| .abilities | ||
| .first() | ||
| .expect("Scheming Symmetry lowers to a spell ability"); | ||
| assert!( | ||
| ability | ||
| .target_constraints | ||
| .iter() | ||
| .any(|c| matches!(c, TargetSelectionConstraint::DifferentTargetPlayers)), | ||
| "a \"choose two target players\" requirement must carry \ | ||
| DifferentTargetPlayers (issue #6459); got {:?}", | ||
| ability.target_constraints | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn scheming_symmetry_rejects_choosing_the_same_player_twice() { | ||
| let mut scenario = GameScenario::new_n_player(3, 42); | ||
| scenario.at_phase(Phase::PreCombatMain); | ||
| for &pid in &[P0, P1, P2] { | ||
| scenario.with_library_top(pid, &["Lib A", "Lib B"]); | ||
| } | ||
| let spell = scenario | ||
| .add_spell_to_hand_from_oracle(P0, "Scheming Symmetry", true, SCHEMING) | ||
| .with_mana_cost(ManaCost::zero()) | ||
| .id(); | ||
| let mut runner = scenario.build(); | ||
|
|
||
| let card_id = runner.state().objects[&spell].card_id; | ||
| runner | ||
| .act(GameAction::CastSpell { | ||
| object_id: spell, | ||
| card_id, | ||
| targets: vec![], | ||
| payment_mode: CastPaymentMode::Auto, | ||
| }) | ||
| .expect("casting the sorcery must be accepted"); | ||
|
|
||
| // First slot: all three players are legal. Choose P1. | ||
| let WaitingFor::TargetSelection { | ||
| target_slots, | ||
| selection, | ||
| .. | ||
| } = runner.state().waiting_for.clone() | ||
| else { | ||
| panic!( | ||
| "expected a per-slot TargetSelection, got {}", | ||
| runner.waiting_for_kind() | ||
| ); | ||
| }; | ||
| let slot0 = &target_slots[selection.current_slot]; | ||
| for pid in [P0, P1, P2] { | ||
| assert!( | ||
| slot0.legal_targets.contains(&TargetRef::Player(pid)), | ||
| "{pid:?} must be a legal first-slot target, slot = {slot0:?}" | ||
| ); | ||
| } | ||
| runner | ||
| .act(GameAction::ChooseTarget { | ||
| target: Some(TargetRef::Player(P1)), | ||
| }) | ||
| .expect("choosing P1 for the first slot must succeed"); | ||
|
|
||
| // Second slot: choosing the ALREADY-CHOSEN player P1 must be rejected | ||
| // (CR 115.1b), while the state stays on the same target slot. | ||
| assert!( | ||
| matches!( | ||
| runner.state().waiting_for, | ||
| WaitingFor::TargetSelection { .. } | ||
| ), | ||
| "a second target slot must be surfaced, got {}", | ||
| runner.waiting_for_kind() | ||
| ); | ||
| let reselect_same = runner.act(GameAction::ChooseTarget { | ||
| target: Some(TargetRef::Player(P1)), | ||
| }); | ||
| assert!( | ||
| reselect_same.is_err(), | ||
| "CR 115.1b (issue #6459): choosing the already-chosen player P1 for the \ | ||
| second slot must be rejected" | ||
| ); | ||
| assert!( | ||
| matches!( | ||
| runner.state().waiting_for, | ||
| WaitingFor::TargetSelection { .. } | ||
| ), | ||
| "after the rejected reselection the second target slot must still be open" | ||
| ); | ||
|
|
||
| // A DIFFERENT player (P2) is accepted, so the requirement is satisfiable — | ||
| // proving the rejection is the distinctness rule, not a dead slot. | ||
| runner | ||
| .act(GameAction::ChooseTarget { | ||
| target: Some(TargetRef::Player(P2)), | ||
| }) | ||
| .expect("choosing a different player (P2) for the second slot must succeed"); | ||
| assert!( | ||
| !matches!( | ||
| runner.state().waiting_for, | ||
| WaitingFor::TargetSelection { .. } | ||
| ), | ||
| "with two distinct players chosen the spell must leave target selection, got {}", | ||
| runner.waiting_for_kind() | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.