Just modified the war declaration code

klokwerk

Prince
Joined
Sep 3, 2006
Messages
435
Location
Paris
Sorry for my poor English, it's not my native language. I installed the sources yesterday and started to mess with the war declaration code. I made the distance much more important for deciding who to attack, and I made the attitude less important. Then I increased the global chances that a AI civ declares war.

It seems to work better now with many more nice wars directed against the neighbour civs (as a human would do) but I need to make extensive tests before I upload anything or ask to join the team. I think we'll all work on the Beyond the Sword version now, and probably after the first patch. Any work now would probably be wasted.

In the latest BetterAI official version (and other versions too), the attitude multiplier was 1 if friendly, 2 if pleased, 4 if cautious, 8 if annoyed and 16 if furious. Basically it means that if you were furious with somebody, you would declare war on him even if he was in the other side of the world.

The problem with that is the AI still doesn't know how to wage distant wars because it can't make sea invasions properly (Blake and Iustus stopped their awesome work before this part of the code worked properly), so right now the best idea is probably to avoid the sea invasions as much as possible. It's often much more sensible to attack one of our neighbours anyway.

More generally, the war declaration system seems flawed to me. I mean to decide if it starts a war, the AI uses a general random number, then if this number is ok, it looks to who it will attack... A human would look at the opportunities (= who we would attack), and then if the opportunity is ther, it would attack. The AI system has two major drawbacks :

- we always have 'too many wars' or 'too few wars', since the 'gobal war chances' are relatively similar between the civs... If the number is too low, the civs won't use their opportunities, and these opportunities vanish. If it's too high, we've got permanent wars everywhere.

- these wars don't feel 'human', it looks forced, since the AI doesn't look at the opportunities before deciding if it starts a war (it looks after)

I'm pretty sure we can improve that when I look at the code. We should probably remove the 'global war chance' and design an 'opportunity / goal' system. The civs could choose to go for conquest / domination victory when they're ahead.

But there's a choice we'll always have to make. You can design an AI who 'roleplays' or an AI who 'tries to win' like the player would do, or a mix of both. We can design both kind of AIs too...
 
Excellent I notice Nacht or Yakk have also started a post below about the distant Civs maybe there are a few people interested in this still.
 
Yes I saw this thread and I included the fix found by Nacht too. I trust him, I didn't check this part of the code.
 
Thinking... Why does a player go to war in Civilization?

Civilizations should only try to expand if their economies can handle it.

Not all wars are wars of expansion: sometimes they are wars of hatred, or wars of "I can do more damage to them then the war will cost me".

Finally, there are Diplomatic wars. To build up a friendship with an ally, you got to war with a rival of that ally.

Wars of Expansion:
TastyFactor: how good would taking that territory be for the empire? (Closer cities & better cities are Tastier) Is there a cherry of a city I can see and pick off? (note transportation links to/from the city)

DangerFactor: how strong are they, compared to me?

AllyFactor: Can I bring allies into the war? Can they bring allies into the war?

Allies are uncertain: so one shouldn't always avoid going to war just because the target has strong allies.

Wars of Hatred:
If you really dislike someone, you start destroying and pillaging their territory.

This can also set you up for later Expansion wars, when your economy is doing better.

Wars of Hatred also models an early Conquest victory.

Diplomatic Wars:
Possibly should be restricted to someone asking for help -- then the AI decides "how costly would this war be, and how much do I want the asker to like me?" This simplifies the problem significantly.
 
Nice summary. Thank you for your post, it gives me nice ideas about the way our AI could change.

- Finances : Right now, there's a financial check before they think about declaring war (I don't know if it's working well though), I won't modify this part of the code until further testing.

- Wars of Expansion :

1) your TastyFactor is only very partly considered, I mean closeness matters when deciding who the AI will attack. I greatly increased this closeness factor, because the attitude factor was much much more important, and it gave unrealistic results like attacking a small useless civ on the other part of the world (which would kill your finances if you get its cities anyway), while you could just attack you rich neighbour and extend your empire.

The value of the cities which will be taken are NOT calculated though afaik, and it would be a nice idea to put it into each civ 'war value' before the choice.

2) DangerFactor : right now the enemy power is a blocking factor to stop the AI from attacking, which is ok, but AI should also understand when someone else is about to attack us anyway, or if he's 'going to win', not to start a stupid dogpile war, but to try to find solutions (diplo alliances and isolation, vassals, sabotage, and ultimately war if necessary...)

3) Allies : the current allies are factored in, not the possible future allies (probably because it's uncertain). It would be to nice calculate this uncertain future alliances. The AI looks for allies just before the war, and during the war, which is good.

- Wars of Hatred : they were already in, since attitude was by far the most important factor. I reduced this as I explained above. In my opinion, massive pillaging should be considered as an option when you can't conquer an enemy because the cities are too well defended (or don't want to conquer him for financial reasons) and you want to disturb him anyway. Pillaging and sabotaging are good ways to slow a potential winner too (it would be nice to calculate that).

- Diplomatic wars : I agree. I don't know well this part of the code, so I can't tell much. I think some AIs should aim for diplo win if this win is close, and more generally they should try to make very close friends (especially when permanent alliances are on), even if it's mean going to war. But I don't think we should remove the 'power check' though, even in this case, just weight it differently. This check works well I think.

In my opinion, the ultimate goal would be a design a more 'human-like' AI. The changes I made (see in my next post) are a first step towards this. Right now, the AIs roleplay too much. While the player tries to win, the AIs often just attacks the nations it hates, and so it kills the game (except if you like sandbox games). We must find a better compromise between a 'roleplay AI' and a 'multiplayer AI'.
 
A first approximation of Tasty for a city can be the same for every civilization.

Then scale it based on the distance to the capital of the city.

Cities that you can't scout should be assumed to have (average of enemy strength, weighted by city value) defences.

Take Tasty/Defence, and that gives you a first-pass Cherry score for the city.

Cherry Picking:
A stack of your units "threatens" a city if it can get within 3 turns of the city.

A city supports another city if they can move troops to the city from the other one in 2 turns. The second-pass defence of a city is that city, plus the support from other nearby cities. Note that railroads, roads and engeneering significantly boost support.

If you find a potential cherry with someone you might consider going to war with (high first-pass Cherry score):
1> Figure out if you can get a stack to threaten the target city. (naval or land).
2> Calculate the second-pass Cherry store for the target (taking into account nearby support, and how awkward it makes your borders)
3> If it passes, maybe engage operation Threaten.

You move your stack into position to Threaten. You attempt to reconfirm the target stays a Cherry. Once it is in position, you open hostilities and attack.

A Cherry strategy would make the AI much more human-esque. And it would make players much more leery about open borders agreements. :)

In war, you also want to Cherry-pick: look at cities nearby your attack stacks, and determine which ones you can take. If you can't take cities due to the threat of support, check if cutting road links would give you a better chance, or determine if you can spare extra forces to increase the size of your threat. And if all else fails, pillage the enemy into the ground.

...

I don't think we should design a more "human-like" AI, but rather we should steal from humans good tactics and strategies. Remember, humans ignore the in-game diplomacy values -- we want the AI to roleplay them.

Stealing some human strategies -- "conquor the world", "expand when my economy can handle it", "dagger thrusts", "cherry picking", "dog-pile", etc is a good thing -- but our goal isn't solely to make a harder AI.

It is to make a Better AI. :)
 
Your cherry idea seems good. Some of the elements you give in the detailed plan are probably not possible right now though (that's not the way the AI wages war), maybe in BtS or if we redesign the tactical AI.

I don't agree with you on the fact that the player ignore the diplo values, at least it's a bad strategy if they do (especially on high level) : you quickly end up being hated by the whole planet and eventually beaten because you can't trade techs or all your enemies have allied against you, or someone gets a diplo win. It clearly cares less for us than for them, though. I just decreased this gap (see on the other thread).

What you say about 'human strategies' is exactly what I mean when I talk about 'a more human-like AI', just include our own strategies (English is not my native language, so my sentences are sometimes wrong I guess). You can see in the other thread that I already plan to make dogpile more frequent. I totally agree on the goal, which is not to make the AI harder, but more challenging in the way it tries more to win. Yes, there will always be differences between the AI and the player, and yes they will always roleplay more than we do. I'm fully aware of that.
 
Back
Top Bottom