The AI and man lands
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
6 posts
• Page 1 of 1
The AI and man lands
by Chris H. » 05 May 2010, 21:28
I have spent some time recently fixing several of the lands which can be used to buff a creature type or changeling. Several of these cards can turn into a man land but the canPlayAI() returns false. There is a note with Mishra's Factory which states:
I put together a wee bit of code for Mutavault:
and the computer does attack most turns with the Mutavault.
There is still a minor problem. The computer tapped a mox to turn it's first Mutavault into a man land. It then tapped the man land Mutavault to convert the second Mutavault into a man land. There were still untapped mox in the land zone.
- Code: Select all
//it turns into a creature, but doesn't attack
I put together a wee bit of code for Mutavault:
- Code: Select all
public boolean canPlayAI() {
if (!card.isCreature() && CardFactoryUtil.canTarget(card, card) &&
AllZone.Phase.getPhase().equals(Constant.Phase.Main1)) return true;
else return false;
}
and the computer does attack most turns with the Mutavault.
There is still a minor problem. The computer tapped a mox to turn it's first Mutavault into a man land. It then tapped the man land Mutavault to convert the second Mutavault into a man land. There were still untapped mox in the land zone.
-
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: The AI and man lands
by jim » 08 May 2010, 23:25
Cool that you're looking at this. I notice that ComputerUtil.payManaCost() has a check to prevent the computer from tapping this card to pay for its own effect by removing it from the list of lands, so:
- Code: Select all
//this is to prevent errors for land cards that have abilities that cost mana.
if(sa.getSourceCard().isLand() /*&& sa.isTapAbility()*/)
{
land.remove(sa.getSourceCard());
}
- jim
- Posts: 46
- Joined: 19 Feb 2010, 01:46
- Location: Sunny New England
- Has thanked: 0 time
- Been thanked: 0 time
Re: The AI and man lands
by Chris H. » 09 May 2010, 00:01
`jim wrote:Maybe in the same place you could put a check for any SourceCards that are both land and creature? Alternately, if you added some kind of flag to tell that the "becomes a creature" ability was activated this turn, then you could check that flag and remove the land from the list if it's true...
Interesting, that does get us a little closer to having the AI attack with man lands. I am not familiar with the way the computer pays mana. I suspect that it creates a list of mana sources. The first mana source to go into play will always be the first entry in the list and the second mana source to go into play will always be the second entry in the list.
This creates a situation where if the AI has to pay mana costs and if the man land was one of the first sources to enter the battlefield ... well, this creates a situation where the man land taps for mana rather than attacking and there may have been other sources of mana available to use.
I'm wondering if we create a list of ! isCreature mana sources and then add to this a list of isCreature mana sources. We may find that the AI would normally still have untapped man lands to attack with after spending mana to animate a land into a man land. I don not know the mana code well enough to do much about this at this time.
I hope that Dennis and Rares will pitch in and comment on this idea of mine.

-
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: The AI and man lands
by Chris H. » 10 May 2010, 00:31
I thought about it some and I have this code in place and I will test it out. It may or may not work, not quite sure at this time.

- Code: Select all
static public void payManaCost(SpellAbility sa)
{
if(sa.getManaCost().equals(("0")))
return;
CardList land = getAvailableMana();
//this is to prevent errors for land cards that have abilities that cost mana.
if(sa.getSourceCard().isLand() /*&& sa.isTapAbility()*/)
{
land.remove(sa.getSourceCard());
}
//this is to prevent animated land/artifact cards from tapping for mana during Main 1
if ((sa.getSourceCard().isLand() || sa.getSourceCard().isArtifact()) &&
AllZone.Phase.getPhase().equals(Constant.Phase.Main1) &&
sa.getSourceCard().getController().equals(Constant.Player.Computer))
{
land.remove(sa.getSourceCard());
}
-
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: The AI and man lands
by DennisBergkamp » 10 May 2010, 05:30
I think in general, the AI will always try to cast/use his most expensive spells and abilities first, which is why I'm guessing it's kind of random whether he'll attack or not with his lands.
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: The AI and man lands
by Chris H. » 10 May 2010, 13:48
`DennisBergkamp wrote:I think in general, the AI will always try to cast/use his most expensive spells and abilities first, which is why I'm guessing it's kind of random whether he'll attack or not with his lands.
I tested my code a wee bit last night. I also changed the canPlayAI() method for Blinkmoth Nexus. The computer's Dryad Arbor did not tap to provide the mana needed to animate the Blinkmoth Nexus ... good. The Blinkmoth Nexus tapped to provide the mana they needed for this ability ... ugh, two tapped animated Blinkmoth Nexus in the creature zone.
I think that it still might be best to modify the list created in getAvailableMana(). Sort the list to have non-creatures first and creatures last in the list. The creature portion could be reverse sorted by attack. This might be the best that we can accomplish.
But I admit that I am in over my head. The code and the interactions can be very complicated. And the results may not be what we had initially intended.

-
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
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 52 guests