Computer phases?
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
15 posts
• Page 1 of 1
Computer phases?
by Rob Cashwalker » 23 May 2010, 14:58
I've been working on a all-pump keyword (like Overrun). Using this line from most of the other pump keywords:
So I flipped it a bit, and did a console print, and found that indeed, every time canPlayAI was called, getPhase returned "Main2".
However, during the human turn, it returns correct data.
On the other hand, I'm sure I've seen the AI play a pump spell, but how? (I put the same console print in the spPumpTgt section and found the same results)
- Code: Select all
if(AllZone.Phase.getPhase().equals(Constant.Phase.Main2)) return false;
So I flipped it a bit, and did a console print, and found that indeed, every time canPlayAI was called, getPhase returned "Main2".
However, during the human turn, it returns correct data.
On the other hand, I'm sure I've seen the AI play a pump spell, but how? (I put the same console print in the spPumpTgt section and found the same results)
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
Re: Computer phases?
by Chris H. » 23 May 2010, 17:12
I seem to remember that the computer would use pump spells on it's own creatures a long time ago. At some point this changed. It may have coincided with the spPump keyword or it may have been a tweaking of the code that caused this to happen.
Over the last year I believe that I too have seen the computer cast a pump spell on rare occasion. Was this a spPump keyword spell or was it one of the original pump spells that we had forgotten to convert at that time? I'm not sure.
Over the last year I believe that I too have seen the computer cast a pump spell on rare occasion. Was this a spPump keyword spell or was it one of the original pump spells that we had forgotten to convert at that time? I'm not sure.
-
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: Computer phases?
by Beached As » 23 May 2010, 18:36
I've witnessed the AI play Overrun as well (and then the AI won the game
)
On a side note, it would be good to allow the computer to play spells during the battle phase (such as power / toughness pumps) and have the available spells in a list, similar to the lists for the main1 and main2 phases in ComputerAI_General.java

On a side note, it would be good to allow the computer to play spells during the battle phase (such as power / toughness pumps) and have the available spells in a list, similar to the lists for the main1 and main2 phases in ComputerAI_General.java
- Beached As
- Programmer
- Posts: 110
- Joined: 23 Feb 2010, 07:48
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by DennisBergkamp » 23 May 2010, 21:25
Weird, I've never noticed this. I'll play around with some of the code...
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by DennisBergkamp » 24 May 2010, 16:52
Alright, I looked at this a bit more in depth, and as it turns out there's some funky stuff going on in ComputerAI_general:
We should either consider all cards, or perhaps add cards that make sense to be played in Main1. All cards might add a lot of stupidity to the AI though, so I'm not sure.
- Code: Select all
private ArrayList<String> getMain1PlayHand() {
ArrayList<String> play = new ArrayList<String>();
play.add("Man-o'-War");
play.add("Fire Imp");
play.add("Flametongue Kavu");
play.add("Briarhorn");
play.add("Inner-Flame Acolyte");
play.add("Affa Guard Hound");
play.add("Keening Banshee");
play.add("Aggressive Urge");
play.add("Amnesia");
play.add("Angelic Blessing");
play.add("Ashes to Ashes");
play.add("Beacon of Destruction");
play.add("Blinding Light");
play.add("Brute Force");
play.add("Cackling Flames");
play.add("Char");
play.add("Control Magic");
play.add("Crib Swap");
play.add("Dark Banishing");
play.add("Devour in Shadow");
play.add("Do or Die");
play.add("Douse in Gloom");
play.add("Echoing Decay");
play.add("Echoing Truth");
play.add("Elvish Fury");
play.add("Epic Proportions");
play.add("Erratic Explosion");
play.add("Explore");
play.add("Expunge");
play.add("Faceless Butcher");
play.add("Feral Lightning");
play.add("Finest Hour");
play.add("Firebolt");
play.add("Flamebreak");
play.add("Gaea's Anthem");
play.add("Giant Growth");
play.add("Glorious Anthem");
play.add("Hex");
play.add("Hidetsugu's Second Rite");
play.add("Hymn to Tourach");
play.add("Ichor Slick");
play.add("Infest");
play.add("Inspirit");
play.add("Kamahl, Pit Fighter");
play.add("Kjeldoran War Cry");
play.add("Lightning Bolt");
play.add("Might of Oaks");
play.add("Nameless Inversion");
play.add("Needle Storm");
play.add("Oblivion Ring");
play.add("Oubliette");
play.add("Path of Anger's Flame");
play.add("Peel from Reality");
play.add("Pestilence");
play.add("Plague Wind");
play.add("Pongify");
play.add("Primal Boost");
play.add("Psionic Blast");
play.add("Pyrohemia");
play.add("Repulse");
play.add("Saltblast");
play.add("Shock");
play.add("Shriekmaw");
play.add("Sower of Temptation");
play.add("Strangling Soot");
play.add("Sunlance");
play.add("Swords to Plowshares");
play.add("Take Possession");
play.add("Tendrils of Corruption");
play.add("Terror");
play.add("Threaten");
play.add("Tribal Flames");
play.add("Tromp the Domains");
play.add("Volcanic Hammer");
play.add("Wildsize");
play.add("Wings of Velis Vel");
play.add("Wit's End");
play.add("Wrap in Vigor");
return play;
}//getMain1PlayCards()
private SpellAbility[] getMain1() {
//Card list of all cards to consider
CardList hand = new CardList(AllZone.Computer_Hand.getCards());
hand = hand.filter(new CardListFilter() {
public boolean addCard(Card c) {
Collection<Card> play = playMain1Cards;
if(c.isLand()) return false;
if(play.contains(c.getName()) || (c.isCreature() && c.getKeyword().contains("Haste"))) return true;
return false;
}
});
CardList all = new CardList();
all.addAll(hand.toArray());
all.addAll(AllZone.Computer_Play.getCards());
return getPlayable(all);
}//getMain1()
We should either consider all cards, or perhaps add cards that make sense to be played in Main1. All cards might add a lot of stupidity to the AI though, so I'm not sure.
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by Rob Cashwalker » 25 May 2010, 03:09
Actually, unless there's a bunch that you didn't show above, then even that list seems ignored. (getPlayMain1Hand is not called by getMain1)
However, the canPlayAI methods for the pump spells were definitely being called. The status text indicated that it should still be prior to Attack Phase, and yet the AllZone.Phase seemed to think it was already Main2....
We should add a Card property for "shouldAIPlayMain1" and while we're at it, "shouldAIPlayMain2". Then the CardFactory code will set as appropriate. Change the getMain1 stuff to just look for creatures with haste or cards with "shouldAIPlayMain1".
I wonder if this is active code anyway... it doesn't make sense that a land isn't played in Main1. (isLand returns false)
However, the canPlayAI methods for the pump spells were definitely being called. The status text indicated that it should still be prior to Attack Phase, and yet the AllZone.Phase seemed to think it was already Main2....
We should add a Card property for "shouldAIPlayMain1" and while we're at it, "shouldAIPlayMain2". Then the CardFactory code will set as appropriate. Change the getMain1 stuff to just look for creatures with haste or cards with "shouldAIPlayMain1".
I wonder if this is active code anyway... it doesn't make sense that a land isn't played in Main1. (isLand returns false)
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
Re: Computer phases?
by jim » 28 May 2010, 01:42
Rob Cashwalker wrote:Actually, unless there's a bunch that you didn't show above, then even that list seems ignored. (getPlayMain1Hand is not called by getMain1)
The routine gets called by other code not shown above, which stuffs the list into the variable playMain1Cards.
I think the code is active. I added both Explore and Finest Hour to this list while I was testing them, and saw it make a difference in the way the AI played them. The reason it's returning false for any land cards because a separate routine (ComputerUtil.playLand()) finds the land card to play and plays it.Rob Cashwalker wrote: I wonder if this is active code anyway... it doesn't make sense that a land isn't played in Main1. (isLand returns false)
I have no explanation for the phase always returning Main2 though.
- jim
- Posts: 46
- Joined: 19 Feb 2010, 01:46
- Location: Sunny New England
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by DennisBergkamp » 28 May 2010, 02:40
This is probably just because the canPlayAI() method is ONLY called during Main2, since getMain1PlayHand() does not have the card in the list.I have no explanation for the phase always returning Main2 though.
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by Rob Cashwalker » 28 May 2010, 04:46
So all the pump spells and abilities have been completely useless all this time....
This list was probably added as a one or two card hack, and now it's standing in the way of hundreds of cards.
This list was probably added as a one or two card hack, and now it's standing in the way of hundreds of cards.
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
Re: Computer phases?
by DennisBergkamp » 28 May 2010, 04:53
Hmm, it's true it prevents spells from being cast, but abilities should still work during Main1.
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by mtgrares » 28 May 2010, 18:24
Alot of ComputerAI_general was struggling to make the computer play like a human. Since a human player usually plays lands during his Main2 phase, I reasoned that the computer should do that also. (Although now it seems like the computer plays his land during his Main1 but I'm not 100% sure.)
(The other ComputerAI_ classes like ComputerAI_rats can be deleted and aren't used.)
- Code: Select all
private ArrayList<String> getMain1PlayHand() {
ArrayList<String> play = new ArrayList<String>();
play.add("Man-o'-War");
play.add("Fire Imp");
(The other ComputerAI_ classes like ComputerAI_rats can be deleted and aren't used.)
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Computer phases?
by Rob Cashwalker » 29 May 2010, 15:08
With Landfall, it's better to play land in Main1. I've never seen (IRL) land played in Main2, unless it had some sort of drawback that made a difference.
Dennis- if you haven't started replacing the list as I suggested, then I'm going to start tackling it.
Dennis- if you haven't started replacing the list as I suggested, then I'm going to start tackling it.
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
Re: Computer phases?
by DennisBergkamp » 29 May 2010, 20:54
I haven't... feel free to start working on this, I'll be extremely busy for the next few weeks (months?), due to some quite significant changes in my life.
Hmm, I do remember there being some funky stuff going on with playing lands during Main1/Main2, it might be a bit unpredictable... but I agree the computer should definitely play lands during Main1. I think the Main2 land play code was put in there so that the computer will attempt to play a second or third (fourth... fifth...) land if possible (Exploration, Fastbond, etc.).
Hmm, I do remember there being some funky stuff going on with playing lands during Main1/Main2, it might be a bit unpredictable... but I agree the computer should definitely play lands during Main1. I think the Main2 land play code was put in there so that the computer will attempt to play a second or third (fourth... fifth...) land if possible (Exploration, Fastbond, etc.).
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by jim » 30 May 2010, 01:07
My recollection is also that the computer only plays land during main1. Like Dennis says, there is some funky stuff with the computer's land-playing code. I experimented with some code to try to make it play land during main2 when I was adding Explore. I seem to recall that the computer's "Can I still play a land" flag gets reset at the end of main1. If you try to allow the computer play land in main2 without changing that fact, it will play twice the number of land it's allowed to during the turn. At the time I wasn't sure where to move the reset of that flag, and I'm not sure if anything else counts on it being reset before main2. This is why I ended up putting Explore in the 'play during main1' list: it was a smaller change with a more easily visible consequence.
In any case, because I forgot to say it before, I should say I also endorse the idea of replacing this list with card-specific information. It doesn't seem very maintainable in its present form.
In any case, because I forgot to say it before, I should say I also endorse the idea of replacing this list with card-specific information. It doesn't seem very maintainable in its present form.
- jim
- Posts: 46
- Joined: 19 Feb 2010, 01:46
- Location: Sunny New England
- Has thanked: 0 time
- Been thanked: 0 time
Re: Computer phases?
by mtgrares » 02 Jun 2010, 19:55
Well just take it easy, no one expects you to be super human. (Well unless your Superman which I doubt.DennisBergkamp wrote:I haven't... feel free to start working on this, I'll be extremely busy for the next few weeks (months?), due to some quite significant changes in my life.

You have done a great job being the lead programmer.

- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
15 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 21 guests