Arcomage - AI

The role-playing games (I-X) that started it all and the various spin-offs (including Dark Messiah).
User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Arcomage - AI

Unread postby GreatEmerald » 02 Aug 2011, 11:32

Right now I'm in the middle of rewriting Arcomage Clone code and one of the things I'm working on right now is AI. Naturally, the AI will perform better if I knew what strategies other people use.

For now, the deck there is the original Arcomage cards, but anyone will be able to write their own cards later and it will also support everything MArcomage has, thus there will be two types of AI - general and specific. General AI doesn't deal with the specifics of cards, but goes by the trend - for example, favouring green cards when the enemy's wall is down. Specific AI will be individual for every card and people will be able to define it when they create their own cards.

Firstly I'm going to focus on general AI. So, what general strategy do you use when playing the game? So far, I have this in mind:
  • When your tower is 75% or more built, favour blue cards.
  • When your tower is 25% or less built, favour blue cards.
  • When enemy tower is 75% or more built, or 25% or less built, and the wall is 25% or less built, favour green cards.
  • When enemy wall is 5% or less, favour green cards.
  • When your wall is less than 25%, favour red cards.
  • When your wall is at 75% or more, do not favour red cards.
  • When your resources are at 75% or more of the resource goal, favour cheap cards or discarding.
Anything else that comes to mind? I thought about favouring cards that counteract the resource that the enemy has (like favouring red cards if enemy has a lot of recruits), but the enemy might be going for a resource victory or they might not have any green cards in hand.

And I'm going to make specific AI one card at a time. The first card is Brick Shortage, 0 cost red card, description reads "All players lose 8 bricks". Those are my thoughts on it so far:
  • When you have lower than 8 bricks, favour this card.
  • When enemy has lower than 8 bricks, do not favour this card.
  • When enemy's bricks are at 75% or more needed to win, favour this card.
  • When you have more quarry than the enemy, favour this card, if enemy has more than you - do not favour this card.
  • In all other cases, discarding it is as good as playing the card.
Any other thoughts?

Spin
Pixie
Pixie
Posts: 131
Joined: 18 Aug 2010

Unread postby Spin » 02 Aug 2011, 12:28

Great rules so far, they're fairly general but all very good.

You might want to add secondary 'labels' to cards e.g. Tower Damage Cards, Wall Damage cards, Wall cards, Tower Cards, Resource Cards, Production (quarry, magic, dungeon) cards + then make a more complex AI system. It will enhance the AI a lot i would think, imagine when you have 5 tower left and the enemy keeps increasing his recruits or dungeon or something stupid instead of playing a 5 damage card (unless of course you've already rated cards by preferred order of playing).

I think Specific cards for the resource cards is a brilliant idea, if you only have 1 game mode (i.e starting resources and tower doesn't change with the game type) you could be really specific and end up writing a super AI code that would play like a human.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 02 Aug 2011, 13:06

I thought about that and it might indeed be necessary, since MArcomage already has a system that relies on that. But for the original Arcomage cards, I think I can do with putting things into the specific AI, for example, have all damaging cards have the highest priority when the victory can be achieved by playing them. That will make it rather redundant code on most green cards, but that's the easiest way, since making tags like "6 damage" would be quite problematic, knowing how many different amounts of damage different cards can deal. That would mean making lots of different tags ending up in a lot of code that does basically the same thing, just for different tags. Or, if there was a variable "Damage", it would be useless for cards that don't deal damage to begin with. But, of course, tagging cards like Rock Thrower, that is a red card yet deals damage, would indeed be very useful.

The AI uses both specific and general rules all the time. That is, first it looks at the specific rules and gets the rating; then that rating is modified according to general rules. Since resource, tower, wall, facility etc. levels are configurable and will also have the ability to be randomised in the future, I have to keep most values relative.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 03 Aug 2011, 09:24

All right, so now I implemented all those rules (still open to suggestions if anyone has them!). I'm looking into other red cards now. Here are my thoughts:

Lucky Cache
+2 Bricks +2 Gems Play again

and

Friendly Terrain
+1 Wall Play again
  • Play it instantly under any circumstances, except if you can play something else to get an instant win.
Miners
+1 Quarry
  • When quarry is less than 10, prefer this card.
  • When bricks are low, prefer this card.
  • When bricks or quarry are high, do not prefer this card.
Mother Lode
If quarry<enemy quarry, +2 quarry Else, +1 quarry
  • Repeat rules for Miners.
  • When quarry is lower than enemy quarry, prefer this card.
Dwarven Miners
+4 Wall +1 Quarry
  • Repeat rules for Miners.
  • When wall is low, prefer this card.
  • When wall is high, do not prefer this card.
Any thoughts on these?

User avatar
tolich
Spectre
Spectre
Posts: 748
Joined: 10 Jan 2009
Location: Minsk, Belarus

Unread postby tolich » 03 Aug 2011, 10:28

At least some AI stupidity must be changed, i.e., prevent AI player from completely destroying own tower (if this doesn't destroy enemy's one) or from raising enemy's tower when it's a point below victory condition.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 03 Aug 2011, 15:26

Don't worry, those will be definitely taken care of. But thanks for reminding me about those particular ones.

Now when I think about it, those general rules, with the exception of the last one, are rather redundant. That's because if I have, say, Orc, that does nothing but deal damage, it would have no specific AI code, since the general code would have it handled. And that's not good, since you need to see what the AI is capable of at a glance when reading through the Lua code. Plus, those general rules are pretty specific for being general rules. So right now only the last one stays. But it might be good to implement specific functions to aid AI, like a function for cards that build walls, since that code gets quite lengthy and copying it is prone to errors...

Hm, I have to say that assigning values to those is difficult. When if statements pile, they can go over 1.0 easily, or below 0.0. I guess the only way to do it right is to test it and see where the priorities are wrong.

User avatar
Macros the Black
Druid
Druid
Posts: 897
Joined: 21 May 2008
Location: Elemental Plane of Air

Unread postby Macros the Black » 09 Aug 2011, 20:40

Well, this is how I play Arcomage, in order of importance:

1. Cards that grant victory immediately (this can be a tower card, a damage card or a resource card).
2. "Free" cards, like Lucky Cache.
3. Cards that prevent the enemy from winning in his turn.
* 4. Cards that will make you win in a few turns.
5. Cards that grant Magic if Magic is under a certain treshold (the treshold should probably be the highest possible cost of a blue card).
6. Cards that grant Zoo if Zoo is under a certain treshold.
7. Cards that grant Quarry if Quarry is under a certain treshold.
8. Cards that build tower.
9. Cards that deal damage if you can damage the enemy's tower with them.
10. Cards that build wall.

* this is the big one. I'm not sure AI can be coded to make a plan for the next few turns depending on all the cards in his hand. Well actually, you probably CAN code it like that but it would be too much work and the AI might be too slow :/
Last edited by Macros the Black on 09 Aug 2011, 20:56, edited 1 time in total.
You'd think Darkmoor was a ghost town, but instead there's plenty of life among the dead.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 09 Aug 2011, 20:52

Yeap, that's pretty much how I made it work right now. Except for the bias towards Magic... Perhaps I should make AI personalities, where some would prefer building tower, some would prefer attacking you and some would prefer going for a resource victory. But that will be for later.

Right now I have completed the AI for all cards, and it was very easy, actually. I simply made preset functions (like AIDamageEnemy(TheAmountOfDamageTheCardDeals)) that rate the card for me. Now all I need is to compile and link the static library and create the CLI frontend for it, then test it.

User avatar
Macros the Black
Druid
Druid
Posts: 897
Joined: 21 May 2008
Location: Elemental Plane of Air

Unread postby Macros the Black » 09 Aug 2011, 21:00

Sorry, I was still editing my post. Well, what I noticed about Arcomage (well, the basic game at least) is that green cards usually don't deal as much damage as red and blue can build up. Sometimes one red card can keep someone playing damage busy for 3 turns. Hence, a tower victory is more likely than destroying your opponent's tower.

AI personalities would be interesting though.
You'd think Darkmoor was a ghost town, but instead there's plenty of life among the dead.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 09 Aug 2011, 22:01

Given that you use the term "Zoo", I assume you're talking about MM7 Arcomage deck? In that case, yes, building the tower is definitely a better strategy. However, bonus cards introduced in MM8 and the standalone Arcomage game level the playing field - there is Lightning Shard that hits the enemy tower if your tower is higher than the enemy wall (which it is most of the time), there is Warlord that deals raw 13 damage, there is Pegasus Lancer that hits the enemy tower directly for massive damage and finally there is Shift that switches your and your opponent's walls. So attack cards are no longer that useless.

And yes, making the AI think in advance is a little too difficult. I can make it recognise two cards to play in a sequence a la MArcomage, but other than that, not much else. The result would be pretty negligible compared to the time it would take to compute it and implement the code in the first place.

User avatar
Macros the Black
Druid
Druid
Posts: 897
Joined: 21 May 2008
Location: Elemental Plane of Air

Unread postby Macros the Black » 09 Aug 2011, 22:13

Ah, well I'm not as familiar with MM8, but it's great that they fixed the imbalance then. In that case, AI personalities would be really cool :D
You'd think Darkmoor was a ghost town, but instead there's plenty of life among the dead.

User avatar
GrayFace
Round Table Hero
Round Table Hero
Posts: 1660
Joined: 29 Nov 2005

Re: Arcomage - AI

Unread postby GrayFace » 11 Aug 2011, 14:59

I think AI should be able to estimate how good the situation is and express it as a number. When choosing a card it should emulate moves with each card and find the best move. The difference in situation after and before card's use would be card's rating. It should also evaluate dropping a card and prefer discarding cards with negative rating.
Some specific rules: Use free cards with "Play again" first. Increase 'rating' of cards that have "Play again". Etc.
My patches: MM6 MM7 MM8. MMExtension. Tools. Also, I love Knytt Stories and Knytt Underground. I'm also known as sergroj.

User avatar
tolich
Spectre
Spectre
Posts: 748
Joined: 10 Jan 2009
Location: Minsk, Belarus

Re: Arcomage - AI

Unread postby tolich » 12 Aug 2011, 05:37

GrayFace wrote:Some specific rules: Use free cards with "Play again" first.
It's highly depends of AI current resources: IIRC there's only one 'Play Again' card that doesn't consume resources (a little amount though) but produces instead. If raising tower by 1 prevents you from raising it by 15, there's wrong to do it.

User avatar
GrayFace
Round Table Hero
Round Table Hero
Posts: 1660
Joined: 29 Nov 2005

Re: Arcomage - AI

Unread postby GrayFace » 15 Aug 2011, 14:14

tolich wrote:If raising tower by 1 prevents you from raising it by 15, there's wrong to do it.
Accounting for that would be a task for an AI that would emulate more than 1 move. In Arcomage it's relatively easy to do so, because you can assume the player doesn't do anything and just simulate the next AI move. Still, it may cause additional problems.
My patches: MM6 MM7 MM8. MMExtension. Tools. Also, I love Knytt Stories and Knytt Underground. I'm also known as sergroj.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 19 Aug 2011, 07:53

Simulating is not a very good way to do that, considering that you get completely random cards and you can have an infinite amount of cards in your deck. That would grind the game to a halt and produce no viable results.

User avatar
UndeadHalfOrc
Cyber Zombie
Cyber Zombie
Posts: 1362
Joined: 13 Mar 2007

Unread postby UndeadHalfOrc » 25 Sep 2011, 16:22

Anybody else love getting the Spizzer card? (assuming the game didn't start with a wall of 50)

It's hard to use, but so satisfying when you finally finish destroying the opponent's wall and you get to play that card that you held for so long.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 25 Sep 2011, 17:01

Indeed, same goes for cards like Berserker. You can have a lot of offensive cards in hand, plenty of recruits and a single Shift card, then wait for the enemy to grind down your wall and go on an offensive :D

Almer
Leprechaun
Leprechaun
Posts: 3
Joined: 26 Mar 2015

ressurect:)

Unread postby Almer » 26 Mar 2015, 19:51

Hi guys,

i know it is quite lately, but i came to same situation as described in original post. Can someone give me some usefull tips on this?

How to build that AI? And maybe even some "Game theory" so i can do also some science?

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 30 Mar 2015, 00:31

Well, right now my AI code is here:
https://github.com/GreatEmerald/libarco ... rdPool.lua (AIFunction parts, that call the functions below:)
https://github.com/GreatEmerald/libarco ... dPools.lua

The way it works is that the AI executes the AI functions associated with each card, and the functions return a "desirability" rating. More than zero is good, less than zero is damaging, so if the rating is below zero it's better to discard than play.

What it could do better is have some long-term strategies of combos defined. Something like determining that playing one card is likely to increase the rating of another card; perhaps by tracking how the average desirability of cards in hand would change if each card is played.

Almer
Leprechaun
Leprechaun
Posts: 3
Joined: 26 Mar 2015

Unread postby Almer » 01 Apr 2015, 14:59

Thx GreatEmerald for reply..I was not hoping for reply by posting in "death-thread".

As i understand it right, ur using some kind of alpha-beta minimax algorithm? ( choosing card according to its "value"). Straigth-forward solution but pretty fragile...based on "good" Card-Evaluation function.

Am i right? How did you construct this function (made base evaluation)? And how did you get rid of non-direct effect cards (like wall swap, discard a card + discard another one etc.)?

I am actually thinking about some strategy-based computing (based on some math). Acromage is Bayesian game (or zero-score game with partial information). More http://en.wikipedia.org/wiki/Bayesian_game

Also - what can be done is some sort of "game ending mechanism". I mean like in chess - one card ending, two card endings (that can be exactly computed in limited time - like at chess).

And for the beginning some Bayesian strategy (like remove 8 stones have different effect when he has 80 or 10).

What do you think? have you considered something like that?


Return to “Might and Magic”

Who is online

Users browsing this forum: Google [Bot] and 28 guests