- Adamant AI: initial implementation, needs refining.

This commit is contained in:
Agetian
2020-07-08 21:21:41 +03:00
parent 03e15a4156
commit 1ae2055f5a
16 changed files with 36 additions and 13 deletions

View File

@@ -120,9 +120,18 @@ public class ComputerUtilMana {
}
private static void sortManaAbilities(final Multimap<ManaCostShard, SpellAbility> manaAbilityMap) {
sortManaAbilities(manaAbilityMap, null);
}
private static void sortManaAbilities(final Multimap<ManaCostShard, SpellAbility> manaAbilityMap, final SpellAbility sa) {
final Map<Card, Integer> manaCardMap = Maps.newHashMap();
final List<Card> orderedCards = Lists.newArrayList();
String manaPref = sa.getParamOrDefault("AIManaPref", "");
if (manaPref.isEmpty() && sa.getHostCard() != null && sa.getHostCard().hasSVar("AIManaPref")) {
manaPref = sa.getHostCard().getSVar("AIManaPref");
}
for (final ManaCostShard shard : manaAbilityMap.keySet()) {
for (SpellAbility ability : manaAbilityMap.get(shard)) {
final Card hostCard = ability.getHostCard();
@@ -147,6 +156,8 @@ public class ComputerUtilMana {
System.out.println();
}
final String preferredShard = manaPref;
for (final ManaCostShard shard : manaAbilityMap.keySet()) {
final Collection<SpellAbility> abilities = manaAbilityMap.get(shard);
final List<SpellAbility> newAbilities = new ArrayList<>(abilities);
@@ -160,6 +171,13 @@ public class ComputerUtilMana {
public int compare(final SpellAbility ability1, final SpellAbility ability2) {
int preOrder = orderedCards.indexOf(ability1.getHostCard()) - orderedCards.indexOf(ability2.getHostCard());
if (!preferredShard.isEmpty()) {
if (ability1.getManaPart().mana().contains(preferredShard))
return -1;
else if (ability2.getManaPart().mana().contains(preferredShard))
return 1;
}
if (preOrder == 0) {
// Mana abilities on the same card
String shardMana = shard.toString().replaceAll("\\{", "").replaceAll("\\}", "");
@@ -310,7 +328,7 @@ public class ComputerUtilMana {
// select which abilities may be used for each shard
Multimap<ManaCostShard, SpellAbility> sourcesForShards = ComputerUtilMana.groupAndOrderToPayShards(ai, manaAbilityMap, cost);
sortManaAbilities(sourcesForShards);
sortManaAbilities(sourcesForShards, sa);
ManaCostShard toPay;
// Loop over mana needed
@@ -621,7 +639,7 @@ public class ComputerUtilMana {
}
}
}
sortManaAbilities(sourcesForShards);
sortManaAbilities(sourcesForShards, sa);
if (DEBUG_MANA_PAYMENT) {
System.out.println("DEBUG_MANA_PAYMENT: sourcesForShards = " + sourcesForShards);
}

View File

@@ -3,5 +3,6 @@ ManaCost:3 W
Types:Creature Human Knight
PT:2/5
K:etbCounter:P1P1:1:Adamant$ White:Adamant — If at least three white mana was spent to cast this spell, CARDNAME enters the battlefield with a +1/+1 counter on it.
SVar:AIManaPref:W
DeckHas:Ability$Counters
Oracle:Adamant — If at least three white mana was spent to cast this spell, Ardenvale Paladin enters the battlefield with a +1/+1 counter on it.

View File

@@ -1,7 +1,7 @@
Name:Cauldron's Gift
ManaCost:4 B
Types:Sorcery
A:SP$ Mill | Cost$ 4 B | NumCards$ 4 | Defined$ You | SubAbility$ DBChangeZone | ConditionCheckSVar$ X | References$ X | SpellDescription$ Adamant — If at least three black mana was spent to cast this spell, mill four cards. You may choose a creature card in your graveyard. If you do, return it to the battlefield with an additional +1/+1 counter on it.
A:SP$ Mill | Cost$ 4 B | NumCards$ 4 | Defined$ You | SubAbility$ DBChangeZone | ConditionCheckSVar$ X | References$ X | AIManaPref$ B | SpellDescription$ Adamant — If at least three black mana was spent to cast this spell, mill four cards. You may choose a creature card in your graveyard. If you do, return it to the battlefield with an additional +1/+1 counter on it.
SVar:DBChangeZone:DB$ ChangeZone | Origin$ Graveyard | Destination$ Battlefield | ChangeType$ Creature.YouOwn | Hidden$ True | ChangeNum$ 1 | WithCounters$ P1P1_1
SVar:X:Count$Adamant.Black.1.0
DeckHas:Ability$Counters & Ability$Graveyard

View File

@@ -4,5 +4,6 @@ Types:Creature Human Knight
PT:4/1
K:Haste
K:etbCounter:P1P1:1:Adamant$ Red:Adamant — If at least three red mana was spent to cast this spell, CARDNAME enters the battlefield with a +1/+1 counter on it.
SVar:AIManaPref:R
DeckHas:Ability$Counters
Oracle:Haste\nAdamant — If at least three red mana was spent to cast this spell, Embereth Paladin enters the battlefield with a +1/+1 counter on it.

View File

@@ -1,7 +1,7 @@
Name:Foreboding Fruit
ManaCost:2 B
Types:Sorcery
A:SP$ Draw | Cost$ 2 B | NumCards$ 2 | ValidTgts$ Player | TgtPrompt$ Choose a player | SubAbility$ DBLoseLife | SpellDescription$ Target player draws two cards and loses 2 life. Adamant — If at least three black mana was spent to cast this spell, create a Food token. (It's an artifact with "{2}, {T}, Sacrifice this artifact: You gain 2 life.")
A:SP$ Draw | Cost$ 2 B | NumCards$ 2 | ValidTgts$ Player | TgtPrompt$ Choose a player | SubAbility$ DBLoseLife | AIManaPref$ B | SpellDescription$ Target player draws two cards and loses 2 life. Adamant — If at least three black mana was spent to cast this spell, create a Food token. (It's an artifact with "{2}, {T}, Sacrifice this artifact: You gain 2 life.")
SVar:DBLoseLife:DB$ LoseLife | LifeAmount$ 2 | Defined$ Targeted | SubAbility$ DBToken
SVar:DBToken:DB$ Token | TokenAmount$ X | TokenScript$ c_a_food_sac | TokenOwner$ You | LegacyImage$ c a food sac eld | References$ X
SVar:X:Count$Adamant.Black.1.0

View File

@@ -4,5 +4,6 @@ Types:Creature Giant Knight
PT:4/4
K:etbCounter:P1P1:1:Adamant$ Green:Adamant — If at least three green mana was spent to cast this spell, CARDNAME enters the battlefield with a +1/+1 counter on it.
K:CantBeBlockedBy Creature.powerLE2
SVar:AIManaPref:G
DeckHas:Ability$Counters
Oracle:Adamant — If at least three green mana was spent to cast this spell, Garenbrig Paladin enters the battlefield with a +1/+1 counter on it.\nGarenbrig Paladin can't be blocked by creatures with power 2 or less.

View File

@@ -4,5 +4,6 @@ Types:Creature Human Knight
PT:3/2
K:Menace
K:etbCounter:P1P1:1:Adamant$ Black:Adamant — If at least three black mana was spent to cast this spell, CARDNAME enters the battlefield with a +1/+1 counter on it.
SVar:AIManaPref:B
DeckHas:Ability$Counters
Oracle:Menace (This creature can't be blocked except by two or more creatures.)\nAdamant — If at least three black mana was spent to cast this spell, Locthwain Paladin enters the battlefield with a +1/+1 counter on it.

View File

@@ -1,7 +1,7 @@
Name:Once and Future
ManaCost:3 G
Types:Instant
A:SP$ ChangeZone | Cost$ 3 G | Origin$ Graveyard | Destination$ Hand | TgtPrompt$ Select target card in your graveyard to return to your hand | ValidTgts$ Card.YouOwn | SubAbility$ DBPump | StackDescription$ SpellDescription | SpellDescription$ Return target card from your graveyard to your hand. Put up to one other target card from your graveyard on top of your library. Exile CARDNAME. Adamant — If at least three green mana was spent to cast this spell, instead return those cards to your hand and exile CARDNAME.
A:SP$ ChangeZone | Cost$ 3 G | Origin$ Graveyard | Destination$ Hand | TgtPrompt$ Select target card in your graveyard to return to your hand | ValidTgts$ Card.YouOwn | SubAbility$ DBPump | AIManaPref$ G | StackDescription$ SpellDescription | SpellDescription$ Return target card from your graveyard to your hand. Put up to one other target card from your graveyard on top of your library. Exile CARDNAME. Adamant — If at least three green mana was spent to cast this spell, instead return those cards to your hand and exile CARDNAME.
SVar:DBPump:DB$ Pump | TargetMin$ 0 | TargetMax$ 1 | TgtZone$ Graveyard | TgtPrompt$ Select up to one target card in your graveyard to put on top of your library | ValidTgts$ Card.YouOwn | TargetUnique$ True | RememberObjects$ ThisTargetedCard | SubAbility$ DBReturn | StackDescription$ None
SVar:DBReturn:DB$ ChangeZone | Origin$ Graveyard | Destination$ Library | Hidden$ True | Defined$ Remembered | ConditionCheckSVar$ X | ConditionSVarCompare$ EQ0 | References$ X | SubAbility$ DBReturn2
SVar:DBReturn2:DB$ ChangeZone | Origin$ Graveyard | Destination$ Hand | Hidden$ True | Defined$ Remembered | ConditionCheckSVar$ X | References$ X | SubAbility$ DBExile

View File

@@ -1,7 +1,7 @@
Name:Outmuscle
ManaCost:3 G
Types:Sorcery
A:SP$ PutCounter | Cost$ 3 G | ValidTgts$ Creature.YouCtrl | TgtPrompt$ Choose target creature you control | RememberTargets$ True | CounterType$ P1P1 | CounterNum$ 1 | AILogic$ Fight | SubAbility$ DBFight | SpellDescription$ Put a +1/+1 counter on target creature you control, then it fights with a creature you don't control. Adamant — If at least three green mana was spent to cast this spell, the creature you control gets indestructible until end of turn.
A:SP$ PutCounter | Cost$ 3 G | ValidTgts$ Creature.YouCtrl | TgtPrompt$ Choose target creature you control | RememberTargets$ True | CounterType$ P1P1 | CounterNum$ 1 | AILogic$ Fight | AIManaPref$ G | SubAbility$ DBFight | SpellDescription$ Put a +1/+1 counter on target creature you control, then it fights with a creature you don't control. Adamant — If at least three green mana was spent to cast this spell, the creature you control gets indestructible until end of turn.
SVar:DBFight:DB$ Fight | Defined$ ParentTarget | ValidTgts$ Creature.YouDontCtrl | AILogic$ Always | TgtPrompt$ Choose target creature you don't control | SubAbility$ DBPump
SVar:DBPump:DB$ Pump | Defined$ Remembered | KW$ Indestructible | ConditionCheckSVar$ X | References$ X | SubAbility$ DBCleanup
SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True

View File

@@ -1,7 +1,7 @@
Name:Rally for the Throne
ManaCost:2 W
Types:Instant
A:SP$ Token | Cost$ 2 W | TokenAmount$ 2 | TokenScript$ w_1_1_human | TokenOwner$ You | LegacyImage$ w 1 1 human eld | SubAbility$ DBGainLife | SpellDescription$ Create two 1/1 white Human creature tokens. Adamant — If at least three white mana was spent to cast this spell, you gain 1 life for each creature you control.
A:SP$ Token | Cost$ 2 W | TokenAmount$ 2 | TokenScript$ w_1_1_human | TokenOwner$ You | LegacyImage$ w 1 1 human eld | AIManaPref$ W | SubAbility$ DBGainLife | SpellDescription$ Create two 1/1 white Human creature tokens. Adamant — If at least three white mana was spent to cast this spell, you gain 1 life for each creature you control.
SVar:DBGainLife:DB$ GainLife | Defined$ You | LifeAmount$ Y | ConditionCheckSVar$ X | References$ X,Y
SVar:X:Count$Adamant.White.1.0
SVar:Y:Count$Valid Creature.YouCtrl

View File

@@ -1,7 +1,7 @@
Name:Searing Barrage
ManaCost:4 R
Types:Instant
A:SP$ DealDamage | Cost$ 4 R | ValidTgts$ Creature | TgtPrompt$ Select target creature | NumDmg$ 5 | SpellDescription$ CARDNAME deals 5 damage to target creature. Adamant — If at least three red mana was spent to cast this spell, CARDNAME deals 3 damage to that creature's controller. | SubAbility$ DBDmg
A:SP$ DealDamage | Cost$ 4 R | ValidTgts$ Creature | TgtPrompt$ Select target creature | NumDmg$ 5 | AIManaPref$ R | SpellDescription$ CARDNAME deals 5 damage to target creature. Adamant — If at least three red mana was spent to cast this spell, CARDNAME deals 3 damage to that creature's controller. | SubAbility$ DBDmg
SVar:DBDmg:DB$ DealDamage | Defined$ TargetedController | NumDmg$ 3 | ConditionCheckSVar$ X | References$ X
SVar:X:Count$Adamant.Red.1.0
Oracle:Searing Barrage deals 5 damage to target creature.\nAdamant — If at least three red mana was spent to cast this spell, Searing Barrage deals 3 damage to that creature's controller.

View File

@@ -1,7 +1,7 @@
Name:Silverflame Ritual
ManaCost:3 W
Types:Sorcery
A:SP$ PutCounterAll | Cost$ 3 W | ValidCards$ Creature.YouCtrl | CounterType$ P1P1 | CounterNum$ 1 | SubAbility$ DBPumpAll | SpellDescription$ Put a +1/+1 counter on each creature you control. Adamant — If at least three white mana was spent to cast this spell, creatures you control gain vigilance until end of turn.
A:SP$ PutCounterAll | Cost$ 3 W | ValidCards$ Creature.YouCtrl | CounterType$ P1P1 | CounterNum$ 1 | SubAbility$ DBPumpAll | AIManaPref$ W | SpellDescription$ Put a +1/+1 counter on each creature you control. Adamant — If at least three white mana was spent to cast this spell, creatures you control gain vigilance until end of turn.
SVar:DBPumpAll:DB$ PumpAll | ValidCards$ Creature.YouCtrl | KW$ Vigilance | ConditionCheckSVar$ X | References$ X
SVar:X:Count$Adamant.White.1.0
DeckHas:Ability$Counters

View File

@@ -1,6 +1,6 @@
Name:Slaying Fire
ManaCost:2 R
Types:Instant
A:SP$ DealDamage | Cost$ 2 R | ValidTgts$ Creature,Player,Planeswalker | TgtPrompt$ Select any target | NumDmg$ X | References$ X | SpellDescription$ CARDNAME deals 3 damage to any target. Adamant — If at least three red mana was spent to cast this spell, it deals 4 damage instead.
A:SP$ DealDamage | Cost$ 2 R | ValidTgts$ Creature,Player,Planeswalker | TgtPrompt$ Select any target | NumDmg$ X | References$ X | AIManaPref$ R | SpellDescription$ CARDNAME deals 3 damage to any target. Adamant — If at least three red mana was spent to cast this spell, it deals 4 damage instead.
SVar:X:Count$Adamant.Red.4.3
Oracle:Slaying Fire deals 3 damage to any target.\nAdamant — If at least three red mana was spent to cast this spell, it deals 4 damage instead.

View File

@@ -1,7 +1,7 @@
Name:Turn into a Pumpkin
ManaCost:3 U
Types:Instant
A:SP$ ChangeZone | Cost$ 3 U | ValidTgts$ Permanent.nonLand | TgtPrompt$ Select target nonland permanent | Origin$ Battlefield | Destination$ Hand | SubAbility$ DBDraw | SpellDescription$ Return target nonland permanent to its owner's hand. Draw a card. Adamant — If at least three blue mana was spent to cast this spell, create a Food token. (It's an artifact with "{2}, {T}, Sacrifice this artifact: You gain 3 life.")
A:SP$ ChangeZone | Cost$ 3 U | ValidTgts$ Permanent.nonLand | TgtPrompt$ Select target nonland permanent | Origin$ Battlefield | Destination$ Hand | SubAbility$ DBDraw | AIManaPref$ U | SpellDescription$ Return target nonland permanent to its owner's hand. Draw a card. Adamant — If at least three blue mana was spent to cast this spell, create a Food token. (It's an artifact with "{2}, {T}, Sacrifice this artifact: You gain 3 life.")
SVar:DBDraw:DB$ Draw | NumCards$ 1 | SubAbility$ DBToken
SVar:DBToken:DB$ Token | TokenAmount$ X | TokenScript$ c_a_food_sac | TokenOwner$ You | LegacyImage$ c a food sac eld | References$ X
SVar:X:Count$Adamant.Blue.1.0

View File

@@ -1,7 +1,7 @@
Name:Unexplained Vision
ManaCost:4 U
Types:Sorcery
A:SP$ Draw | Cost$ 4 U | NumCards$ 3 | SubAbility$ DBScry | SpellDescription$ Draw three cards. Adamant — If at least three blue mana was spent to cast this spell, scry 3.
A:SP$ Draw | Cost$ 4 U | NumCards$ 3 | SubAbility$ DBScry | AIManaPref$ U | SpellDescription$ Draw three cards. Adamant — If at least three blue mana was spent to cast this spell, scry 3.
SVar:DBScry:DB$ Scry | ScryNum$ 3 | ConditionCheckSVar$ X | References$ X
SVar:X:Count$Adamant.Blue.1.0
Oracle:Draw three cards.\nAdamant — If at least three blue mana was spent to cast this spell, scry 3.

View File

@@ -5,4 +5,5 @@ PT:2/2
K:Flying
K:etbCounter:P1P1:1:Adamant$ Blue:Adamant — If at least three blue mana was spent to cast this spell, CARDNAME enters the battlefield with a +1/+1 counter on it.
DeckHas:Ability$Counters
SVar:AIManaPref:U
Oracle:Flying\nAdamant — If at least three blue mana was spent to cast this spell, Vantress Paladin enters the battlefield with a +1/+1 counter on it.