AI Improvement

All about getting the AI less baka...
Locked
abrasax
Posts: 976
Joined: Wed Oct 15, 2008 7:46 am
Location: Switzerland

AI Improvement

Post by abrasax »

Hi,

As wololo suggested here are some list of typical errors made by the AI, in addition some specific card handling could be programmed (maybe some tip on how to program AI would help other programmers)

Here is a first brainstorming...

AI – Handling errors
- Cast Damage<toughness on Creature (e.g Lightning Bolt on creature 3/4) ? Sometime will not cast damage on player even if that will allow the AI to win the game.
- Does not take First strike in consideration when blocking (e.g block with two 1/1 creature a creature with 1/2 and first strike resulting in not being able to kill the creature)
- Cast Fear on creature with defender.
- Attack with creature (0/1 – e.g. will’o’wisp)
- Creature with unblockable abilities (e.g unblockable, landwalk, fear ) ?do not attack each turn if possible (more complex creature have unblockable and cannotblock should attack each turn), some creature like Serra are as well not optimize, the AI does not understand the strategic advantage of the Serra if no creature with flying are in opponent hand…
- AI will attack with creature with Lord ability ? this one is complex, but some creature should not attack especially the one that are lord to other excluding themselves like lord of Atlantis. Normal player will tend to try to destroy the lord first.

The AI is not able to use activated ability correctly, the following should be considered:
- Token creator : should not attack and at the second main phase if enough mana then produce token… (e.g imperious perfect)
- Mana producer -> simple mana producer like elf that only produce one type of mana should be considered by the AI as mana source…
- Some specific card should be coded to be used by the AI (e.g assassin, should not attack, and should try to destroy creature attacking and tapped with highest power)

Grüssi

Abra
We need your Help !!!
New to wagic ? Be sure to check the following :

Bug report: Bug reporting
Help us: Add cards & Compiling.
Customize: Themes FAQ, All images thread, Abra's Mediafire folder
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: AI Improvment.

Post by wololo »

Thanks abrasax, this thread is a good idea.
I have no tip to give regarding AI programming. The only good way to do AI programming in such a game is to use a minmax algorithm, which, given the possibilities space of MTG and the low CPU power of the PSP is probably impossible. So if you want info on how to program good AIs, look up for minmax, or alpha beta pruning in Wikipedia.

Regarding the AI in Wagic, everything lies in AIPlayer.cpp, and is mostly a dirty pile of hacks. The best way for us to improve it right now is to keep hacking into it with very specific changes such as the ones you suggested. You have to understand though, that the more specific you get, the more stupid mistakes you can do.
sometimes the current AI plays remarkably well. That's because there's lot of random in there. The more specific rules you add, the less random there is, the easiest it can become for a human player to find ways to trick the AI.

I would love this thread to be a list of things you guys usually do to make sure you always win, or at least, to make the AI do stupid mistakes that even the nobbiest noob wouldn't do

Edit: I also want to create a bunch of AI keywords so that deck creators can tweak the AI a little bit.
superhiro
Posts: 151
Joined: Thu Nov 13, 2008 1:28 pm

Re: AI Improvment.

Post by superhiro »

I notice a lot of problems, but don't have them all in my mind right now, so I'll just note what I have in mind right now.

The Ai really should be able to use nonbasic lands (simple ones such as duals or the Alara shard lands). Because that is just essential and really should not be so difficult to code.

It should also be able to use activated abilities, especially pump and sacrifice abilities.

Furthermore, it has to be able to use Armageddon or Wrath of God like effects. It makes no sense to Armageddon when your opponent is the only one with creatures in play and cards in hand. And there is no sense in Wrath of God when you're ahead in the damage race. I would think this could be handled with formulas, that the chance, that the AI casts the destroy all spell increases if he is behind on resources.
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: AI Improvment.

Post by wololo »

superhiro wrote:[...] It makes no sense[...]
Whatever suggestions you come up with, always remember that there is no such thing as "making sense" for a computer.


It is very easy to come up with a rule for one card. Just remember that we have to deal with more than 2000 of them.
And imagine that there is an enchantment in play that says "whenever a player casts a white spell, he gets 20 damage"? Does your rule change? Probably... so you have to be EXTREMELY careful when you say that something makes sense or doesn't... because it doesn't depend on the card alone, but on the whole environment.

My point is: whatever clever rule you come up with, it will make no sense in some specific situations. So the AI will always look crappy one way or another. Knowing that, the rules controlling the AI should be as simple and generic as possible, otherwise we're wasting time.

"Wrath of god" belongs to the class of "destroy all". If you can give me a rule that works for ALL "destroy all" cards/abilities, then we can implement it. Pseudo-code allowed, it doesn't have to be C++ to convince me, but things such as "ahead in the damage race" need to be clarified (so that the machine can understand them). With these "destroy all" effects, we easily have access to the list of cards that will be "impacted" by the effect, so you can use that in your rule.

Here's the current algorithm:
myNbCards = count the number of cards in my play that will be impacted by the "destroy all"
opponentNbCards = count the number of cards in my opponent's play that will be impacted
myCardsPower = count the total power of the creatures in my play that will be impacted by the card
opponentCardsPower= count the total power of the creatures in opponent's play that will be impacted by the card
if (myNbCards < opponentNbCards OR myCardsPower < opponentCardsPower) then high percentage of chance to cast the spell, otherwise low percentage

http://code.google.com/p/wagic/source/b ... ty.cpp#518

I am (genuinely) waiting for something better

Edit: also look for the discussions on the same subject on MTGForge's blog, they are very interesting
superhiro
Posts: 151
Joined: Thu Nov 13, 2008 1:28 pm

Re: AI Improvment.

Post by superhiro »

I will test some more and then try to come up with something better... I'm not promising anything, though :)
Mirkling
Posts: 6
Joined: Fri Jun 19, 2009 7:35 am

Re: AI Improvment.

Post by Mirkling »

wololo wrote: "Wrath of god" belongs to the class of "destroy all". If you can give me a rule that works for ALL "destroy all" cards/abilities, then we can implement it. Pseudo-code allowed, it doesn't have to be C++ to convince me, but things such as "ahead in the damage race" need to be clarified (so that the machine can understand them). With these "destroy all" effects, we easily have access to the list of cards that will be "impacted" by the effect, so you can use that in your rule.

Here's the current algorithm:
myNbCards = count the number of cards in my play that will be impacted by the "destroy all"
opponentNbCards = count the number of cards in my opponent's play that will be impacted
myCardsPower = count the total power of the creatures in my play that will be impacted by the card
opponentCardsPower= count the total power of the creatures in opponent's play that will be impacted by the card
if (myNbCards < opponentNbCards OR myCardsPower < opponentCardsPower) then high percentage of chance to cast the spell, otherwise low percentage

I am (genuinely) waiting for something better
Ok, i don't know how hard this could be (not a C++ode lover) but you could break down the class of "destroy all" in several sub classes like

Destroy all -lands -creatures -enchantments -artifacts -cards in hand (i.e: decree of anihilation) -planeswalker(still no need for pw here but...)

and make some value type decitions involving life totals and other resources, for example:

-Start making a scale of what's more important/has more impact in game (imo creatures are the most important as they are an evident threat to life totals, then come lands which enable, cards in hand that come after that, enchantments and artifacts are the, generally least important as they usually need of creatures to be a real threat, as a general "less imperfect than the actual but also imperfect" rule).

-Getting aditional parameters for destroying:

All creatures:
-you start with a, let's say 5% chances of "stupidly" playing it
-add to your "AI's creature counter" auras you control (as a pacifism would "take down" an enemy creat, and a blanchwood armor would be an investment on a creat)
-add to "opponent's creature counter" auras player controls (same logic as before)
-now same check u are doing now should add a 40% (since it's the most significant part, and AI should have the right to a hunch from time to time, this should be enough to have it in hand + play it)
-being AI life total below 10 should add 10%
-being AI life total less than opponent 5%
-having AI more cards in hand than opponent 5%
(all of this i guess, taking into account not playing the same card more than 4 times, and that the card is in the deck)

All lands:
-you start with a, let's say 5% of "stupidly" playing it
-same as u do now should add a 30% (just count permanents here i guess)
-having more and bigger creats in play 15%
-having more cards in hand than opponent 10%
-having another mana source (llanowar elves? mindstone? ignore this if not implemented yet) 10%

All cards in hand, artifacts and enchantments... what's applied now should be enough (count ur cards affected, his cards affected and strike or not based on that)

There are cards like decree of anihilation, obliterate, upheaval (if evacuation is ment to follow the same rules as WoG) and jokulhaups that destroy many things at the time, there a formula could be done, such as:

destroy all effect probability: 1/(creatures*5 + lands*4 + cards*3 + enchantments*2 + artifacts*2) obviously, for a spell like obliterate, enchantments and cards in hand shouldn't be taken into account (just put a 0 in the ecuation) and you would get a somehow accurate evaluation of the board position that would help you decide.

This could be modiffied so as to get a more accurate pyroclasm, or if some day implemented, pernicious deed, or devastating dreams

Hope this helps a bit at least...
Mirkling
Posts: 6
Joined: Fri Jun 19, 2009 7:35 am

Re: AI Improvment.

Post by Mirkling »

after being playing for a while, i can say AI doesn't take into account how big looming shade can get, so i guess it only considers present states... i guess some function looking for "cardname 'gets +'" in the ability of creats could be made, so as to see how big a creat can get, based on available resources...
zhykon
Posts: 4
Joined: Mon Jun 15, 2009 8:45 am

Re: AI Improvment.

Post by zhykon »

Untap creature enchanted with paralyze cause they have sufficient mana and also on that turn they don't summon or put anything in play leaving their mana source useless for that turn or I don't have any creature in play.
genismaxwell
Posts: 3
Joined: Mon Jul 27, 2009 3:33 am

Re: AI Improvment.

Post by genismaxwell »

AI dont know to use NON-BASIC LAND as mana souce, it playing it as a "ability", so at the end of turn it tap a duel-land for "ability" to get 1 damage and a damage of mana burn...= =
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: AI Improvment.

Post by wololo »

genismaxwell wrote:AI dont know to use NON-BASIC LAND as mana souce, it playing it as a "ability", so at the end of turn it tap a duel-land for "ability" to get 1 damage and a damage of mana burn...= =
True. I don't recall any AI deck having a non basic land though...
Locked