mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
-Changed CharmAi to use canPlayAi() instead of doTrigger() when deciding if a choice is good
This commit is contained in:
@@ -38,14 +38,24 @@ public class CharmAi extends SpellAbilityAi {
|
|||||||
} else if ("Triskaidekaphobia".equals(sa.getHostCard().getName())) {
|
} else if ("Triskaidekaphobia".equals(sa.getHostCard().getName())) {
|
||||||
chosenList = chooseTriskaidekaphobia(choices, ai);
|
chosenList = chooseTriskaidekaphobia(choices, ai);
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
|
* The generic chooseOptionsAi uses canPlayAi() to determine good choices
|
||||||
|
* which means most "bonus" effects like life-gain and random pumps will
|
||||||
|
* usually not be chosen. This is designed to force the AI to only select
|
||||||
|
* the best choice(s) since it does not actually know if it can pay for
|
||||||
|
* "bonus" choices (eg. Entwine/Escalate).
|
||||||
|
* chooseMultipleOptionsAi() uses "AILogic$Good" tags to manually identify
|
||||||
|
* bonus choice(s) for the AI otherwise it might be too hard to ever fulfil
|
||||||
|
* minimum choice requirements with canPlayAi() alone.
|
||||||
|
*/
|
||||||
chosenList = min > 1 ? chooseMultipleOptionsAi(choices, ai, min)
|
chosenList = min > 1 ? chooseMultipleOptionsAi(choices, ai, min)
|
||||||
: chooseOptionsAi(choices, ai, timingRight, num, min, sa.hasParam("CanRepeatModes"), false);
|
: chooseOptionsAi(choices, ai, timingRight, num, min, sa.hasParam("CanRepeatModes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chosenList.isEmpty()) {
|
if (chosenList.isEmpty()) {
|
||||||
if (timingRight) {
|
if (timingRight) {
|
||||||
// Set minimum choices for triggers where chooseMultipleOptionsAi() returns null
|
// Set minimum choices for triggers where chooseMultipleOptionsAi() returns null
|
||||||
chosenList = chooseOptionsAi(choices, ai, true, num, min, sa.hasParam("CanRepeatModes"), false);
|
chosenList = chooseOptionsAi(choices, ai, true, num, min, sa.hasParam("CanRepeatModes"));
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -56,48 +66,49 @@ public class CharmAi extends SpellAbilityAi {
|
|||||||
return r.nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
return r.nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<AbilitySub> chooseOptionsAi(List<AbilitySub> choices, final Player ai, boolean playNow, int num,
|
private List<AbilitySub> chooseOptionsAi(List<AbilitySub> choices, final Player ai, boolean isTrigger, int num,
|
||||||
int min, boolean allowRepeat, boolean opponentChoser) {
|
int min, boolean allowRepeat) {
|
||||||
List<AbilitySub> chosenList = new ArrayList<AbilitySub>();
|
List<AbilitySub> chosenList = new ArrayList<AbilitySub>();
|
||||||
// Make choice(s)
|
|
||||||
AiController aic = ((PlayerControllerAi) ai.getController()).getAi();
|
AiController aic = ((PlayerControllerAi) ai.getController()).getAi();
|
||||||
for (int i = 0; i < num; i++) {
|
// First pass using standard canPlayAi() for good choices
|
||||||
AbilitySub thisPick = null;
|
for (AbilitySub sub : choices) {
|
||||||
for (SpellAbility sub : choices) {
|
sub.setActivatingPlayer(ai);
|
||||||
sub.setActivatingPlayer(ai);
|
if (AiPlayDecision.WillPlay == aic.canPlaySa(sub)) {
|
||||||
if (!playNow && AiPlayDecision.WillPlay == aic.canPlaySa(sub)) {
|
chosenList.add(sub);
|
||||||
thisPick = (AbilitySub) sub;
|
if (chosenList.size() == num) {
|
||||||
choices.remove(sub);
|
return chosenList; // maximum choices reached
|
||||||
playNow = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if ((playNow || i < num - 1) && aic.doTrigger(sub, false)) {
|
|
||||||
thisPick = (AbilitySub) sub;
|
|
||||||
choices.remove(sub);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (thisPick != null) {
|
|
||||||
chosenList.add(thisPick);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set minimum choices for triggers
|
if (isTrigger && chosenList.size() < min) {
|
||||||
if (playNow && chosenList.size() < min) {
|
// Second pass using doTrigger(false) to fulfil minimum choice
|
||||||
for (int i = 0; i < min; i++) {
|
choices.removeAll(chosenList);
|
||||||
AbilitySub thisPick = null;
|
for (AbilitySub sub : choices) {
|
||||||
for (SpellAbility sub : choices) {
|
sub.setActivatingPlayer(ai);
|
||||||
sub.setActivatingPlayer(ai);
|
if (aic.doTrigger(sub, false)) {
|
||||||
if (aic.doTrigger(sub, true)) {
|
chosenList.add(sub);
|
||||||
thisPick = (AbilitySub) sub;
|
if (chosenList.size() == min) {
|
||||||
choices.remove(sub);
|
return chosenList;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (thisPick != null) {
|
}
|
||||||
chosenList.add(thisPick);
|
// Third pass using doTrigger(true) to force fill minimum choices
|
||||||
|
if (chosenList.size() < min) {
|
||||||
|
choices.removeAll(chosenList);
|
||||||
|
for (AbilitySub sub : choices) {
|
||||||
|
sub.setActivatingPlayer(ai);
|
||||||
|
if (aic.doTrigger(sub, true)) {
|
||||||
|
chosenList.add(sub);
|
||||||
|
if (chosenList.size() == min) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (chosenList.size() < min) {
|
||||||
|
chosenList.clear(); // not enough choices
|
||||||
|
}
|
||||||
return chosenList;
|
return chosenList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user