Replace first withContext call with more stable AI prediction (#7261)

This commit is contained in:
tool4ever
2025-03-25 19:08:36 +01:00
committed by GitHub
parent fcd8b8fd35
commit ac67a36ccf
29 changed files with 43 additions and 35 deletions

View File

@@ -111,6 +111,7 @@ public enum AbilityKey {
OriginalDefender("OriginalDefender"),
OriginalParams("OriginalParams"),
PayingMana("PayingMana"),
Phase("Phase"),
Player("Player"),
PreventedAmount("PreventedAmount"),
Produced("Produced"),

View File

@@ -58,7 +58,7 @@ public class SkipPhaseEffect extends SpellAbilityEffect {
final Card eff = createEffect(sa, player, name, image);
final StringBuilder sb = new StringBuilder();
sb.append("Event$ BeginPhase | ActiveZones$ Command | PlayerTurn$ You | ActivePhases$ ");
sb.append("Event$ BeginPhase | ActiveZones$ Command | ValidPlayer$ You | Phase$ ");
sb.append(phase != null ? phase : step);
if (duration != null && !isNextThisTurn) {
sb.append(" | Skip$ True");

View File

@@ -203,6 +203,7 @@ public class PhaseHandler implements java.io.Serializable {
}
final Map<AbilityKey, Object> repRunParams = AbilityKey.mapFromAffected(playerTurn);
repRunParams.put(AbilityKey.Phase, phase);
ReplacementResult repres = game.getReplacementHandler().run(ReplacementType.BeginPhase, repRunParams);
if (repres != ReplacementResult.NotReplaced) {
// Currently there is no effect to skip entire beginning phase

View File

@@ -4,6 +4,7 @@ import java.util.Map;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.phase.PhaseType;
import forge.game.spellability.SpellAbility;
public class ReplaceBeginPhase extends ReplacementEffect {
@@ -18,6 +19,14 @@ public class ReplaceBeginPhase extends ReplacementEffect {
@Override
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Affected))) {
return false;
}
if (hasParam("Phase") && !PhaseType.parseRange(getParam("Phase")).contains(runParams.get(AbilityKey.Phase))) {
return false;
}
return true;
}

View File

@@ -18,7 +18,6 @@
package forge.game.replacement;
import java.util.*;
import java.util.concurrent.Callable;
import com.google.common.base.MoreObjects;
import forge.game.card.*;
@@ -856,15 +855,13 @@ public class ReplacementHandler {
* Helper function to check if a phase would be skipped for AI.
*/
public boolean wouldPhaseBeSkipped(final Player player, final PhaseType phase) {
Callable<Boolean> proc = () -> {
final Map<AbilityKey, Object> repParams = AbilityKey.newMap();
List<ReplacementEffect> list = getReplacementList(ReplacementType.BeginPhase, repParams, ReplacementLayer.Control);
if (list.isEmpty()) {
return false;
}
return true;
};
return player.getGame().getPhaseHandler().withContext(proc, player, phase);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(player);
repParams.put(AbilityKey.Phase, phase);
List<ReplacementEffect> list = getReplacementList(ReplacementType.BeginPhase, repParams, ReplacementLayer.Control);
if (list.isEmpty()) {
return false;
}
return true;
}
/**