It is currently 05 Sep 2025, 11:02
   
Text Size

AI_getBestEnchantment, Artifact and Permanent

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

AI_getBestEnchantment, Artifact and Permanent

Postby Sloth » 03 Aug 2010, 08:39

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()))
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: AI_getBestEnchantment, Artifact and Permanent

Postby Snacko » 03 Aug 2010, 13:20

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.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: AI_getBestEnchantment, Artifact and Permanent

Postby Rob Cashwalker » 03 Aug 2010, 14:46

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);
   }
}
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 33 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 33 users online :: 0 registered, 0 hidden and 33 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 33 guests

Login Form