How to make an AI with varying intelligence

rhialto

Emperor
Joined
Sep 18, 2003
Messages
1,163
A long time ago I was semi-involved with the Ultima 6 Online (U6O) project. A friend of mine was making it, and as a fellow tech-head we often discussed aspects of it. One big issue was how to make the monsters act, and how to make vampires act noticeably more intelligent that rats. I recall we came to the following options:

zero - monster acts randomly, completely ignoring the presence of players, only attacking if it bumps into it.

low - monster attacks a random party member, randomised each turn.

medium - monster attacks a random player in party, and then always attacks same target following turn.

high - monster attacks best target in terms of threat potential (damage you can do / hit points left).

Once these behaviours were defined, you could then say a monster has a set percentage of acting according to each level of intelligence each turn. So a vampire might have a 90% of acting high each turn, and a 10% of acting medium. Rats might be 75% low and 25% zero.

Obviously this cannot e directly copied over into civ, as the format is completely different. But by defining several possible AI behaviours for the same act, and then setting chances of acting according to each AI pattern, you can give widely iffering AI personalities. The different personalities need not even be on a clever/stupid axis as in this example, but could be on a builder-expander-whatever multiple axes.

Thoughts?
 
I definitely think the most important thing to come out of this is "threat potential". As a player, I definitely use this in guiding my decisions about war and peace. I feel as though the AI is much more "emotional" or even "random" about who it declares war on.
 
I agree with how I understand dh_epic's statement:
The first step in creating a at least to a certain extent meaningful AI is giving it the chance to perform a threat analysis. Although this just cannot be all, without it all would be nothing.
 
i like the personality idea. im not so sure about "dumbing down the ai" though. its dumb enough as it is. for all our complaints about the dumb ai they play a smarter game than in most any game ive seen. this reduces the need to give production bonuses. and this is a good thing. as for personality i would love to see war-like or builder-type - that type of thing.
 
Yes, the specific example I used wasn't probably the best, although it would be a good way to make teh game levels meaningful. Currently, teh AI seems to be the same across levels, except higher levels have extra starting units and production bonuses. 'd rather the higher levels meant the AI was more intelligent.

Although this system can be used to make AIs of varying intelligence, the beauty of it lies in that it can also be designed to make AIs with distinct personalities. INstead of making a "low intelligence" and "high intelligence" AI algorithm, you make a "perfectionist" and "expander" algorithms. The mechanism is as flexible as the number of algorithms you can think of.

ETA: Or even "dumb builder", "clever builder", dumb expander", clever expander", etc algorithms. The concept really is that flexible. There are two levels of design at work here...

1 - define a number of AI algorithms for each decision process.
2 - For each civ leader, define a set of % chanbces for it to act according to a specific algorithm. Essentially, the computer, instead of merely checking the sole AI algorithm to see how the AI reacts, it first checks to see which algorithm to follow, then, based on that randomly (weighted by the civ leader personality) chosen algorithm, makes a decision.

Rough example:

The Russian computer civ is ruled by Peter the Great, and in the civ leader definition, he is defined as having a 75% chance of following the "perfectionist" algorithm, and a 25% chance of following the "expander" algorithm, any time a decision needs to be made.

On that civ's turn, the city build queue for Kiev needs to be chosen. Random numbers are generated, and this turn the Russian civ will follow the expander algorithm. The expander algorithm is checked, its priorities regarding what needs to be examined, and the AI decides to build a hussar unit based on that algorithm.

If the perfectionist algorithm had been chosen that turn, it would probably have chosen a marketplace as the desired build item. Of course, if Russia was at war at the time, even the perfectionist algorithm might have decided to build a military unit. Each specific personality algorithm should be fairly viable in its own right as an AI actor.
 
I would like an AI that attacks based on threat potential, since my military is only ever large enough to defend my empire effectively. It would mean that I could concentrate on culture and economics without my pesky neighbors forcing me to divert my attention from my buildup.
 
Are you trying to say that AI should alway attack the strongest civ? That against any common sense.
 
@Lockesdonkey
Using the above threat potential formula would not work for civ. The idea behind that specific formula is to get a rating for how quickly you could get a "weapon kill" in an rpg. So if you have a lot of hit points, the monster would pass you over as it would take a long time to get that weapon kill, but if you do huge amounts of damage per attack, he would prioritise you.

Relating this to civ, the generic formula is (reward for attacking you / cost for attacking you). So the size of your empire, in land, developed tiles, and large cities is the reward, and the number of defenders is the cost. Putting only minimal defenders would make an AI with this kind of prioritisation VERY likely to choose you as its next target, simply because the AI 'knows' it can get away with it.

Of course, a properly developed AI would base its calculations on what the AI civ knows (and extrapolates) you have, not on what the game engine knows you have.

On the other hand, if you are having a really bad game and falling behind in tech and failing to develop your civ, the rewards for invading you won't be so high, which will reduce teh chance of you being attacked.
 
Pentium said:
Are you trying to say that AI should alway attack the strongest civ? That against any common sense.

No, I am not saying teh AI will attack the strongest civ. I am saying the AI will attack the civ that reflects the best cost/benefits analysis. This is not necessarily the least developed civ. Given a lot of 'builder' players' habits of skimping on defences, I imagine this kind of AI might give them a higher priority for attack than if those builder players had given proper defences to all his cities.

How about an analogy. Imagine you are a burglar. Do you rob the rich man's mansion that has a burglar alarm, or the rich mansion that doesn't? Easy decision - the undefended one. But do you rob the alarmed mansion, or the non-council flat? The council flat might be easier to rob (low cost), but have nothing worth stealing (low benefits). In civ terms, the builder player has a non-alarmed mansion. So even though he is the strongest civ in terms of science and city improvements and population, the cost of attacking is very low, making what might be considered the strongest civ to become a viable target.
 
The industry is already good at making AIs with varying intelligence:

Dumb and Dumberer! :lol:


Sorry, couldn't resist. ;) Actually, one can pray that Civ4 has a cool AI. I've heard that God sometimes answers prayers. :D


rhialto said:
I am saying the AI will attack the civ that reflects the best cost/benefits analysis.

That would be a valid way to do it. Unfortunately, it would make the AI rather predictable, if you could divine its calculation matrix.

Civ3's AI isn't weak. It actually beat me, on Monarch, in my first game of Civ3. :eek: (You can visit my site if you want to read the story. 'Tis old news now, but you can read it if you want.) Civ3's AI has some very predictable elements, though, and that in itself can become a weakness vs a player who knows exactly what to expect.

How do you propose they should fix that problem?


- Sirian
 
Well, I know I say this ALL the time, but I still think that a number of good algorithms could be put together to help make the AI look more intelligent.
For instance, a ranking on relative culture strength/culture group rankings could be a definer of how likely/unlikely an AI civ might go to war with you.
Similar algorithms could be used to account for relative military strength, religion rankings, morality levels, relative economic strength and general 'trustworthiness'.
Of course, the next step would be to extend these algorithms to the behaviour of YOUR people so that, though you the PLAYER can act out of total self-interest (i.e. winning the game) such behaviour might hurt you domestically.

Yours,
Aussie_Lurker.
 
When I started this thread, I wasn't thinking so much about making the AI intelligent, so much as creating an engine that can allow for different AI leaders with distinguishable personalities. As it stands, all the AIs use the same intelligence algorithm, regardless of the historical personality of the named leader for that civ, and regardless of game difficulty (game difficulty is purely a function of production multipliers and starting units in civ).

With this engine in place for AIs, you can not only make different difficulty levels literally mean smarter AIs, but different leaders can have different personalities.
 
Oh, sorry Rhialto, I kind of 'saw it' but didn't 'see it'-if that makes sense?!
Anyway, I think that current civ traits and current civ leader SHOULD effect the AI civs you play against and that, YES, all your different civs should have their own AI algorithm to help differentiate them-especially as the game progresses.

Yours,
Aussie_Lurker.
 
I think one important aspect that the AI is lacking is shrewdness.

Like humans, they need to know when to negotiate for peace and when not to. When the war is going their way, they should not negotiate for peace, or better still, sue for peace, but break the treaty the very next turn and crush that last few cities of yours, just like we humans frequently do.
 
After mastering Civ 2, I got my bum wooped on regent in Civ 3 the first time I tried it. But predictability is a problem. But I don't think it's just that the AI is predictable, but that the game as a WHOLE is predictable. You know that you need to expand like crazy, no matter what everyone else is doing.

What if you expand like crazy only to find that someone has taken a slightly different strategy that exploits the weakness of your strategy? Unpredictability is important.

But even looking back at the AI and unpredictability... while it's important, I think that learning how to balance the most logical target is super important. There's nothing wrong with a predictable strategy if it ALWAYS WORKS.

Rhialto brings up the rich man's house with the burgler alarm versus the unprotected flat. One has high risks and high benefits, the other has low risk but low benefits. There's one more variable -- and that's length of time / effort.

On some occasions, there will be an AI with 4 cities just ripe for the picking. Sure, 4 cities isn't worth a whole lot. But he doesn't have the might of 20 cities to funnel more troops into his cities. And most importantly, if I plan correctly, I can take his entire empire in 2 TURNS!! 4 cities in 2 turns with essentially no reprocussions (except for a reputation hit that really doesn't amount to a hill of beans in the game)... you're damn right I should do it.

The AI should be much more cutthroat. At least at the high levels. Don't make it a question of handicapping, make it a question of how ruthless it is. And if it has to cheat, have it cheat with KNOWLEDGE about the best target, instead of its production speed.
 
As I said above the secret, IMHO, is to make the AI play in a more 'Human' way. But by that I don't mean like a human game player, but like a real-life human leader of a nation. Yes, sometimes they will be ruthless and cut-throat, but at other times they will recognise the need for diplomacy and co-operation-for whatever reason that might be. Then, to make sure that the AI isn't 'hamstrung', the same thinking should apply to the population of a civ that is played by a human player.

Yours,
Aussie_Lurker.
 
I think the AI should at least be able to evaluate threats, like a SOD sitting at the border is a potential threat, even if they are at peace. I don't know how many times I used this trick/common-sense to catch an AI off guard and capture like 4-5 cities in one turn. The AI should recognize that a stack of 10+ units (or something like that) on it's border is a potential threat, just like when Germany realized that Russia was mobilizing their army west that it was a threat.
 
I think what the developers need to do is sit down with a few experienced players and discuss what a human would do, what tactics he would use etc, and try to transfer as much of that as possible into programming the AI. Then they should vary the AI, so that different AIs will have different personality, strategy and build focus (they have incoporated it now as "traits" and "aggression levels", but that isn't good enough at all).
 
Rohili said:
I think what the developers need to do is sit down with a few experienced players and discuss what a human would do, what tactics he would use etc, and try to transfer as much of that as possible into programming the AI. Then they should vary the AI, so that different AIs will have different personality, strategy and build focus (they have incoporated it now as "traits" and "aggression levels", but that isn't good enough at all).


Well the AI's different "personalities" should correspond to good Human player "personalities" ie overall strategies approach to winning the game, etc.

Then I think a small amount of randomness could allow for a 'lower level AI'
For higher level... I think a slight economic+cultural+diplomatic advantage could be good (but not a research speed advantage, that definitely changes the balance of play) if it gets too much free info, then that strongly alters the nature of the game (if information is as important as it should be)

[A major point to this is that means an 'AI patch' would have to be released several months after every gameplay patch, while the human players adapted to it, and then Firaxis would compile their experience, and then they could go about updating the AI algorithms]
 
rhialto said:
@Lockesdonkey
Using the above threat potential formula would not work for civ. The idea behind that specific formula is to get a rating for how quickly you could get a "weapon kill" in an rpg. So if you have a lot of hit points, the monster would pass you over as it would take a long time to get that weapon kill, but if you do huge amounts of damage per attack, he would prioritise you.

Relating this to civ, the generic formula is (reward for attacking you / cost for attacking you). So the size of your empire, in land, developed tiles, and large cities is the reward, and the number of defenders is the cost. Putting only minimal defenders would make an AI with this kind of prioritisation VERY likely to choose you as its next target, simply because the AI 'knows' it can get away with it.

Of course, a properly developed AI would base its calculations on what the AI civ knows (and extrapolates) you have, not on what the game engine knows you have.

On the other hand, if you are having a really bad game and falling behind in tech and failing to develop your civ, the rewards for invading you won't be so high, which will reduce teh chance of you being attacked.

I don't defend my cities minimally. I merely don't have an attacking military. My cities are always defended by at least three units in the core, five in the borders, and generally with a line of defenders along said borders. I do not skimp on defense. Only on attack. (except air)

In short, my modern-era military looks like this:
150+ Mech Infantry
About 50 planes
Three Modern Armor.
Some assorted artillery and TOWs

And a navy of no particular size.
 
Back
Top Bottom