Page 1 of 1

AI_getBestEnchantment, Artifact and Permanent

PostPosted: 03 Aug 2010, 08:39
by Sloth
While testing the AI handling the Bounce keyword, I noticed that the AI doesn't pick the most expensive Permanent. So I looked into the functions in CardFactoryUtil.java and I think they don't work as intended.

This entry should sort out the card with the biggest mana cost:
Code: Select all
...
//get biggest Enchantment
        Card biggest = null;
        biggest = all.get(0);
       
        for(int i = 0; i < all.size(); i++) {
            if(CardUtil.getConvertedManaCost(biggest.getManaCost()) >= CardUtil.getConvertedManaCost(biggest.getManaCost())) {
                biggest = all.get(i);
            }
        }
       
        return biggest;
Correct me if I'm wrong but shouldn't
Code: Select all
if(CardUtil.getConvertedManaCost(biggest.getManaCost()) >= CardUtil.getConvertedManaCost(biggest.getManaCost()))
be something like:
Code: Select all
if(CardUtil.getConvertedManaCost(all.get(i).getManaCost()) >= CardUtil.getConvertedManaCost(biggest.getManaCost()))

Re: AI_getBestEnchantment, Artifact and Permanent

PostPosted: 03 Aug 2010, 13:20
by Snacko
It's good to create local variable to hold all.get(i), because if the if cause triggers then you'll have a 2nd collection lookup and this adds up the more cards there are.

Re: AI_getBestEnchantment, Artifact and Permanent

PostPosted: 03 Aug 2010, 14:46
by Rob Cashwalker
Code: Select all
int bigCMC = 0;
for (int i=0; i<all.size(); i++)
{
   int curCMC = CardUtil.getConvertedManaCost(all.get(i).getManaCost());
   
   if (curCMC > bigCMC)
   {
      bigCMC = curCMC;
      biggest = all.get(i);
   }
}