Page 1 of 1

AbilityFactory and X cost spells

PostPosted: 12 Dec 2010, 17:37
by Chris H.
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.

Re: AbilityFactory and X cost spells

PostPosted: 12 Dec 2010, 20:47
by Rob Cashwalker
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.

Re: AbilityFactory and X cost spells

PostPosted: 12 Dec 2010, 21:14
by friarsol
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.

Re: AbilityFactory and X cost spells

PostPosted: 12 Dec 2010, 22:39
by Chris H.
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

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()