Possible improvements for AI combat
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Possible improvements for AI combat
by mtgrares » 16 Aug 2010, 21:24
I think I could improve the AI combat code but it would only value each creature by its power/toughness and getValue(Card) which returns a number. getValue() would return 100 for Royal Assassin and 1 for a generic 1/1. Do you think this would really improve the AI or not?
(The values returned by getValue() would be guesses but it would help the computer differentiate between low value and high value cards that have very good abilities like Royal Assassin.)
Right now the code for when the AI attacks or blocks is very, very simple, no simulations are run. Allowing the AI to run simulations that take a few seconds would simulate when you think ahead and figure out how your opponent may block.
On a side note, the new code would probably take a few seconds to run and some cards like Giant Growth "ask" the AI if a specific creature attacks or not. So the new card may break cards that increase the power/toughness.
I should be able to use a alpha-beta for the AI.
Alpha-Beta - Wikiepdia Entry
Below is useable pseudo-code for alpha-beta.

(The values returned by getValue() would be guesses but it would help the computer differentiate between low value and high value cards that have very good abilities like Royal Assassin.)
Right now the code for when the AI attacks or blocks is very, very simple, no simulations are run. Allowing the AI to run simulations that take a few seconds would simulate when you think ahead and figure out how your opponent may block.
On a side note, the new code would probably take a few seconds to run and some cards like Giant Growth "ask" the AI if a specific creature attacks or not. So the new card may break cards that increase the power/toughness.
I should be able to use a alpha-beta for the AI.
Alpha-Beta - Wikiepdia Entry
Below is useable pseudo-code for alpha-beta.

- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Possible improvements for AI combat
by mtgrares » 16 Aug 2010, 21:25
As another side note, if getValue() was created, it could be used for drafts so the AI would pick high value cards.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Possible improvements for AI combat
by Chris H. » 17 Aug 2010, 00:27
I guess that we could create an SVar:Value:{1 to 100} and then add this additional SVar to the cards in cards.txt.
-
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: Possible improvements for AI combat
by Rob Cashwalker » 17 Aug 2010, 03:53
SVars don't work as we had thought... see my post in the picture and rarity thread.....
Problem with scoring like that is it's entirely subjective.... Ask 100 people to rate Royal Assasin on a scale of 0 to 100, and you'll get a number of different responses..
As I was trying to brainstorm in Sloth's spBounceAll thread, there has to be a way to dynamically score a card. P/T/keywords, CMC, rarity, legendary, length of text. Forge is full of sorting methods based on these metrics, very few of which use any standards....
A big help for AI would be a variant of CombatUtil.getAttackers that is able to take power. toughness and keywords as parameters, such that the evaluation would take into account the bonus that would be applied IF the pump spell was played by the time combat occurred. The AI may not attack in the current state... but after Overrun? Probabaly.
Problem with scoring like that is it's entirely subjective.... Ask 100 people to rate Royal Assasin on a scale of 0 to 100, and you'll get a number of different responses..
As I was trying to brainstorm in Sloth's spBounceAll thread, there has to be a way to dynamically score a card. P/T/keywords, CMC, rarity, legendary, length of text. Forge is full of sorting methods based on these metrics, very few of which use any standards....
A big help for AI would be a variant of CombatUtil.getAttackers that is able to take power. toughness and keywords as parameters, such that the evaluation would take into account the bonus that would be applied IF the pump spell was played by the time combat occurred. The AI may not attack in the current state... but after Overrun? Probabaly.
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: Possible improvements for AI combat
by Chris H. » 17 Aug 2010, 12:04
I see that I went to bed early last night and I am now trying to get caught up on the brainstorming. A card.getValue() is starting to look very interesting. This method would dynamically score the card and we could add in tests for new keywords as they are added to the code base.
This scoring system could be adjusted via some sort of a modifier, like the quest difficulty setting?
This scoring system could be adjusted via some sort of a modifier, like the quest difficulty setting?
-
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: Possible improvements for AI combat
by juzamjedi » 17 Aug 2010, 15:42
Improving combat AI is a very important topic. I'm happy to kick around some ideas with you folks as I would love to be surprised by Giant Growth, or Lightning Bolt / Doom Blade / Unsummon removing one of my creatures that multiple blocked a big monster.
The getValue() function for each card would be pretty hard to do. Rob is right that people would value those cards very differently. The context of the game state changes the value of a card a lot. Something like the CombatUtil.getAttackers evaluating the entire game state is the spirit of rares' pseudo code and also (in my opinion) the better way to approach the AI.
I am personally OK with the game taking longer if the AI will make better decisions. Maybe you could have a toggle button in the menu bar that can let users decide if they want the easy AI or the (new, hopefully) hard AI.
Rares, I have been meaning to update the draft cube for a while. I'll revive that topic with an update and then we can discuss how to improve the AI draft values in that topic.
The getValue() function for each card would be pretty hard to do. Rob is right that people would value those cards very differently. The context of the game state changes the value of a card a lot. Something like the CombatUtil.getAttackers evaluating the entire game state is the spirit of rares' pseudo code and also (in my opinion) the better way to approach the AI.
I am personally OK with the game taking longer if the AI will make better decisions. Maybe you could have a toggle button in the menu bar that can let users decide if they want the easy AI or the (new, hopefully) hard AI.
Rares, I have been meaning to update the draft cube for a while. I'll revive that topic with an update and then we can discuss how to improve the AI draft values in that topic.

Re: Possible improvements for AI combat
by Rob Cashwalker » 17 Aug 2010, 19:06
juzamjedi - check into the thread about SVars for rarity and pictures. At the moment, the draft files aren't being used. We are intending to use an SVar for it, possibly "DraftRarity". The ReadBoosterPack class is called by the DeckEditor, so every card needs to present a "Rarity" SVar. I'll check how much ReadDraftBoosterPack is used, and if it is only used for generating the draft pools, then I can make it accept something like "Removed".
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: Possible improvements for AI combat
by juzamjedi » 18 Aug 2010, 04:33
It is interesting you say that. I still have my Draft folder from ages past and my draft rarity files still work. The only cards that show in my draft pool are the cards in my draft cube.
Re: Possible improvements for AI combat
by DennisBergkamp » 18 Aug 2010, 05:00
Oh, those changes haven't gone into effect yet, except on the SVN.
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
getValue() and min-max
by mtgrares » 19 Aug 2010, 18:17
The getValue(Card) is meant to be viewed as "how good can the AI use this card" which is similar but not the same as "how good can a human player use this card". getValue(Card) is a way for the AI to view Eager Cadet as less valuable as Soul Warden, since they are both 1/1 creatures. This hypothetical, better combat system would not take into account activated or static abilities because the combat system would be built separate from everything else in Forge.
Min-Max:
On a side note I spent a couple of hours implemented min-max but even from the nice pseudo-code, I couldn't get the code working. The book where I got the pseudo-code implements min-max and its optimized cousin alpha-beta in Java. The link to the book is here, the code is under "Examples" on the left of the page, and in the "Releases" directory. There is nothing like 10 MB of zipped source code to swim through.
Min-Max:
On a side note I spent a couple of hours implemented min-max but even from the nice pseudo-code, I couldn't get the code working. The book where I got the pseudo-code implements min-max and its optimized cousin alpha-beta in Java. The link to the book is here, the code is under "Examples" on the left of the page, and in the "Releases" directory. There is nothing like 10 MB of zipped source code to swim through.

- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
draft
by mtgrares » 19 Aug 2010, 18:23
No problem, I've sort of been in limbo myself.juzamjedi wrote:Rares, I have been meaning to update the draft cube for a while. I'll revive that topic with an update and then we can discuss how to improve the AI draft values in that topic.

- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
dynamically score a card
by mtgrares » 19 Aug 2010, 18:43
Good questionRob Cashwalker wrote:As I was trying to brainstorm in Sloth's spBounceAll thread, there has to be a way to dynamically score a card. P/T/keywords, CMC, rarity, legendary, length of text. Forge is full of sorting methods based on these metrics, very few of which use any standards....

Sometimes Goblin King is worth his weight in gold if you are using a goblin deck, but if you happen to find him in your randomly created deck, he is a lame 2/2 that costs 1RR. Forge does "static guessing" and does not compute any future actions. Since cards can (and do) change value, the only correct way to do dynamic scoring is to use a real algorithm like min-max. The problem of min-max and similar algorithms is that you have to be able to undo everything which is a ton of work.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Possible improvements for AI combat
by Rob Cashwalker » 20 Aug 2010, 15:05
We don't necessarily need a flat-out score, we just need a good, EXTENSIBLE and DYNAMIC way for the Card object to compare itself to another Card.
Then evaluation simply becomes either
Goblin King would have a method that MAY evaluate higher than the other card if there were other goblins controlled by its controller, possibly also consider whether the opponent has mountains in play.... There would be other qualifiers of course, comparing power and toughness and CMC, for example. As a static pump keyword becomes available, the method generated by the keyword code will have to consider whatever types are specified.
Then evaluation simply becomes either
- Code: Select all
if (CardA.isBetterThan(CardB))
or
if (CardA > CardB)
Goblin King would have a method that MAY evaluate higher than the other card if there were other goblins controlled by its controller, possibly also consider whether the opponent has mountains in play.... There would be other qualifiers of course, comparing power and toughness and CMC, for example. As a static pump keyword becomes available, the method generated by the keyword code will have to consider whatever types are specified.
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: Possible improvements for AI combat
by mtgrares » 20 Aug 2010, 18:09
Yeah cards like Goblin King (and other things like card combos) become more valuable with other certain cards. So the evaluation function could look in the player's hand to see if anything is valuable. Obviously it is hard to make evaluations simple because all of the parts are connected.
DeckArena is really good at evaluations but I'm sure that it took a lot of time.
DeckArena is really good at evaluations but I'm sure that it took a lot of time.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
16 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 28 guests