• Civilization 7 has been announced. For more info please check the forum here .

The Civilization IV AI mod project

Brain said:
Well, I'm a professional programmer too so maybe I can help.

What Warpstorm means is that the RTS doesn't need to be smarter. It can beat the human player just because it's faster. However, this doesn't mean that RTS AIs are simpler. In fact, it's harder to make a time-constrained AI.

Correct, but...most RTSs do use the crutch. They can juggle more than you can, so they are "smarter".

The big time usage with a time constrained AI isn't usually the deep strategic thought (which it doesn't usually do), but rather the "simpler" path-finding and unit management stuff. It is hard to do that type of processing fast and accurate. In a TBS, you can wait.

Another crutch that most (but not all) RTSs fall back on is scripted skirmishes. If you look at C&C (or any of the games based off of it, like LOTR), the AI follows a very tight script, including where to build up the forces and what to build when. This crutch can't be used directly on random map games like Civ, but many of them do have scripted build orders.

Another crutch that most RTSs (and to a degree even Civ) falls back on is too much knowledge of the map. In Starcraft for example, the AI rushes my encampment before they could have know which site it was at. Even the random map RTS AIs usually exploit this.

I expect more from a TBS game's AI because it is turn-based. I am willing to wait for a good decision, not the best that can be done between animation frames.
 
SenJarJar said:
@vbraun: You're of course correct in that during turns we can try to be as efficient as ai. But in C3C, I would guess that most people would refuse to micromanage such that for instance at the end of every scientific discovery, you would convert excess beakers into tax revenue. Not doing so had a way of drastically "slowing" your progress relative to the ai.

I do that in my games and I only play Monarch. :)
 
@Warpstorm: But Warpstorm, the Starcraft ai is most powerful when you play on a user-created map, starting with a hub-collection building and four worker units. Surely you do not mean that the map's writer has anything to do with how the ai faction will perform? The only thing a map-creator must do is make sure that there is enough room and resource for the ai faction to grow and move around. Beyond that, the ai takes care of pretty much everything else. It can figure out for example where the best locations for staging assaults are and attack with a coherent battle strategy--moving in with quick melee troops and then quickly backing them up with the heavy units and specialists.

Furthermore, even in Starcraft's storyline maps, you can alter ai behavior by changing your own strategies. This proves that even though it is scripted, Starcraft's ai scripts are not unadaptable.

But let's say that it is harder for an ai like Starcraft's to figure out a randomly generated map, like Civ4's. Well then can you tell me some examples of what you mean by saying that you expect more from tbs ai? What are some of your expectations?
 
@vbraun: Well many Starcraft players, including myself once, have figured out the timing and the order of player-events such that--like your mm in C3C--we can most efficiently maximize our resources and time. In this way, the raw speed of Starcraft's ai is nullified, just as you have nullified C3C's power of efficient micro-management. But this does not take away from the fact that unless you mm every detail in C3C, you will fall behind interms of development compared to the ai's.

In other words, a phenomenon that is analogous to the rts's power of speed exists even in tbs. Or so it seems to me. :goodjob:
 
SenJarJar said:
@Warpstorm: But Warpstorm, the Starcraft ai is most powerful when you play on a user-created map, starting with a hub-collection building and four worker units. Surely you do not mean that the map's writer has anything to do with how the ai faction will perform?

My complaint of Starcraft's AI was it's near perfect knowledge of the map from the beginning of the game, not that once it had that knowledge it didn't know howe to use it.

I complained that C&C required a map-maker to lay out exactly the battle plan for the fight.
 
SenJarJar said:
But this does not take away from the fact that unless you mm every detail in C3C, you will fall behind interms of development compared to the ai's.

I don't mm Civ3 (never have, never will, but I do acknowledge that it can give you an edge) and can win fairly often at any level below Sid. I hope that mm will not give anyone an advantage in Civ4.
 
@SenJarJar - That's probably why I suck so much at Starcraft :lol: . But the thing is the C3C AI doesn't mm anything.
 
Okay. Since I promissed to present some more ideas, let me do just that. Here are some of my rough design ideas for this AI mod.

First, we have to define some terms. A strategy is a sequence of approximate steps to achieve a goal. I know that some will argue that an AI that just follows a script like this is not a true AI, but to be honest that's the best that we can do. That's why we want human players to think and invent strategies. By approximate I mean that the steps may be described only partially with unknowns left as parameters, and/or that there is an error margin. A goal is a specific game state to achieve within an acceptable error margin.

With this in mind the system would work in roughly the following way:

Choose a goal
Choose a strategy that fits this goal
Follow the steps of the strategy

Each step in the strategy can of course have several more goals to choose from and several sub-strategies. The algorithm can be exectuted recursively as many times as needed.

Choosing an appropriate goal and strategy is relatively simple. For this we can use a point scoring system. We look at various attributes of the game such as map settings, AI personality, and so forth, and assign a score to each of the goals/strategies with respect to that attribute. We can also add a random factor to the score for unpredictability. Then, we choose the highest scoring goal/strategy. Something like this:

Set the score for all goals/strategies to zero
For each goal/strategy
For each attribute
Add a score based on interaction of attribute and goal/strategy​
Add a random factor
Pick the highest scoring goal/strategy

To be even smarter, one of these attributes could be based on what the opponents would do. We can run the algorithm again for all opponents to see what they would do and then assign a score to all the goals/strategies based on our opponent's decision. For those who know what I'm talking about, this works like the minmax algorithm.

The next step, following the steps of the strategy, is more tricky. Here I have to point out that we're still looking at the strategic level not the tactictical level. At the strategic level specific actions such as unit orders or build orders are not specified. Instead, the system enters into a mode that affects its tactical level decisions. For example, if we are in "war mode" we are only going to produce military improvements and units and we are going to send our units on missions instead of just garrisoning them in cities. Or if we are in "expansion mode" we are going to produce settlers and workers and try to grab as much land as possible. Of course, these are just an examples to show how the mode affects tactics without dictating exactly what to do.

In addition, there have to be some trigger conditions that change the state of the AI. When such a trigger condition is met the system chooses between one of several possible outcomes:

a) Go to next the step in the strategy
b) Retract to the previous step in the strategy
c) Re-evaluate the goal/strategy.

For example, if we are in "expansion mode" and there is no more unclaimed land then we move on to the next step. If we are trying to attack a neighbour and they rebuff our attack then we have to go to the previous step, build up our military. Or if we're loosing badly we might re-evaluate our strategy completely.

For now we don't have enough specific details about the game to say how the AI will make tactical level decisions, but I'm hoping that the default AI will be at least decent in this regard. This way we can concentrate on the strategy level first. But we have to wait and see.
 
@Warpstorm&vbraun: I will yield to the experts.:)

@Brain: Can non-programmers make suggestions here? Or do you want this thread closed to non-programmers? I would like to make suggestions, but being ignorant in the ways of programming I think I would feel like a backseat programmer if you didn't think it was ok.:)
 
SenJarJar said:
Can non-programmers make suggestions here? Or do you want this thread closed to non-programmers? I would like to make suggestions, but being ignorant in the ways of programming I think I would feel like a backseat programmer if you didn't think it was ok.:)
Of course you can make suggestions. It's just that if we're going to make an AI mod we have to get technical at some point. My previous post was addressed mostly at the programmers, but feel free to make any comments/suggestions you like.
 
@Brain: Thank you. Technical language isn't a problem as long as I can follow the logic behind it. The logical aspect of your project is what I find most interesting about this thread anyway. As long as I can expose the logic behind the programming jargon you intend to use, I think I'll be able to keep up.:)
 
@Brain
Regarding your proposal I find it a well thought way to do it. I do have a few suggestions though:
I would like to see the introduction of countergoals. By that I mean that the AI will be able to set a goal that says 'prevent civ X's goal'. This especially thought to make it more competetive against the human. This requires that the AI will be able to conclude what strategy the human is currently using and what the human is trying to achieve.

Also about the tactical level I really hope that the AI will start thinking tactical on a turn by turn basis as opposed to the unit by unit basis which is in C3C. If it is not included in civ4 then that will have to added too, before any strategy will have a decent chance of succeding.
 
Before making specific strategies we must first create a system that can evaluate the game and choose a strategy. It might sound simple but that's actually the hardest part. I'll present my ideas for this shortly.

I agree.

I think also that to build a decent AI strategy, you have to be able to
describe your own strategy in details.
(I think this is easy to do for a first player shooter, for example, but much more difficult for Civ, especially since there is such a wide variety of situations)
I think one track would be to observe succession games in this forum.
the players there discuss their choice, and therefore it should help describe their strategies.
I think once you can describe the different situations and the way to best deal with it, you're out of trouble. The coding is just technical, as it should be.

+ why not python for these devs ? since it is the scripting langage that will be used, I see no point in using an other one.
 
I also really think we should separate diplomacy from war itself.

the diplomacy part should evaluate :
-who is a threat
-who is a potential prey
-who is trustworthy and who isn't
-whether it is time to build up forces or if you can allocate more ressources to building.
-deal with other players (alliance/war declarations, cultivate friendship (yes, I said that :crazyeye: ))

the war part, in relation with data from diplo, should :
-choose the units to build, upgrade units (disband units)
-place units on the map
-evaluate strategic importance of cities/areas/chokepoint...
-choose consistent strategies once a war is declared (avoid to be lost as soon as two fronts open, use significant stacks/armies)

I think not making a clear distinction between those two leads to dead-end.

These to have to be separated as well from the overall strategic choices :
- what is our best shot to win (military, cultural, etc) => push toward it
- what threatens us the more (elimination, an other player victory) => influence diplo, trigger special strategies (raze this 19,5K culture city at any price)

I think this fits with brain approach. I would simply divide the system in several distinct subsystems informing each other.
 
If I may make a suggestion regarding Brain's concept of "modes":

I would like to suggest that there should be two sets of modes, each under the auspices of a Macro-Mode which affect every other mode and strategy: 1) "MACRO-MODE: WAR" and 2) "MACRO-MODE: PEACE." All other modes and strategies--such as expansion, culture building, and engaging in diplomacy--should be set as a sub-mode under each of these two auspices. This is because it seems to me that these are the fundamental states in which any Civ exists in. And all other modes and strategies are shaped by these two states.
 
In case I didn't make myself clear about the above post, what I had in mind was something like:

00) PEACE
-----000) expansion
---------->some routines and algorythms
-----001) diplomacy
---------->some routines and algorythms
...
-----00n) declare war, exit MACRO-MODE: PEACE (whatever you need to do to enter MACRO-MODE: WAR)


01) WAR
-----000) expansion
---------->some routines and algorythms
-----001) diplomacy
---------->some routines and algorythms
...
-----00n) declare end to war, exit MACRO-MODE: WAR(whatever you need to do to enter MACRO-MODE: PEACE)
 
I'm not sure about those two macro-modes.

1/ it sounds too binary to me.
there are some difference between a vital war between two neighbooring players and a low intensity one at the other end of the map.
+
It would make the AI far too much predictable (and exploitable)

I think a progressive threat level augmenting the priority of some needs as compared to some others would be more appropriate.
(I kind of imagine moving global priorities vs moving local priorities for deciding what to construct in a given city at a given time. geographical location will have to be taken into account)

(it's only my avice, I may be wrong)
 
Brain said:
The next step, following the steps of the strategy, is more tricky. Here I have to point out that we're still looking at the strategic level not the tactictical level. At the strategic level specific actions such as unit orders or build orders are not specified. Instead, the system enters into a mode that affects its tactical level decisions. For example, if we are in "war mode" we are only going to produce military improvements and units and we are going to send our units on missions instead of just garrisoning them in cities. Or if we are in "expansion mode" we are going to produce settlers and workers and try to grab as much land as possible. Of course, these are just an examples to show how the mode affects tactics without dictating exactly what to do.

Then in each mode have a list of paramaters that coorelate to each aspect of running a Civ, such as
Expansion
Growth
-Build lots of Settlers
Military
-1 Warrior per city
Economy
-After a city has built 1 Settler build a Worker
Religon
-After a city has built 3 Settlers build a Temple
Science
-Reasearch something depending on overall stratagy
...​

SenJarJar said:
@Warpstorm&vbraun: I will yield to the experts.
I'm no expert. :)
 
Old_Lion said:
I'm not sure about those two macro-modes.

1/ it sounds too binary to me.
there are some difference between a vital war between two neighbooring players and a low intensity one at the other end of the map.
+
It would make the AI far too much predictable (and exploitable)

I think a progressive threat level augmenting the priority of some needs as compared to some others would be more appropriate.
(I kind of imagine moving global priorities vs moving local priorities for deciding what to construct in a given city at a given time. geographical location will have to be taken into account)

(it's only my avice, I may be wrong)


@Old Lion: Heh, heh, I see that the silent lurker has retired, long live the Sid, er emperor, er king.;)

Old Lion, I would like to ask you whether you truly desire to have a situation in Civ4 in which you or the ai declare war on the other and then rarely engage the enemy, even if that enemy lay far away. If you declare war, shouldn't there be a coordinated effort by the ai to attain military victory? And by coordinated effort, I mean don't you think that it would be best if the ai employed its full trading, diplomatic, cultural, religious, political, etc power in addition to its raw military strength. It seems to me that war should be a serious state to find oneself in. The ai should be given the power to bring its full influence, resource, and power to bear against the enemy.

But even if you did prefer to have "low-intensity conflict" in your mod, using these macro-states would not necessarily preclude this phenomenon. For instance, if two distant Civs find themselves at war with each other, then we could enter into the calculation various factors based on a points system that would result in each choosing between a low-intensity response and full mobilization. Such a calculation could take into account such variables as distance from each other, strength of each's immediate neighbors, potential for military alliance, etc. But if there is a war, then regardless of whether the ai chooses a low intensity or high intensity response, every strategy and mode the ai employs should be one that takes into account its war status. For instance, unlike during states of peace, during even a low intensity conflict, the range of diplomatic strategies should be focused. It seems to me that the Macro-Mode model would make this focusing easier.

True, if modders are interested in ai programming, then they should always be aware of human exploits. But even so, using variables such as ones I have listed above should protect the ai from these predations. Furthermore, one key variable to give the ai is the ability to allow the ai to score its immediate neighbors on their propensity for warmongering. For example, if the ai at war knows that it has a warmongering neighbor, then we could devise a strategy that would make it less likely to invade and more likely to put itself into a defensive posture. Also, I am sure that there are ways we can devise to limit within reason human players from manipulating ai nations into declaring war on each other.

In other words, implementing a calculate-progressive-threat-level ability for the ai would not be mutually exclusive with any of my suggestions. In fact, I think we should use them together. What do you think of this argument, Old Lion. :)
 
SenJarJar,

I think we can agree. I find your last message more in adequation with what I had in mind.
The progressive threat level / war intensity are the same concept taken by both side.
I don't think my vision is contradictory with high intensity war.
"personality" and dislikeness should be able to put war priority high for a long time.

What i don't wan't to see is an AI declaring a civ at the other end of an huge map and spending 50 turns sending troops there while not developing and becoming a easy prey for its neighboors.

in my view, the war mode should never stop. Not preparing for it means losing, anyway.
(si vis pacem para bellum, as they used to say in Rome.)
 
Top Bottom