Skip to content

Improve AI mode selection for modal spells#10569

Open
Madwand99 wants to merge 2 commits intoCard-Forge:masterfrom
Madwand99:ImproveModalSpellAI
Open

Improve AI mode selection for modal spells#10569
Madwand99 wants to merge 2 commits intoCard-Forge:masterfrom
Madwand99:ImproveModalSpellAI

Conversation

@Madwand99
Copy link
Copy Markdown
Contributor

This improves CharmAi mode selection for modal spells that can choose extra modes when doing so is useful and payable.

Previously, the AI could identify one good mode and stop there, even on cards like Crush Contraband where choosing both modes is free and beneficial. It also did not properly reason about extra mode costs for mechanics like Escalate, Entwine, and Spree/Tiered.

Changes included:

Let non-trigger modal spells add additional useful modes when MinCharmNum < CharmNum.

Treat candidate extra modes like effects the AI can evaluate in the moment via normal spell/trigger heuristics.

Add cost-aware mode checks for:

  • Escalate: adds the Escalate cost once per mode beyond the first.
  • Spree/Tiered: adds each selected mode’s ModeCost.
  • Entwine: pays Entwine only when the full cost is payable and all modes look useful.

Avoid crashes from sub-mode AI that assumes full spell context by falling back safely during optional mode evaluation.

Added regression coverage for:

  • Crush Contraband
  • Collective Resistance with affordable/unaffordable Escalate
  • Journey of Discovery with Entwine
  • Requisition Raid with affordable/unaffordable Spree

Remaining known gap:

CanRepeatModes is still not properly handled by CharmAi. Cards like Confluences and Seasons that say “you may choose the same mode more than once” do not yet have smart repeat-mode selection. The current AI can choose multiple distinct good modes, but it does not intentionally rank and repeat the best mode when repetition would be optimal.

@Hanmac
Copy link
Copy Markdown
Contributor

Hanmac commented Apr 30, 2026

Example of AI where the old code added extra Cost but shouldn't:

AI used Lively Dirge: Return up to two creature cards with total mana value 4 or less from your graveyard to the battlefield.
while not having any creature in GY.

Because of that up to, AI thinks that it might be good enough.

Comment thread forge-ai/src/main/java/forge/ai/ability/CharmAi.java
Comment thread forge-ai/src/main/java/forge/ai/ability/CharmAi.java Outdated
Comment thread forge-ai/src/main/java/forge/ai/ability/CharmAi.java Outdated
@Madwand99
Copy link
Copy Markdown
Contributor Author

Example of AI where the old code added extra Cost but shouldn't:

AI used Lively Dirge: Return up to two creature cards with total mana value 4 or less from your graveyard to the battlefield. while not having any creature in GY.

Because of that up to, AI thinks that it might be good enough.

I looked into this case. We could add a narrow guard in CharmAi before paying for an extra mode: for paid ModeCost modes that are hidden ChangeZone effects from a known zone like graveyard to battlefield, check whether there is at least one matching card before adding the mode.

That would stop the Lively Dirge case where the AI pays for the reanimation mode with no creatures in graveyard. However, after checking the current card scripts, this guard appears to only help Lively Dirge right now, so it feels a bit too card-shaped for this modal-spell PR.

I think the better long-term fix is in ChangeZoneAi or the hidden-origin ChangeZone evaluation: “up to” hidden moves should not be considered useful just because choosing zero is legal, especially when an extra cost is being paid. I’m inclined to leave that as a follow-up unless maintainers prefer the narrow modal guard here.

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.

3 participants