AbilityFactory and X cost spells
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
4 posts
• Page 1 of 1
AbilityFactory and X cost spells
by Chris H. » 12 Dec 2010, 17:37
Sol suggested a couple of weeks ago that we start a topic devoted to how we should handle AbilityFactory and X cost spells.
At one point, Dennis cobbled together a few X-cost spells like Hurricane, etc. I used his code as a template and added a few more. I seem to remember that there was a method that we could call which would return how much un-tapped mana the AI had available.
We would subtract the non-X portion of the cost from this and that would give us a maximum value for the X portion. We could use this in determining if we should return a true or a false for canPlayAI(). Under most circumstances we probably do not want the computer to cast a Braingeyser that draws zero or one card.
I have not had a chance yet to think about how we would add this to AbilityFactory. It might make sense for the AFs to have at least a minimum X portion and some AFs might also want to have a max value.
I will get off of the soap box at this time and give others a chance to offer their own thoughts on how to handle X cost spells.
At one point, Dennis cobbled together a few X-cost spells like Hurricane, etc. I used his code as a template and added a few more. I seem to remember that there was a method that we could call which would return how much un-tapped mana the AI had available.
We would subtract the non-X portion of the cost from this and that would give us a maximum value for the X portion. We could use this in determining if we should return a true or a false for canPlayAI(). Under most circumstances we probably do not want the computer to cast a Braingeyser that draws zero or one card.
I have not had a chance yet to think about how we would add this to AbilityFactory. It might make sense for the AFs to have at least a minimum X portion and some AFs might also want to have a max value.
I will get off of the soap box at this time and give others a chance to offer their own thoughts on how to handle X cost spells.
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: AbilityFactory and X cost spells
by Rob Cashwalker » 12 Dec 2010, 20:47
The AI for an X spell needs to be smarter than just all available mana. Blaze a creature, and you don't need to spend more than necessary. Blaze the human, and you want to pump as much mana into it as possible.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: AbilityFactory and X cost spells
by friarsol » 12 Dec 2010, 21:14
Right. Don't forge the Human to discard more cards than are in their hand. Don't draw more than maybe 1 more than your hand limit.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: AbilityFactory and X cost spells
by Chris H. » 12 Dec 2010, 22:39
OK, I found the code for Braingeyser in an old archive. I will include the code below since it is fairly brief. canPlayAI calls ComputerUtil.getAvailableMana(). I will also include that code below.
Rob and Sol bring up good points. I think that these original X cost cards would tap out all of the computer's mana to pump up the biggest X cost that it could. The canPlayAI method is only checking to make sure that there is enough untapped mana to meet the minimum requirements.
How would we set and enforce a limit to the maximum X cost?
Braingeyser
ComputerUtil.getAvailableMana()
Rob and Sol bring up good points. I think that these original X cost cards would tap out all of the computer's mana to pump up the biggest X cost that it could. The canPlayAI method is only checking to make sure that there is enough untapped mana to meet the minimum requirements.
How would we set and enforce a limit to the maximum X cost?
Braingeyser
- Code: Select all
//*************** START *********** START **************************
else if(cardName.equals("Braingeyser"))
{
final SpellAbility spell = new Spell(card){
private static final long serialVersionUID = -7141472916367953810L;
public void resolve()
{
String player = getTargetPlayer();
for(int i=0;i<card.getXManaCostPaid();i++)
{
AllZone.GameAction.drawCard(player);
}
card.setXManaCostPaid(0);
}
public boolean canPlayAI()
{
final int maxX = ComputerUtil.getAvailableMana().size() - 1;
return maxX > 3 && AllZone.Computer_Hand.size() <= 3;
}
};
spell.setDescription("Target player draws X cards.");
spell.setBeforePayMana(CardFactoryUtil.input_targetPlayer(spell));
spell.setChooseTargetAI(CardFactoryUtil.AI_targetHuman());
card.clearSpellAbility();
card.addSpellAbility(spell);
}
//*************** END ************ END **************************
ComputerUtil.getAvailableMana()
- Code: Select all
static public CardList getAvailableMana()
{
CardList list = new CardList(AllZone.Computer_Play.getCards());
CardList mana = list.filter(new CardListFilter()
{
public boolean addCard(Card c)
{
//if(c.isCreature() && c.hasSickness())
// return false;
for (Ability_Mana am : c.getAIPlayableMana())
if (am.canPlay()) return true;
return false;
}
});//CardListFilter
CardList sortedMana = new CardList();
for (int i=0; i<mana.size();i++)
{
Card card = mana.get(i);
if (card.isBasicLand()){
sortedMana.add(card);
mana.remove(card);
}
}
for (int j=0; j<mana.size();j++)
{
sortedMana.add(mana.get(j));
}
return sortedMana;
}//getAvailableMana()
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 8 guests