Skip to content

Improve AI simulation stack resolution for multiplayer choices#10567

Closed
Madwand99 wants to merge 5 commits intoCard-Forge:masterfrom
Madwand99:ai-sim-controller-fixes
Closed

Improve AI simulation stack resolution for multiplayer choices#10567
Madwand99 wants to merge 5 commits intoCard-Forge:masterfrom
Madwand99:ai-sim-controller-fixes

Conversation

@Madwand99
Copy link
Copy Markdown
Contributor

This PR narrows the earlier AI decision work (#10559) to the simulator stack-resolution fix plus focused sacrifice decision coverage.

GameSimulator.resolveStack() now preserves the simulated AI player’s controller while temporarily installing simulation controllers for every other player. Previously, simulated stack resolution only wrapped one opponent, usually the weakest opponent. That worked for many two-player cases, but in multiplayer a resolving spell or trigger can require choices from several players. If a non-wrapped player needed to choose cards, permanents, targets, or confirm an action, simulation could accidentally hit a normal/UI/test controller instead of an AI simulation controller.

The included regression test uses a three-player Innocent Blood scenario because it forces multiple players to make sacrifice choices during stack resolution. With the old behavior, the non-weakest third player’s controller is reached and the test fails. With the new behavior, all non-preserved players use simulation controllers and the simulated stack resolves cleanly.

This also brings over focused sacrifice tests showing deterministic, value-aware sacrifice choices:

  • stable sacrifice choice across repeated simulation-controller calls
  • legal-candidate filtering
  • worst creatures selected first
  • least valuable permanent selected from mixed permanent options

Comment thread forge-ai/src/main/java/forge/ai/simulation/GameSimulator.java Outdated
Comment thread forge-gui-desktop/src/test/java/forge/ai/sacrifice/AiSacrificeDecisionTest.java Outdated
sa.setActivatingPlayer(opponent);
game.getStack().addAndUnfreeze(sa);

PlayerControllerForTests throwingController = new PlayerControllerForTests(game, otherOpponent, otherOpponent.getLobbyPlayer()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh, actually this test isn't proof either and it looks to me like the TODO was just outdated:
I spent the effort of actually debugging and thanks to clonePlayer I don't see how a GUI player should end up in a simulated game anyway...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll close this PR. If you have any feedback on how I can actually solve the issue of AI drawing cards into Xyris -> Impact tremors -> death, let me know.

@Madwand99 Madwand99 closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants