A "Generic" I.A. improvement

All about getting the AI less baka...
Yorien
Posts: 33
Joined: Tue Feb 02, 2010 10:59 pm

A "Generic" I.A. improvement

Post by Yorien »

Yorien says:

Well, this is just an idea continuing the "old" AI Improvement topic...

viewtopic.php?f=14&t=416&start=0

Since the main problem with the PSP is that CPU is low on speed (in fact, I played Shandalar with an old 350mhz PII, and once there were enough cards on the battlefield the IA could spend minutes "thinking") hardcoding should be kept to a minimum and as generic as possible.

So, a first idea could be to create a list of generic "behaviors" for the cards (starting with creatures for example) that can be added as a keywords in the deck#.txt's. Those behaviors then are coded into the game's IA.

This is an example of possible "behaviors" for creatures.

Suicidal (SU): The creature is only used for attack, and will attack each turn if able (even if it get's killed - this may be used for example for cards like Erg Raiders or the like)
Attacker (AT): The creature is mainly used for attack, and will try to attacks each turn if able unless it seems its gonna be killed without dealing fatal damage itself.
Hybrid (HY): The creature will attack and/or defend depending on the situation (actual behavior for most of the cards)
Defender (DF): Card will probably stay untapped waiting to block enemies on the opponent's turn trying not to receive fatal damage.
Blocker (BL): Card will almost never attack and focus on blocking enemy attacks, trying not to get killed in the proccess or to "die killing".
Meatbag (MB): Card is disposable and will be used as a meat shield to block the most damaging enemy creatures no matter it gets killed in the proccess w/o dealing damage (useful for tokens, for example. Also, could be used so if some kind of "sacrifice" is needed, meatbags are selected first instead of a random card)
Skiller (SK<#>,<when>,<target>): Card will mostly focus on using skill <skill number/name> (in case the card has more than one skill). Will be kept out of harm if possible and won't attack or block unless it can get a "clean hit" or is absolutely necessary (example, as a last measure against a killing blow). More coding can be done to this behavior so the card uses the skill on myturn,enemyturn,beforeattack... or event to "help" the card to chose target for the skill)

So, in the DECK.TXT, right after the card name/id, you could add some behaviors so the AI "knows" how to use the card in that particular deck. The more behaviors coded, the more complex the deck AI.

For example, in a Suicide black deck, a Black Knight could have the (SU) and/or (AT) behaviour, while in other deck might have an (AT) or even (HY) behavior. If more than one behavior added, priority will be taken from left to right BUT will be consider for both behaviors (chances of 60/40, or even 70/30...)

- - - - - -

More advanced options might be the possibility to script "behavior combos", "behavior changes" or even depending on the situation. Scripting should be kept as easy as possible with simple keywords, So people w/o programming experience may script the deck easily.

Behavior combo example: an inflatable creature could have the (Skill <#><beforeattack>)+(AT) behavior so it first inflates with available mana and then is considered as an attacker instead of a skiller

Behavior change example: Erg Raiders could have (IfMyLife>10,(AT));(SU);(MB) so the raiders are mainly considered as ATtackers If AI's life is higher than 10, and will switch to SUicidal if AI's life drops too low, or can even be used as a meat shield or sacrificed if no other "suitable" card is available...
almosthumane
Posts: 66
Joined: Wed Mar 31, 2010 3:52 am

Re: A "Generic" I.A. improvement

Post by almosthumane »

That's a great idea!

To solve non creature card issues combine that with something like "autoAI=" key that would be only read by AI.

Could use keywords like mustplay, cantplay shouldplay, mustattack, shouldattack and the available trigger system.

A signaler like "Deckbasecard(level)", for things like (i.e.) Pestilence, howling mine or necropotence could be used, so that the AI knew that those cards are the main card of the opponent deck and prefer to destroy their effect as soon as possible, and the level (1,2,etc.) for trimming. Cards like Bad Moon could be "Deckbasecard(2)" while a Pestilence or Nevinrall's Disk would be "Deckbasecard(1)".

If this "autoAI" had higher priority that generic AI command logic I believe this could "patch" most AI problems.
Yorien
Posts: 33
Joined: Tue Feb 02, 2010 10:59 pm

Re: A "Generic" I.A. improvement

Post by Yorien »

Yorien says:

About the AutoAI and DeckBaseLevel, both features might help so the AI "works" as less as possible, but... why should people place bullseyes on their cards? Unless it's some kind of combo deck (and placing bullseyes/priorities should be something like "cheating" because the IA "knows" how to break the combo even before you start playing the match), I feel this idea is somewhat limited to a particular deck; one idea is to "help" the IA how to play it's deck, and a different one is to "whisper" the IA how to "deal" with the opponent's deck. And of course, unless you like to edit your deck properties every time you make a card change, IA won't know how to deal with "your" deck and will revert to base functionality.

Although those "deal with this one first" features may help a lot on computing, I'd prefer something more "generic" and useful for all decks and not hardcoded into a single one, like some kind of "threat meter".

From the match start, IA starts building a simple database with cards played (assigning an initial threat depending on how "powerful" the card is - taking into account power, thoughness, special abilities,... - ) by the opponent and adds/deducts "threat" depending on the actions taken by these cards. Once the IA has "means" (blocking, burying, destroying, whatever...) to deal with enemy cards, a check at the threat list can "tell" the IA whose cards should concentrate on, both taking into account "initial threat" and "current threat" (if an opponent just plays some nasty I-kill-you-on-sight 10/10, maybe "current threat" equals 0 because the card hasn't taken any action... but "initial threat" should skyrocket). After the match ends, threat table is cleared and ready for the next match.

Even better, Your idea could be placed by the IA onto another database (since most decks will remain static) so the IA "remembers" previous matches (something like Soccer League Stats: vsDeck 137, Wins=4, Loss=13, most threatening cards=#3654[112 threat], #97633[92 threat], #67541[79 threat], Less threatening cards= #1123[12 threat], #78656 [8 threat]), database fed by the "threat meter". This way the IA "learns" how to deal with returning opponents, both taking into account the "current match" threat and "lifetime matches". First time you play against an opponent you don't know his/her deck, but the more you play against, the more loy learn against that deck behaviour.

This way, IA adapts to the opponent's playstyle instead of taking a fixation with particular "coded" cards; two games against the same deck doesn't mean the other IA/playes will play exactly the same cards in the same order and make the same use of them than in the previous match.
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: A "Generic" I.A. improvement

Post by wololo »

Yorien wrote: Although those "deal with this one first" features may help a lot on computing, I'd prefer something more "generic" and useful for all decks and not hardcoded into a single one, like some kind of "threat meter".
The AI in Wagic already does that in a limited way. That's probably the only cool feature of the AI right now :)
It keeps track of the "danger" level of each of your cards and tries to focus on the most dangerous ones when blocking / casting spells.

Edit: see http://code.google.com/p/wagic/source/b ... IStats.cpp
Yorien
Posts: 33
Joined: Tue Feb 02, 2010 10:59 pm

Re: A "Generic" I.A. improvement

Post by Yorien »

Yorien says:
wololo wrote:
Yorien wrote: Although those "deal with this one first" features may help a lot on computing, I'd prefer something more "generic" and useful for all decks and not hardcoded into a single one, like some kind of "threat meter".
The AI in Wagic already does that in a limited way. That's probably the only cool feature of the AI right now :)
It keeps track of the "danger" level of each of your cards and tries to focus on the most dangerous ones when blocking / casting spells.

Edit: see http://code.google.com/p/wagic/source/b ... IStats.cpp
In my elven deck, I have the feeling that the AI deck has a fixation with the elven tokens I place onto play instead of getting rid of way more powerful cards. 99 out of 100 times, IA keeps targeting my non skilled 3/3 elf tokens, no matter there's a 56/56 trampling Heedless One and some token generators right at their side. Unless AI really believes that a token is far more dangerous than a trampling I-One-Shot-You-Next-Turn card, I don't get it.

But that's not the point, what I meant before is that the AI should "build" the danger level, and not rely on a deckXXX.txt "this card is more/less essential" coding since this should be the same as cheating.
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: A "Generic" I.A. improvement

Post by wololo »

Yorien wrote: In my elven deck, I have the feeling that the AI deck has a fixation with the elven tokens I place onto play instead of getting rid of way more powerful cards.
Yes, that's a flow in the mechanics: since you have lots of the same tokens, the AI "thinks" these tokens represent a major threat, because it counts only based on card id. For example if you attack with 5 "elf token", this will artificially multiply the threat represented by these tokens by 5.

That's a bug ;)
Yorien
Posts: 33
Joined: Tue Feb 02, 2010 10:59 pm

Re: A "Generic" I.A. improvement

Post by Yorien »

Yorien says:
wololo wrote:
Yorien wrote: In my elven deck, I have the feeling that the AI deck has a fixation with the elven tokens I place onto play instead of getting rid of way more powerful cards.
Yes, that's a flow in the mechanics: since you have lots of the same tokens, the AI "thinks" these tokens represent a major threat, because it counts only based on card id. For example if you attack with 5 "elf token", this will artificially multiply the threat represented by these tokens by 5.

That's a bug ;)
Well, I pretty much suck at programming myself and don't know how cards are handled in-game, but the "logical" idea should be to have each token "numbered" in some way, so the game distinguishes between many, equally named "token cards".

Is that not implemented already in some way? How does the game handle which "token card" has, for example, an enchantment or equipment applied?
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: A "Generic" I.A. improvement

Post by wololo »

The problem is that the stats are id based, to be able to reload them for a next game. Some improvement is needed ingame, it is probably needed to divide the threat by the number of cards with the same id, or something like that.
Yorien
Posts: 33
Joined: Tue Feb 02, 2010 10:59 pm

Re: A "Generic" I.A. improvement

Post by Yorien »

Yorien says:
wololo wrote:The problem is that the stats are id based, to be able to reload them for a next game. Some improvement is needed ingame, it is probably needed to divide the threat by the number of cards with the same id, or something like that.
Hmm, that's more of a quick workaround than a real fix. Will help a lot on assessing the correct danger made by the tokens, but can easily see many disadvantages on that idea. For example, you could "artificially" increase the danger level of all your tokens by equiping/enchanting one of them (for example, if you pop an unholy strength in one token, is seems that IA actually "thinks" ALL of them have been enchanted, thus skyrocketing their threat) and use them as a divert strike while the real threat comes from other cards.

I still "feel" the correct way to fix that should be to grant each card/token/wathever played in a particular game a unique "battle ID" and force the IA to play depending on that unique ID instead of the card #ID. Of course, this should mean a higher CPU/memory usage (and I don't know how limited the PSP is) because of having to maintain a bigger database (that "game DB" should be built "on the fly" - and cleaned/deleted after each match, of course - ).

This way, you play llanowar elves, with card #ID 3247 and in-game, the card is assigned battle ID #2 (3247[2], or whatever) - first battle ID being probably a forest... ;) . If next turn your play another Llanowar elves from the same expansion set (and thus, same card #ID), IA will assign them battle ID #4 (or #15, or #28, depending on when they're played) and "think" of them as 3247[4], or 3247[15], or 3247[28]. This way, if you pop an unholy strenght on your first Elves, IA "knows" you popped +2/+1 on 3247[1], and not in all your Llanowar elves. Same for lands, tokens... so the IA takes every played card as unique. this way you build danger on a "per unique card/token" basis instead of a "per card #ID".
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: A "Generic" I.A. improvement

Post by wololo »

I see your point but I don't think you see mine.
Next time you play against the AI, it has to know a bit about your deck. Last time you played a llanowar elve, you killed it with it, so it has to be careful of llanowar elves. That card happened to have enchantments on it, but that's already included in the stats.

The stats should take cards into account on an individual basis, but also on a "per id" basis, to use the information from previous battles.

Not sure I'm clear enough, but, if you played a "serra angel" and used it extensively, it doesn't matter if it was serra angel[4] or serra angel[2], what matters is that it was a Serra angel and it's somehow part of your combo, so next time you play it, the ai has to remember that serra angel is a danger. Not a particular instance of serra angel.

Because of that, I went with the simple way of treating only ids.
The real fix, as you mention, would be to work with both IDs of the card AND id of the instance.
if you attack with Serra Angel[1], the AI needs to increase the danger level of Serra Angel[1], but also (to a lesser extent) of all other Serra Angels.
If that particular Serra Angle has an enchantment on it, the enchantment also gets its danger level increased.

Cleaning the DB after each match loses LOTS of the efficiency of the system. one game is not enough for the AI to understand what is dangerous or not. That's my point.
Locked