mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- Prevent the Reckless AI (with MOVE_EQUIPMENT_TO_BETTER_CREATURES=true) from randomly moving equipment back and forth between two creatures with similar evaluation.
- Some code reorganization related to AI card memory.
This commit is contained in:
@@ -615,7 +615,6 @@ public class AiAttackController {
|
||||
attackersLeft.remove(attacker);
|
||||
}
|
||||
}
|
||||
aiMemory.clearRememberedAttackers(); // avoid "leaking" remembered cards over to the next turn
|
||||
|
||||
// Exalted
|
||||
if (combat.getAttackers().isEmpty()) {
|
||||
|
||||
@@ -42,6 +42,7 @@ public class AiCardMemory {
|
||||
|
||||
private HashSet<Card> memMandatoryAttackers = new HashSet<Card>();
|
||||
private HashSet<Card> memHeldManaSources = new HashSet<Card>();
|
||||
private HashSet<Card> memMovedEquipment = new HashSet<Card>();
|
||||
//private HashSet<Card> memRevealedCards = new HashSet<Card>();
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,7 @@ public class AiCardMemory {
|
||||
public enum MemorySet {
|
||||
MANDATORY_ATTACKERS,
|
||||
HELD_MANA_SOURCES,
|
||||
MOVED_EQUIPMENT,
|
||||
//REVEALED_CARDS // stub, not linked to AI code yet
|
||||
}
|
||||
|
||||
@@ -61,6 +63,8 @@ public class AiCardMemory {
|
||||
return memMandatoryAttackers;
|
||||
case HELD_MANA_SOURCES:
|
||||
return memHeldManaSources;
|
||||
case MOVED_EQUIPMENT:
|
||||
return memMovedEquipment;
|
||||
//case REVEALED_CARDS:
|
||||
// return memRevealedCards;
|
||||
default:
|
||||
@@ -232,6 +236,13 @@ public class AiCardMemory {
|
||||
getMemorySet(MemorySet.HELD_MANA_SOURCES).clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the "remembered moved equipment" memory set stored in this card memory for the given player.
|
||||
*/
|
||||
public void clearRememberedMovedEquipment() {
|
||||
getMemorySet(MemorySet.MOVED_EQUIPMENT).clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the "remembered revealed cards" memory set stored in this card memory for the given player.
|
||||
*/
|
||||
@@ -245,6 +256,7 @@ public class AiCardMemory {
|
||||
public void clearAllRemembered() {
|
||||
clearRememberedAttackers();
|
||||
clearRememberedManaSources();
|
||||
clearRememberedMovedEquipment();
|
||||
//clearRememberedRevealedCards();
|
||||
}
|
||||
}
|
||||
@@ -1145,6 +1145,12 @@ public class AiController {
|
||||
public SpellAbility choooseSpellAbilityToPlay() {
|
||||
final PhaseType phase = game.getPhaseHandler().getPhase();
|
||||
|
||||
if (phase == PhaseType.END_OF_TURN) {
|
||||
// for the next turn, make sure the decision to play SAs won't be affected by previously remembered decisions
|
||||
// TODO: if the card memory is ever used for anything that should be remembered for more than a turn, make sure it's not cleared here.
|
||||
getCardMemory().clearAllRemembered();
|
||||
}
|
||||
|
||||
if (game.getStack().isEmpty() && phase.isMain()) {
|
||||
Log.debug("Computer " + phase.nameForUi);
|
||||
List<Card> landsWannaPlay = getLandsToPlay();
|
||||
|
||||
@@ -1044,6 +1044,14 @@ public class AttachAi extends SpellAbilityAi {
|
||||
aic.reserveManaSourcesForMain2(futureSpell);
|
||||
}
|
||||
}
|
||||
|
||||
// avoid randomly moving the equipment back and forth between several creatures in one turn
|
||||
aic.getCardMemory().rememberCard(attachSource.getEquippingCard(), AiCardMemory.MemorySet.MOVED_EQUIPMENT);
|
||||
if (aic.getCardMemory().isRememberedCard(c, AiCardMemory.MemorySet.MOVED_EQUIPMENT)) {
|
||||
return null;
|
||||
} else {
|
||||
aic.getCardMemory().rememberCard(c, AiCardMemory.MemorySet.MOVED_EQUIPMENT);
|
||||
}
|
||||
}
|
||||
|
||||
if ((c == null) && mandatory) {
|
||||
|
||||
Reference in New Issue
Block a user