It is currently 14 May 2025, 08:26
   
Text Size

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

Postby 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.
Image
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Possible improvements for AI combat

Postby 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

Postby 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.
User avatar
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

Postby 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.
The Force will be with you, Always.
User avatar
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

Postby 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?
User avatar
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

Postby 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. :)
juzamjedi
Tester
 
Posts: 575
Joined: 13 Nov 2008, 08:35
Has thanked: 6 times
Been thanked: 8 times

Re: Possible improvements for AI combat

Postby 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.
User avatar
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

Postby 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.
juzamjedi
Tester
 
Posts: 575
Joined: 13 Nov 2008, 08:35
Has thanked: 6 times
Been thanked: 8 times

Re: Possible improvements for AI combat

Postby DennisBergkamp » 18 Aug 2010, 05:00

Oh, those changes haven't gone into effect yet, except on the SVN.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

getValue() and min-max

Postby 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. :!:
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Overrun

Postby mtgrares » 19 Aug 2010, 18:19

Rob Cashwalker wrote:The AI may not attack in the current state... but after Overrun? Probabaly.
One way to code Overrun is have the AI play it, if it has 3 or more creatures. Even 3 creatures with Overrun is very lethal. (No this isn't a "great" solution, just a real-world one.)
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

draft

Postby mtgrares » 19 Aug 2010, 18:23

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. :)
No problem, I've sort of been in limbo myself. :D (I've recently become addicted to the medical show House and can watch half a season in a day. Needless to say that I don't get much programming done AND I'm enjoying the insane racing game Burnout Revenge on my old, but useable, Playstation 2.)
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

dynamically score a card

Postby mtgrares » 19 Aug 2010, 18:43

Rob 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....
Good question :wink:

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

Postby 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
Code: Select all
 if (CardA.isBetterThan(CardB))
or
 if (CardA > CardB) 
The isBetterThan method (or an over-riden comparison operator) would call upon a helper object that can be dynamically created and added to a Card like a SpellAbility. This object would have a method where all the card-specific differences in evaluation would be considered.

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.
User avatar
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

Postby 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.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 18 guests


Who is online

In total there are 18 users online :: 0 registered, 0 hidden and 18 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 18 guests

Login Form