AI_getBestEnchantment, Artifact and Permanent
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
3 posts
• Page 1 of 1
AI_getBestEnchantment, Artifact and Permanent
by 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:
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;
- Code: Select all
if(CardUtil.getConvertedManaCost(biggest.getManaCost()) >= CardUtil.getConvertedManaCost(biggest.getManaCost()))
- Code: Select all
if(CardUtil.getConvertedManaCost(all.get(i).getManaCost()) >= CardUtil.getConvertedManaCost(biggest.getManaCost()))
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AI_getBestEnchantment, Artifact and Permanent
by 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.
Re: AI_getBestEnchantment, Artifact and Permanent
by 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.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 46 guests