AI Improvement

All about getting the AI less baka...
Saint
Posts: 434
Joined: Sat Jan 09, 2010 4:57 pm
Location: Netherlands

Re: AI Improvement

Post by Saint »

Well might just be a stupid point of view of mine but if you have a dual land, or a bird of paradise or whatever there should be a "request" phase in the AI coding were it checks all possible mana available, all combinations and all effects it could play, then weigh the power of those (wich is the hardest part of it) and make a choise based on wich would be best in the situation at hand. (sounds easy but really is hard to program, after all its Arteficial Intellect and its always hard to make a human like opponent because its hard to make a computer bluff, or play "cannon fodder" because its playing against a destruction deck etc.)
"The bird of the Hermes is my name, eating my wings to make me tame." - Ripley Scrowle, Elias Ashmole's Theatrum Chemicum Britannicum - 1652
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: AI Improvement

Post by wololo »

Right now what the AI does is the following: it computes 1 manapool based on the cards it has that can generate mana. This manapool is computed based on the "first ability" for each card. So for a dual land, it will only use the first version all the time.
Then, based on this single manapool, it looks for the cards it can play.
Probably what should be done is compute all possible manapools instead... (not necessarily easy)
Psyringe
Posts: 1163
Joined: Mon Aug 31, 2009 10:53 am

Re: AI Improvement

Post by Psyringe »

I think it might be better to do it the other way round - first rank the available cards in order of desirability, then see which is the most desirable card that can be played with the available mana sources.

Mana sources could be read into three lists: Simple (produces one type of mana and can't do anything else), Multiple (has at least one alternative usage, such as dual lands or Llanowar Elves), and Filter (costs mana to produce mana of different color). Also create one manapool which holds all mana that could possibly be produced by all mana sources (e.g. for Savannah, add {W} and {G} to this manapool).

Then write a function "canBePaid()" which takes the cost of the most desirable card as a parameter. See if this cost is covered by the virtual "total mana" pool - if not, return "false". If yes, see if the cost can be paid from "simple" sources, then check "multiple" sources (marking used sources so that they don't get used twice). Then check "Filter" sources, and if using a filter can satisfy the cost, see whether the cost of the filter can be paid by calling canBePaid() with the filter's cost. (Recursion is inefficient, but I it would be just 1 level of recursion in the vast majority of cases).

It still sounds pretty complex to code, but I think it would lead to good AI decisions, and would make non-monocolor AI decks much more viable (thereby increasing the variety of decks to play against). :)
TioSolid
Posts: 24
Joined: Tue Aug 25, 2009 11:45 pm

Outnumbered creature AI Bug

Post by TioSolid »

I was just playing a small duel here and saw that the AI usually avoid attacking if you outnumber their creatures on the play field.

It happened like this: AI casted one legends card (cant remember the name now, sorry) that allow only flying creatures to attack. Its an enchantment. AI had like 3 or 4 flying creatures on the field, but as soon as my token deck began spawning tokens like crazy the AI sudenlly stopped attacking, EVEN when I was not able to block (since I had only non-flying creatures) and to attack either (because of the enchantment). The AI could have won the duel easily if it kept attacking me but it stopped as soon as I had like twice as many creatures on the field.

You can recreate this situation easily if you play against the griphin deck and can cast a lot of creatures at once.
Psyringe
Posts: 1163
Joined: Mon Aug 31, 2009 10:53 am

Re: Outnumbered creature AI Bug

Post by Psyringe »

I was just playing a small duel here and saw that the AI usually avoid attacking if you outnumber their creatures on the play field.

It happened like this: AI casted one legends card (cant remember the name now, sorry) that allow only flying creatures to attack. Its an enchantment. AI had like 3 or 4 flying creatures on the field, but as soon as my token deck began spawning tokens like crazy the AI sudenlly stopped attacking, EVEN when I was not able to block (since I had only non-flying creatures) and to attack either (because of the enchantment). The AI could have won the duel easily if it kept attacking me but it stopped as soon as I had like twice as many creatures on the field.

You can recreate this situation easily if you play against the griphin deck and can cast a lot of creatures at once.
Yes, that's a well-known shortcoming of the AI. It doesn't take evasion abilities into account when it decides whether or not to attack.
SlickDragon
Posts: 3
Joined: Wed Mar 03, 2010 7:49 am

Re: AI Improvement

Post by SlickDragon »

I am not sure which thread to post this in since im new to the forums, but i think this is a fitting place.

When the Ai plays Inkfathom Infiltrator (2/1 unblockable, cant block) it wont attack with it since i have beefy creatures. It would be nice if it would be coded to automatically attack every turn, since it wont be blocking and has little to fear while attacking. The Ai almost always just lets it sit around doing nothing, even-though its a potential win condition. I am not sure how difficult it would be to code it to attack every turn, but cards like Bloodrock Cyclops (3/3 attacks each turn if able) have no problem attacking every turn so it shouldn't be impossible.
Yorien
Posts: 33
Joined: Tue Feb 02, 2010 10:59 pm

Re: AI Improvement

Post by Yorien »

Yorien says:

A simple A.I. idea without many processing requirements:

Create some kind of aggro/usefulness table in adition of the current IA. The computer may not "understand" the card, but can take into account card skills and card values and consider the highest threats. Not only for creatures, but can be used for ALL cards. Maybe instead of a table that may grow too large, every card/token played might have two additional numeric values, one for aggro and other for usefulness, so the data is embedded on the card.

Before the first turn all cards get an "initial" aggro/usefulness value (they're checked upon the list and a first Aggro/usefulness is written), and game starts

Let's see an idea:

SPECIFIC TO CREATURES
- Per every creature's power point: +1
- Per every creature's thoughness point: +1
- Creature has Regeneration: +5 as long as there's mana available, and creature has a greater probability to be used as a defender
- Creature has Trample: +1 (extra) per power point. (Trample also requires additional programming so com "understands" how to block Trample, currently does not)
- Creature has Protection from [color]: +1 per color
- First strike: +2 unless oponent has a card with first strike and enemy card's power >= card thoughness)
- Creature has Flying: +3
- Creature has Fear: +3
- Creature has Shadow: +4
- Creature has no special abilities: -1
- Creature dealt damage this turn: +1 per damage dealt
- Creature is currently unblockable (there's nothing actually in play that can currently block the creature - this may require additional checks): +5 and the card has a greater probability to be selected as an attacker
- Creature can "score" a killing blow(i.e, creatures power >= your life total): : +50 (this helps com choosing correctly whose creatures to block first, then after those are taken care of other blockers may be declared)
- Creature is a token: -2, and the token has a greater probability to be used as a meat shield/sacrificed
- Creature cannot attack: -1 and creature has a greater probability to be used as a defender
- Creature cannot block: -1 and the card has a greater probability to be selected as an attacker
-
-
-


SPECIFIC FOR XXXXXXXX CARD TYPE

-
-
-
-

GENERIC FOR ALL CARD TYPES:
- Card is a "generator" different from mana: +5 (The Hive, Keer Keep, Immaculate magistrate...), + 2 per "generation".
- Card is a legend: +3
- Card grants power/thoughness bonuses/penalties to creatures: +1 per card affected (bad moon), additional +1 per every bonus damage/thoughness granted or inflicted (Immaculate Magistrate, creatures with Wither)
- Card heals damage: +1 per point of damage healed (ex. Samite healer, Wellwisher, amulet of Kroog)
- Card generates mana: +1 per every type of mana it can create. "colorless" is considered it's own type of mana (ex. birds of paradise) and +1 per every point of mana created (ex. Gaea's Cradle, Priestess of titania)
- has a "generic" ability not directly harmful: +X (depending on the ability. A library check/arrange may be worth 1 point, a card draw may be worth 2 or 3...), and an additional +1 every time the card uses that ability
- Card has a directly harmful ability: +3
- Card is a land: +5, and only the following mods can affect it: "legend", "has a harmful ability", "has a generic ability not directly harmful" and "generates mana" (the latest one might be used so for example dual lands and/or, special lands get more aggro than a basic swamp)
- Card is disabled (this may be difficult to program - additional checkbox in the card, maybe?- but for example, if you play Pacifism, or Paralize on a card, computer should "know" that the card is disabled so no additional disablers are placed on it (unles the card get's enabled - for example by paying paralizes untap cost)
-
-

... and so on...

Every time a card effect takes place, the game modifies that card's aggro/usefulness value for that card. This way the computer at least has a numeric value idea of the biggest threats, without too many processing.

A play idea...

Turn 1:

You: play a forest: [+5] land, [+1] can generate green mana. Forest #1 total aggro: [6]
You: tap forest: [+1] green mana generated, Forest #1 total aggro: [7]
You: play llanowar elves: [+1] power, [+1] thoughness, [+1] can generate green mana. Llanowar elves total aggro: [3]
EOT

Com: plays a swamp: [+5] land, [+1] can generate black mana. Swamp #1 total usefulness: [6]
Com: taps swamp: [+1] black mana generated, swamp #1 total aggro: [7]
Com: Plays Dark Ritual. [+1] [+1] can generate black mana, [+3] three points of black mana generated. Dark Ritual total usefulness [4] (although DR it's sent to the graveyard, in a deck able to recover cards from there the usefulness value may be used to "recover" the most useful card. this can be tweaked so for example, a creature that dealt damage but utterly got killed is "cleaned" from it and gets a more "logical" value, etc...)
Com: Plays Hypnotic Specter: [+2] power [+2] thoughness, [+3] flying, [+5] currently unblockable (because of flying), [+3] Has a harmful ability. Hypnotic Specter total usefulness: [15] (take note, computer had three mana, and decided to put into play the most "useful" card it currently had on it's hand, instad of playing, for example, Erg Raiders [initial usefulness: 5]. This adds to the "IA".
EOT

Turn 2:

You: Play Gaea's Cradle. [+5] land, [+3] legend, [+1] can generate green mana. Gaea's Cradle total aggro: [9]
You: tap forest #1: [+1] green mana generated. Forest #1 total aggro: [8]
You: play Birds of Paradise: [+0] power, [+1] thoughness, [+3]flying. [+5] can create mana from 5 colors. Bird's total aggro: [9]
-> COM -> [-3] Hypnotic Spectre loses "Currently Unblockable". HS current usefulness: [12]
You: tap Gaea's Cradle. [+2] two green mana generated (one per creature controlled) Gaea's Cradle total aggro: [11].(Gaea's Cradle clearly becomes a bigger threat than the basic forest)
You: play ...
_____________________________________________________________________________________________________

This way, computer can have a numeric idea of the cards being played, and a whole new A.I. system may be implemented. com will protect the most useful cards it has, and concentrate efforts on opponents most threatening cards, destroy the most powerful lands, cast Terror on the highest aggro creature, destroy that stupid tome that is giving the oponent's additional cards... . A bit of randomness can be given so the biggest threat is not always chosen...

Well, it's just an idea.
John Rohan
Posts: 37
Joined: Sat Jul 18, 2009 2:08 am
Contact:

AI makes poor choices

Post by John Rohan »

I have a Putrid Imp (1/1 creature) and a Hellkite Overlord (8/8) in play. And the AI casts his Swords to Plowshares on...the Putrid Imp!!

I see this happen quite a bit.

I realize the AI is limited, but it seems like when using a removal spell the AI should at least choose the highest cc creature. Or the one with the highest power - then at least it would be correct 90% of the time.

BTW, I'm not trying to sound like an ingrate - this is, hands down, the best PSP game I've ever seen!

[ABRA : Merged]
wololo
Site Admin
Posts: 3728
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: AI makes poor choices

Post by wololo »

I have a Putrid Imp (1/1 creature) and a Hellkite Overlord (8/8) in play. And the AI casts his Swords to Plowshares on...the Putrid Imp!!

I see this happen quite a bit.

I realize the AI is limited, but it seems like when using a removal spell the AI should at least choose the highest cc creature. Or the one with the highest power - then at least it would be correct 90% of the time.

BTW, I'm not trying to sound like an ingrate - this is, hands down, the best PSP game I've ever seen!
The AI makes its choices based on the history of your deck + a pinch of random.
If it cast the spell on your imp, it can be either some random luck (I know this happens too often, but it's also because of this randomness that you sometimes think "wow, that was clever") , OR historically your imp has done more damage to the AI than your hellkite overlord.
rawsugar
Posts: 228
Joined: Wed Aug 11, 2010 11:05 am

Re: AI Improvement

Post by rawsugar »

would be nice to have some way to signify whether an effect is beneficial or not. Fx Ai (in my version, im lagging behind, still at 12.1) will cast snap at its own creatures and sadistic glee at enemies (and beacon of immortality on enemy). not to mention creature abilities such as destroy effects that the AI will often use on its own. Just a letter next to the ability when the Ai confuses its use.
If it ever becomes possible to program individual decks numbers to signify the casting order would be good (ie lowest should be cast first and higher numbers later).
Oh and as abrasax i think suggested; to make creatures not attack/bloack (at all, or rarely; best ofc would be rules for exceptions, fx no enemy creatures=attacks, or attacks with 6+ other creatures and such) would be GREAT. The AI is rather wasteful of lords and generators/ability users.
Locked