AI attacking and blocking Observations
by mtgrares
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Re: AI attacking and blocking Observations
by Sloth » 28 May 2011, 13:25
@Agetian: It's still (and will probably always be) a work in progress, but the AI will now make some simple gang blocks if the outcome is beneficial. It will also use Trade blocks a little bit more courageously.
Please keep reporting if you see anything stupid in the next version.
Please keep reporting if you see anything stupid in the next version.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AI attacking and blocking Observations
by Agetian » 28 May 2011, 14:27
Awesome, thanks a lot for your work! I didn't mean to sound overly critical, sorry if I inadvertently did - I just tried to pinpoint some of the things that I believed could be improved. By the way, I'm looking through the code in ComputerUtil_Block2.java and ComputerUtil_Attack2.java, as of now I have a good idea of how the current blocking code works, I'll see if I can come up with any modifications that could benefit the AI as well - I'll post over at the Dev forum if I come up with anything worth consideration.Sloth wrote:@Agetian: It's still (and will probably always be) a work in progress, but the AI will now make some simple gang blocks if the outcome is beneficial. It will also use Trade blocks a little bit more courageously.
Please keep reporting if you see anything stupid in the next version.


P.S. Will update to the latest SVN and give the changes a test run right now. Will report my findings ASAP.

- Agetian
- Programmer
- Posts: 3487
- Joined: 14 Mar 2011, 05:58
- Has thanked: 683 times
- Been thanked: 569 times
Re: AI attacking and blocking Observations
by Agetian » 28 May 2011, 14:43
Just upgraded to the latest SVN and tried the new AI in a match, unfortunately the game crashed during the AI's first attempt at considering whether to block my attack. Here's what happened:
The AI had Silent Attendant (0/2), I had a Goblin Raider with Blanchwood Armor (3/3 overall, I had one Forest in play). I attacked the AI with my Goblin Raider and past the Declare Attackers phase, the game crashed with the following dump:
Detailed error trace:
java.lang.NullPointerException
at forge.ComputerUtil_Block2.makeGangBlocks(ComputerUtil_Block2.java:200)
at forge.ComputerUtil_Block2.getBlockers(ComputerUtil_Block2.java:392)
at forge.ComputerAI_General.declare_blockers(ComputerAI_General.java:283)
at forge.gui.input.InputControl.updateInput(InputControl.java:116)
.......
SVN revision 9047.
Hope this helps.
EDIT: I committed a fix for the error, it seems like it was caused by the 'leader' var being null sometimes. Feel free to revert and fix in a different way if this was not what was intended and/or if the error is actually deeper than that and the 'leader' is not even supposed to be null at that point in the first place.
The AI had Silent Attendant (0/2), I had a Goblin Raider with Blanchwood Armor (3/3 overall, I had one Forest in play). I attacked the AI with my Goblin Raider and past the Declare Attackers phase, the game crashed with the following dump:
Detailed error trace:
java.lang.NullPointerException
at forge.ComputerUtil_Block2.makeGangBlocks(ComputerUtil_Block2.java:200)
at forge.ComputerUtil_Block2.getBlockers(ComputerUtil_Block2.java:392)
at forge.ComputerAI_General.declare_blockers(ComputerAI_General.java:283)
at forge.gui.input.InputControl.updateInput(InputControl.java:116)
.......
SVN revision 9047.
Hope this helps.

EDIT: I committed a fix for the error, it seems like it was caused by the 'leader' var being null sometimes. Feel free to revert and fix in a different way if this was not what was intended and/or if the error is actually deeper than that and the 'leader' is not even supposed to be null at that point in the first place.
- Agetian
- Programmer
- Posts: 3487
- Joined: 14 Mar 2011, 05:58
- Has thanked: 683 times
- Been thanked: 569 times
Re: AI attacking and blocking Observations
by Agetian » 28 May 2011, 16:26
I just played the game with the latest revision in mind, after fixing the null variable error from the previous post - here's a relevant portion of the game, I'm not sure if the AI should have chosen to gang up on my creature this time or not, but it didn't (not sure if it was supposed to according to the new code though):
The AI has 17 life, Pouncing Jaguar (x2), Elvish Lyrist, and Argothian Swine.
I have 14 life, Titania's Chosen currently at 4/4, and Acridian.
I attack with Titania's Chosen and the AI lets me deal damage, making it go down to 14. I think it might have been an opportune time to gang up with the Pouncing Jaguars to destroy my 4/4 before it bloats to much higher proportions.
The next turn the AI casts Hidden Spider and Cave Tiger, making my Titania's Chosen become 6/6. The AI attacks me with the Argothian Swine. The attack was probably not a very good decision too - the Argothian Swine is 3/3 trample while I had an untapped Acridian in play which was 2/4 and was enough to block the AI's attack, so I blocked.
The Argothian Swine is now tapped from the previous attack.
Now, the AI has 14 life and I have 14 life too. I have Titania's Chosen 6/6 and my Acridian 2/4, and the AI now has two Pouncing Jaguars, Elvish Lyrist, Cave Tiger, and the tapped Argothian Swine.
I attack with my Titania's Chosen and the AI lets me deal damage, making it go down to 7 life.
The AI in its turn doesn't attack me back and doesn't cast any spells, so the battlefield situation is the same.
I attack with my Titania's Chosen 6/6 again, and this time the AI sacrifices Elvish Lyrist on it - no attempt to gang up to kill the card is made either (but to be perfectly honest, I'm not sure what is better here, it kind of depends - though of course, the AI had facilities to destroy Titania's Chosen by ganging up if it wanted to).
The AI in its turn doesn't attack and casts Acridian, making my Titania's Chosen go up to 7/7.
All the subsequent turns the AI just sends creatures one by one to die at the hands of my attacker - as I attack with my Titania's Chosen 7/7, the AI will sacrifice one of its creatures by blocking with it.
Eventually the AI casts Serra's Embrace on its Agrothian Swine, and it becomes 5/5 Trample with Vigilance. It then attacks me with it.
Now, the AI has a 5/5 T V creature, a Cave Tiger, and an Acridian. I attack with Titania's Chosen 7/7 and the AI blocks with Cave Tiger only, not making an effort to get rid of my 7/7 threat by trading its Agrothian Swine for it in a gang block e.g. with the Cave Tiger.
Then the AI stops attacking me altogether and just holds on to its 5/5 Agrothian Swine, continuing to sacrifice the 2/* white and green creatures one by one when I attack.
Eventually, it runs out of additional creatures to cast/sac and has to block with the only remaining Agrothian Swine and it dies as well.
I attack with both my cards and win the game.
I'm not sure if the new code was supposed to kick in in any of these scenarios, so I hope it will help decide whether the new code is working correctly or something should be tweaked in it. Thanks again for all your hard work on the AI improvements and on Forge in general!
The AI has 17 life, Pouncing Jaguar (x2), Elvish Lyrist, and Argothian Swine.
I have 14 life, Titania's Chosen currently at 4/4, and Acridian.
I attack with Titania's Chosen and the AI lets me deal damage, making it go down to 14. I think it might have been an opportune time to gang up with the Pouncing Jaguars to destroy my 4/4 before it bloats to much higher proportions.
The next turn the AI casts Hidden Spider and Cave Tiger, making my Titania's Chosen become 6/6. The AI attacks me with the Argothian Swine. The attack was probably not a very good decision too - the Argothian Swine is 3/3 trample while I had an untapped Acridian in play which was 2/4 and was enough to block the AI's attack, so I blocked.
The Argothian Swine is now tapped from the previous attack.
Now, the AI has 14 life and I have 14 life too. I have Titania's Chosen 6/6 and my Acridian 2/4, and the AI now has two Pouncing Jaguars, Elvish Lyrist, Cave Tiger, and the tapped Argothian Swine.
I attack with my Titania's Chosen and the AI lets me deal damage, making it go down to 7 life.
The AI in its turn doesn't attack me back and doesn't cast any spells, so the battlefield situation is the same.
I attack with my Titania's Chosen 6/6 again, and this time the AI sacrifices Elvish Lyrist on it - no attempt to gang up to kill the card is made either (but to be perfectly honest, I'm not sure what is better here, it kind of depends - though of course, the AI had facilities to destroy Titania's Chosen by ganging up if it wanted to).
The AI in its turn doesn't attack and casts Acridian, making my Titania's Chosen go up to 7/7.
All the subsequent turns the AI just sends creatures one by one to die at the hands of my attacker - as I attack with my Titania's Chosen 7/7, the AI will sacrifice one of its creatures by blocking with it.
Eventually the AI casts Serra's Embrace on its Agrothian Swine, and it becomes 5/5 Trample with Vigilance. It then attacks me with it.
Now, the AI has a 5/5 T V creature, a Cave Tiger, and an Acridian. I attack with Titania's Chosen 7/7 and the AI blocks with Cave Tiger only, not making an effort to get rid of my 7/7 threat by trading its Agrothian Swine for it in a gang block e.g. with the Cave Tiger.
Then the AI stops attacking me altogether and just holds on to its 5/5 Agrothian Swine, continuing to sacrifice the 2/* white and green creatures one by one when I attack.
Eventually, it runs out of additional creatures to cast/sac and has to block with the only remaining Agrothian Swine and it dies as well.
I attack with both my cards and win the game.
I'm not sure if the new code was supposed to kick in in any of these scenarios, so I hope it will help decide whether the new code is working correctly or something should be tweaked in it. Thanks again for all your hard work on the AI improvements and on Forge in general!
- Agetian
- Programmer
- Posts: 3487
- Joined: 14 Mar 2011, 05:58
- Has thanked: 683 times
- Been thanked: 569 times
Re: AI attacking and blocking Observations
by Sloth » 28 May 2011, 19:47
Thanks for the fix and for the report Agetian.
There were two spots were the AI could have made a gang block but didn't:
1.
2.
These were real borderline cases you presented, but the decissions were clearly not optimal. I will try to improve gang blocking.
There were two spots were the AI could have made a gang block but didn't:
1.
Here the trade was not good enough for the AI (the more life the AI has the less willing it is to trade).Agetian wrote:The AI has 17 life, Pouncing Jaguar (x2), Elvish Lyrist, and Argothian Swine.
I have 14 life, Titania's Chosen currently at 4/4, and Acridian.
I attack with Titania's Chosen and the AI lets me deal damage, making it go down to 14. I think it might have been an opportune time to gang up with the Pouncing Jaguars to destroy my 4/4 before it bloats to much higher proportions.
2.
At the moment the AI won't trade two for one, so this was to be expexted.Agetian wrote:Now, the AI has a 5/5 T V creature, a Cave Tiger, and an Acridian. I attack with Titania's Chosen 7/7 and the AI blocks with Cave Tiger only, not making an effort to get rid of my 7/7 threat by trading its Agrothian Swine for it in a gang block e.g. with the Cave Tiger.
These were real borderline cases you presented, but the decissions were clearly not optimal. I will try to improve gang blocking.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AI attacking and blocking Observations
by Agetian » 29 May 2011, 07:37
Thanks, I appreciate your effort! Thanks for finding my comment useful too. I'm studying the AI code so I might eventually join you in an attempt to improve it. 

- Agetian
- Programmer
- Posts: 3487
- Joined: 14 Mar 2011, 05:58
- Has thanked: 683 times
- Been thanked: 569 times
Re: AI attacking and blocking Observations
by Sloth » 29 May 2011, 07:58
That's great to hear. I think the blocking code is well documented and very modular.Agetian wrote:Thanks, I appreciate your effort! Thanks for finding my comment useful too. I'm studying the AI code so I might eventually join you in an attempt to improve it.
If you really feel up to it you can also look at the attacking code. Unlike the blocking code it wasn't rewritten by me and it's still a mess, so don't hesitate to throw something out, rewrite it or clean it up.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AI attacking and blocking Observations
by friarsol » 29 May 2011, 13:23
Oh please do. Especially the parts where the AI has enough damage on the board from Evasive creatures to kill the Human. Sometimes it won't quite pull the trigger to do that last point with a flyer.Sloth wrote:If you really feel up to it you can also look at the attacking code. Unlike the blocking code it wasn't rewritten by me and it's still a mess, so don't hesitate to throw something out, rewrite it or clean it up.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: AI attacking and blocking Observations
by Agetian » 29 May 2011, 17:17
@ friarsol: I'll definitely see what I can do about the AI soon, I've pretty much understood the Blocking code and now I'm going to look through the Attacking code. It might still be a while before I start making actual AI-related commits though, but I'm working on it. 
@ Sloth: Here's another 2-to-1 trade type missed block opportunity for the AI by the way - I know it's currently not supported as an option that the AI would consider, but perhaps this scenario is something to think about when implementing how the AI should decide whether to trade 2 cards for one bigger threat:
I have 9 life, the AI has 7 life.
I have Elvish Herder, Priest of Titania, Viashino Outrider, and Elvish Lyrist.
The AI has Angelic Page, Goblin War Buggy, Bull Hippo, Sandbar Merfolk, and Goblin Patrol. The Angelic Page, Bull Hippo, and the Goblin War Buggy are tapped because the AI attacked.
I attack with my 4/3 Viashino Outrider, and the AI chooses not to gang up on it with Sandbar Merfolk and Goblin Patrol (2/1 Echo and 1/1 with no special abilities, respectively) because it doesn't want to trade two of its creatures for one mine.
However, Viashino Outrider is a 4/3 creature, while his two creatures are not really worthy (they don't have any special features and the 2/1 Sandbar Merfolk has an unpaid Echo cost to be paid next turn). I think it would have been a worthwhile trade, especially considering that the AI had other material on the battlefield, some of it tougher than my other creatures (e.g. his 3/3) and some of it with special abilities (e.g. Flying).
So, my considerations are:
Perhaps, the AI should consider trading 2-to-1 if: 1) the attacker's power is significant enough (e.g. 4 or more?) or the attacker has good effects on it (buffs, activated abilities that provided buffs, etc.), etc.; 2) the computer still had other creatures on the battlefield or in the hand so it won't be left with an empty battlefield and no things to cast after the trade; 3) the worth of the attacker is considerable compared to the worth of the creatures blocking it (a rather vague definition, I know, but maybe something to think about...)
Hope it helps!

@ Sloth: Here's another 2-to-1 trade type missed block opportunity for the AI by the way - I know it's currently not supported as an option that the AI would consider, but perhaps this scenario is something to think about when implementing how the AI should decide whether to trade 2 cards for one bigger threat:
I have 9 life, the AI has 7 life.
I have Elvish Herder, Priest of Titania, Viashino Outrider, and Elvish Lyrist.
The AI has Angelic Page, Goblin War Buggy, Bull Hippo, Sandbar Merfolk, and Goblin Patrol. The Angelic Page, Bull Hippo, and the Goblin War Buggy are tapped because the AI attacked.
I attack with my 4/3 Viashino Outrider, and the AI chooses not to gang up on it with Sandbar Merfolk and Goblin Patrol (2/1 Echo and 1/1 with no special abilities, respectively) because it doesn't want to trade two of its creatures for one mine.
However, Viashino Outrider is a 4/3 creature, while his two creatures are not really worthy (they don't have any special features and the 2/1 Sandbar Merfolk has an unpaid Echo cost to be paid next turn). I think it would have been a worthwhile trade, especially considering that the AI had other material on the battlefield, some of it tougher than my other creatures (e.g. his 3/3) and some of it with special abilities (e.g. Flying).
So, my considerations are:
Perhaps, the AI should consider trading 2-to-1 if: 1) the attacker's power is significant enough (e.g. 4 or more?) or the attacker has good effects on it (buffs, activated abilities that provided buffs, etc.), etc.; 2) the computer still had other creatures on the battlefield or in the hand so it won't be left with an empty battlefield and no things to cast after the trade; 3) the worth of the attacker is considerable compared to the worth of the creatures blocking it (a rather vague definition, I know, but maybe something to think about...)
Hope it helps!

- Agetian
- Programmer
- Posts: 3487
- Joined: 14 Mar 2011, 05:58
- Has thanked: 683 times
- Been thanked: 569 times
Re: AI attacking and blocking Observations
by Sloth » 29 May 2011, 18:00
@Agetian: there is a function called evaluateCreature which gives a value of about 100+ to creatures.
And the new SVN version actually supports two for one trades.
And the new SVN version actually supports two for one trades.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AI attacking and blocking Observations
by Agetian » 29 May 2011, 18:03
Hmm, well, unfortunately it chose not to make a trade described above in the very latest SVN (r9071 changes included)... That was the revision I was playing with already.Sloth wrote:@Agetian: there is a function called evaluateCreature which gives a value of about 100+ to creatures.
And the new SVN version actually supports two for one trades.


- Agetian
- Programmer
- Posts: 3487
- Joined: 14 Mar 2011, 05:58
- Has thanked: 683 times
- Been thanked: 569 times
Re: AI attacking and blocking Observations
by timmermac » 31 May 2011, 20:58
If you have a Wolf Pet to start, you can totally wreak havoc on the AI until it gets something with at least 4 toughness in play to block it. Can the blocking AI be modified so that if the AI has something in play with at least 3 power, it will block the Wolf Pet? A current example: I have a Wolf Pet, AI has an Ebony Treefolk. The computer should trade it's Treefolk for my wolf.
Edit: Also, the computer should at least consider blocking with creatures with the Wither ability in the early game.
Edit: Also, the computer should at least consider blocking with creatures with the Wither ability in the early game.
"I just woke up, haven't had coffee, let alone a pee in 7 days, and I find out you stole my ass and made a ...mini-me! Carter, I should be irked currently, yes?" - Jack O'Neill
Re: AI attacking and blocking Observations
by goonjamin » 17 Jun 2011, 11:58
I was playing SVN R9801 last night and had a number of creatures out. 2 of mine had infect, one was a flying 2/4 creature and the other a non flying 2/2 creature).
The AI had one flying 3/3 creature and 6 x 2/2 non flying squirrel tokens.
I was at 5 life and the AI was at 13 life with 8 poison counters. On the AI's turn it chose to attack only with it's flying creature. This left me open to attack and win the following turn using my flying 2/4 infect creature as he had no other flying creatures that could block. Had the AI not attacked he could have blocked this win indefinitely using his 3/3 flyer?
Does the current AI take poison counters into effect at all for attacking and blocking decisions?
The AI had one flying 3/3 creature and 6 x 2/2 non flying squirrel tokens.
I was at 5 life and the AI was at 13 life with 8 poison counters. On the AI's turn it chose to attack only with it's flying creature. This left me open to attack and win the following turn using my flying 2/4 infect creature as he had no other flying creatures that could block. Had the AI not attacked he could have blocked this win indefinitely using his 3/3 flyer?
Does the current AI take poison counters into effect at all for attacking and blocking decisions?
Re: AI attacking and blocking Observations
by Rob Cashwalker » 17 Jun 2011, 13:33
I had Priests of Norn out, and the AI didn't attack at all, with any of its 6 creatures. 10 turns later, the poison got there.
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: AI attacking and blocking Observations
by cc-drake » 02 Jul 2011, 07:53
AI has Mortician Beetle, Pulse Tracker, Cinder Crawler and Goblin Lookout. When I attack with a 2/2, AI decides to gangblock with Mortician Beetle and Pulse Tracker. Wouldn't it be better to gangblock with an 1/1 and a 1/2?
Who is online
Users browsing this forum: No registered users and 34 guests