New experimental BetterAI version : more human-like and warlike behaviour

klokwerk

Prince
Joined
Sep 3, 2006
Messages
435
Location
Paris
While we wait for the new expansion (BtS), I thought I could mess with the latest BetterAI version (Warlords version only for now). It's far from completion but I already modified a few things and I will probably upload the DLL soon (this evening or tomorrow I think).

It's not at all an 'official' betterAI version, right now it's just an evolution of the latest BetterAI to something more warlike.

The idea is also to make the AI more human-like with things like :
- war declarations depending more on opportunities (closeness, city values) and a bit less on official attitudes
- being more conscious of who is about to win and what they can do about it
- more generally trying a bit more to win and a bit less to roleplay

Many people complained about the AI passivity in the latest builds, I fixed that and there are now many more wars.

The things I changed in this version :
*) bug fixes :
- minor bug where 'limited wars' were evaluated incorrectly (they used a 'total war' percentage instead)
- possible wars were not analyzed when the AI found no target for another kind of war
- corrected the way distances were evaluated in CvTeamAI::AI_calculateCapitalProximity according to Nacht's finding (kudos to him !) : this bug was making distant civ much more attractive as war targets.
- debug (chipotle) : several bugs in the war chances displayed with 'Alt'.

*) changes :
- more total wars now, especially when enough units are available
- many more dogpile wars : dogpile wars are now evaluated first, so they're now preferred over total wars
- slightly more limited wars
- 'attitude' weight reduced in deciding who AI should attack. A real player doesn't attack only if relations are 'furious', especially when there are better opportunities closer to him.
- 'closeness' weight greatly increased in deciding who AI should attack. With naval invasions still a bit difficult for the AI, it's often much smarter to attack a closer neighbour. It's also much quicker and better for finances.
- debug (chipotle) : added war chances 1st check (often very high) in the things displayed. Ignore this number.

*) known issues left (which were already in BetterAI latest official version) :
- sometimes an AI decides to attack and the war won't start even dozens of turns later. It's due to the impossibility to reach the chosen enemy to start the sneak attack. I'll try to fix this one soon, but it's probably hard.

The next things :
- continuing to tweak the agression level, depending on feedback
- giving the ability to start more than one war at a time when the first war will clearly be won.
- understanding other parts of the war code, including the 'ask for peace' code and the units evaluation (which decides partly total war chances), to see if I improve something.
- bug fixes
- thinking about giving goals like diplo and domination victory
- further AI vs AI testing (automating that too ?)

EDIT : Ok folks here is the first version. It's really in alpha stage, but the agression level should be much better

http://forums.civfanatics.com/uploads/99614/BetterAI_Warlords_Asserts_Unofficial_07-06-04.zip

Feel free to comment, give other ideas or remind me of other bugs in the latest BetterAI official version.

Many thanks to Firaxis for this great game and to Blake and Iustus for their awesome work on the AI.
 
Sounds good to me.

Personally I like there to be plenty of wars and was slightly disappointed with the last Better AI release, in which the AI aggression seemed to have been toned down a lot.

Anyway Im looking forward to downloading it great work.
 
Good to hear that you've picked up the ball and are trying to improve the AI even further. Of course, you might have to redo all of this when Beyond the Sword arrives. Still, a good idea that works for Warlords is probably still a good idea for Beyond the Sword.

Two comments:

1) Don't completely remove the attitude part in war declarations. I think it is good that the AI will sooner attack a near civilization than a far away civilization, but if at some point the AI almost ignores the relations, then diplomacy will become a less meaningful element of the game and that is surely not something that you would desire.
By the way, I don't think you were planning to completely remove the attitude part from the war declarations.

2) I've read that the AI in Beyond the Sword would be improved and one of the few things that mentioned explicitly was naval invasions. But even if this were not the case, then still an AI should try it sometimes. What if an AI on a continents map were able to conquer an entire continent (which would be great). Then surely it would be immensely powerful compared to civilisations that share a continent. It should try a naval invasion of the weakest civilisation of another continent and go for world domination. If it is in the late game, it should quickly create airports on the enemy continent to transport its army to the other continent. Will it do this with your present ideas?

Good luck! :thumbsup:
 
Thank you for your comments. I'm note sure I can 'improve' BetterAI so much, Blake and Iustus made obviously a great work, and I'm even not a developer, but I can certainly change a few things according to the taste od some of us.

scu98rkr : I agree with that. Now the agression is maybe too high, but we'll see when we test it. I didn't change anything in the 'power check' right now, so the AIs won't be suicidal either, they won't attack if they're not strong enough to beat their enemy. They'll just evaluate possible wars more often.

Roland Johansen :

1) on the attitude in war declarations : I totally agree with you. Before my changes attacking a civ you were 'furious' with was valued 8 times more than attacking a civ you were 'pleased' with (and 16 times more than attacking a 'friendly' civ). This number is mixed with closeness, so basically you could go eight times more far to attack this civ, which was far too much I think (AI always chose the bad attitude civ by a wide margin), so I reduced that but certainly not eliminated this factor. The factors are now something like 1 / 2 / 3 / 4 / 6 (from friendly to furious) instead of 1 / 2 / 4 / 8 / 16 so there's still a nice attitude weight, especially considering the distances between civs don't vary so much. The results I get seem more human-like, but further tests are clearly needed.

2) Exactly. In BtS AI will be improved and we'll probably all restart our work from scratch. If Naval invasions work, the closeness weight should be reduced again. But even now with my changes, the AI will still try sometimes distant naval wars (at least that's what I saw in my tests on a late game). It's just that it will look at the closer opportunities more realistically...

Right now I made no changes to armies or buildings, but I'd surely like to work on this part too... I don't know if it's building airports correctly right now to help in its invasions, but I write down the idea immediately.
 
Thanks for the quick response.

Sometimes you see the AI do strange war declarations. It has someone it could easily beat and doesn't like but it attacks a stronger civilisation that it doesn't like. This is not realistic from a role playing point of view nor is it good from a smart human like point of view. I haven't looked at the code at all, but I guess it just has to do with random number rolls. The AI is more likely to attack the weaker civilisation than the stronger civilisation, but because of a bad random number roll with the weak civilisation and a good one with the stronger civilisation, it decides to go for the stronger one.

Now, we don't want to make the AI predictable. If two civilisations are both disliked and both near to the AI controlled civilisation and one is just slightly stronger, then it should not always go for the slightly weaker one. Some randomness is good.

The likeliness to attack is probably some number based on attitude, distance and strength of the opponents, the higher the number, the higher the likelihood of attacking that civilisation. I suggest that the AI doesn't declare war on civilisations which have a number twice or three times as low as the civilisation with the highest number. That way, there is still some randomness in who the AI declares war upon, but it won't accidentally declare war upon an unlikely opponent. Because in my opinion, it is these few strange war declarations that stop the AI from behaving 'realistic'.

Good luck. :thumbsup:
 
Exactly, the strange declarations you see are due to the rather strange system itself. Maybe it would be better to design another algorithm from scratch, but I won't do it for now. Maybe after BtS if it doesn't change.

The algorithm is :
- if I've got a war, don't declare another (I'll try to change that very soon, a human can easily dogpile a very small civ AND face a bigger one, now this system slows down the domination victory because of pointless small wars vs pushovers)
- otherwise must I declare a war ? First there's a general war check (often yes)
- Then a total war check (rand vs a number depending on personality and units / power). Yes -> choose enemy if possible, No -> next check
- Then a limited war check (rand vs a number depending on personality and units / power). Yes -> choose enemy if possible, No -> next check
- Then a dogpile war check (rand vs a number depending on personality and units / power). Yes -> choose enemy if possible, No -> no war

It's not very 'human-like', a human looks at the opportunities and then decides if he goes to war, here the AI does the opposite, and consider some difficult options (total war) before easy options (dogpile war)

The system is not so bad because the first check (total war) depends on the units available and it often gives acceptable results, but in my opinion, one of the things to do is to put the dogpile check on the first place, that's what a human would do... I'll probably put dogpile in first to give the wars a more 'human-like' feel. But even with my changes, dogpile wars and limited wars are still more unusual than total wars.

We must also consider the situation differently if a civ is about to win, because after all, which human would dogpile a pushover when his neighbour is about to reach a space victory ? I don't say AI must dogpile-war the civ about to win (god no !) but I say that the AI should try to win and know it's about to loose the game to weigh its decisions a bit differently.

On the randomness, I agree that it's good. It's the war declaration algorithm which can be improved.

The target civ chosen depends only on attitude and distance (both capital distance AND global distance between the 2 civs)

There's a final check though, the 'power check' which I didn't touch, and stops any war that the AI doesn't think is good, depending on the relative power (+ allies / vassals / defensive pacts) and on the leader personality. But if I remember correctly, this number is just a final check, it's not included in the target choice. But the AI will never attack a 'too strong' opponent, which is good. Now it can be a bad evaluation...

One dirty thing I don't like in the code too is that when 'agressive AI' is on, the AI believes its power is worth 4/3 of what it's really worth, so it starts wars it will potentially loose... I will maybe reduce that or even remove it completely, because there are other ways to make an AI agressive than fooling itself on its own capacities. On the other hand, it makes it optimistic ;)

Were you playing in 'agressive AI' mode when your AI attacked a too strong opponent ? Which leader was it ? What was the situation ?

Other than this 'agressive AI optimism', I can factor in the opponent's power before the target choice, but it has to be tested, I don't know if it's a good idea. As it is, it should attack the big nations (especially if it doesn't like them) when there are enough units, and the smaller ones when it can't, which doesn't look so bad.

As a summary, the bad war declarations you see are due to total war preferred first and power not considered as a factor for the choice as long as the attacker has enough power to challenge it. If agressive AI is on, it's also due to the optimism factor (4/3).

If I put dogpile wars first, along with my other changes to increase war declarations, I think the AI would choose better opportunities (vs slightly smaller opponents on average) and wage war much more often. I'd like to slightly decrease the 'agressive AI' optimism (since I don't think it's a good idea) factor (4/3) but I'm afraid to decrease agression too...

You'll tell me with the first version (I'll upload it tomorrow or earlier).
 
I always play with aggressive AI, because I'm used to it and in the normal game the non-aggressive AI is far too passive for my liking. In the latest version of betterAI that is the same for me. I'll use aggressive AI to get some more wars in the world.

I think the AI should pick the weakest, closest AI that it doesn't like because it should be able to steamroll such an opponent and thus become stronger and better prepared for the rest of the game, whether it goes for domination or a spaceship victory.
However, the AI will sometimes pick another AI to attack which isn't that weak or isn't as close. Some randomness is ok in the war declaration algorithm, however if one civilisation is a much easier better target, then it shouldn't even consider the other civilisation as a potential target for a war declaration.

A real world example where nations positions on the world map are shifted.
Lets assume that the US is a neighbour of Russia and North Korea and Iran and it dislikes all three of them equally and the US is aggressive and going for world domination. The US military is stronger than the Russian, the North Korean or the Iranian military, but there is a big difference in strength between the Russian and the North Korean or Iranian military strength. If the US would want to go for global domination, then it would be more useful to first quickly conquer North Korea or Iran to further increase its land size and thus potential power and only then consider other potential victims. The battle against Russia could destroy them both. It's in a real world perspective and in a game perspective just a smarter thing to attack North-Korea or Iran.

Now if the choice were between North Korea and Iran, then the difference in strength would be smaller between the potential victims and I wouldn't mind if the AI decided to attack either of them.

So if after an evaluation, the likelihood to attack North Korea would be 15%, the likelihood to attack Iran would be 10 % and the likelihood to attack Russia would be 1%, then I wouldn't want the AI to accidentally attack Russia. It should either attack North Korea or Iran and change the chance to attack Russia to 0%.

I hope that I have some time to play with your succession of the betterAI mod, but I don't know if I'll have the time and I'm not a fast player. But there are bound to be other players testing it. Especially if you promote it in the sticky 'latest version' thread. There are probably still a lot of civfanatics who have subscribed to that thread.
 
Yes, I agree it's often smarter to attack weaker nations, though it can also be a bad idea if we're already too late in the game. Maybe the enemy power should be included in the 'target score' before choosing the target, I'll try to test that. Right now if the bigger nation is closer and they hate them more than the small one, they'll probably choose the bigger nation, which is smart only in the late game... We could fix that relatively easily.

I already hear the fans complain though : 'all that your stupid AI does is dogpiling the weaker civs' :lol:

I discovered another bug on war declarations this evening : when the AI decides to make a total war and finds no good target for it, it doesn't look if it can make limited or dogpile wars, because it's an "elseif" in the code... It means that if the total war random roll succeeds, you won't start any dogpile or limited war this turn, even if you didn't find any target for the total war.

It's a minor bug (I don't think it's intentional), but it further slightly reduces the number of wars (especially dogpiles).
 
Hello klokwerk. Thanks for picking up on the development. Other than a recent foray into playing Rhye's mod, I have been playing Better AI since it first appeared on CFC. I have missed its evolution.

After the last release, I started playing with Aggressive AI on. This made the games more entertaining, but I reluctantly concluded that it was a benefit to the human player and stopped using it. Now I see that the 4/3 strength valuation probably has something to do with why it is an advantage for the human.

I read your post mentioning the check/stop when the potential enemy is too strong. From what you're saying, this happens after target selection. I think you are indicating that it should be part of target selection, which seems logical to me.

I would like it if the AI could take into account any ongoing conflicts, so that a stronger civ might be considered a valid war candidate if it is already engaged in another conflict. This could be especially useful when trying to get one AI to fight against another, though this could work out too much in favor of the human. Still, I've often regretted recruiting an AI to join a war, especially when my enemy becomes that AI's vassal, so it might not be advantage human.

I'm going to give your modded mod a try as soon as it's available.
 
I agree with you. It would be nice if the AI could determine the best war opportunity. It would attack the smaller civs unless it's a good time to attack a bigger enemy, because this enemy is under attack by another powerful civ. I hope that my increase in the dogpile wars is a good step in this direction, but it's a small step.

I just uploaded the first version of the modded BetterAI. It's still in a very early stage, but any feedback on the wars would be nice (with and without 'agressive AI' option).

http://forums.civfanatics.com/uploads/99614/BetterAI_Warlords_Asserts_Unofficial_07-06-04.zip
 
Thanks for continuing the work on this. Hopefully Iustus will get on here and give you the list of failed asserts to finish (he was looking for someone to finish those before he disapeared). The change in war declaration code will be nice to test. Also does this version include the distance declaration fixes?
 
hi!

did you also change something about the way a war ends? or do you intend to?

for me, it's often frustrating that the ai "refuses to talk" even though it is clearly losing the war, i on the other hand am crippled by rising war weariness ... which is why i would rather have peace than spend another ten turns conquering another remote city.

it even happens when the ai declared the war! i think it should have a way to judge if the war is going badly (difference in the number of units lost, difference in the number of cities lost, or maybe change in the power value from the stats) and if so, try to sue for peace.

i'm happy to see that you picked up development again, thank you!
 
phungus : yes, the distance fixes are included in this first version. You can see all the changes on the first post of this thread.

ilteroi : no, i didn't change the way a war ends. The AI already checks whether it's winning a war or not, but this 'war score' is maybe wrong. It's possible I'll work on that too, but actually I intend to work more on the AI after the new BtS version and the new SDK are released (and if possible with the help of other fans), because it will probably change much. It's only 43 days left after all.
 
It's possible I'll work on that too, but actually I intend to work more on the AI after the new BtS version and the new SDK are released (and if possible with the help of other fans), because it will probably change much. It's only 43 days left after all.

Yeah, the AI is going to undergo alot of changes, the current better AI mod wol't be compatible, of this we can be sure. It does make sense to wait.

It'd be cool though if we had this up and running again, this was a cool project in CIV, and it was really fun to test it's progress, I hope it jump starts again after BtS comes out.
 
Yes, I hope there will be people working on the AI after the release. I surely will if they release the SDK.
 
i played a bit with this tonight. seems a big improvement. great work. I'll play a full game later but this seems like a big step for BetterAI.
 
I played (well started and gave up) three games with the new dll on monarch with random leaders. With old dll I won around 90% of these games (with aggr. AI). Now I got smashed three times in a row (with normal aggression level). I would call the that a BIG improvement - or really bad luck with the leaders and starting positions ;)
 
Hi I downloaded this at the weekend and played a bit.

I also used a new map script Earth2 which may have caused the problems. But I found I could not pillage sea based improvements such as fishing net.

It was a bit of an odd map with every one very spread out so I dont want to comment on the aggression I will try it again sometime this week.
 
Thanks a lot for the feedback ! It's nice to hear that you seem to like it. The AI is clearly much more agressive than ever before if it's working like intended, though it's still far from playing the way I'd like. Your comments make me want to continue to change things.

Please give me more detailed information if you can (and / or send me saved games). Were there early wars ? Were there many wars ? Who attacked ? Was it only the warmongers ? Were they distant sea wars or close land wars ? Did any AI get close to domination victory ? Did anybody betrail or dogpile anybody ? (they should betrail a bit more now and dogpile much more)

What do you think should be improved now about wars, agression or diplomacy ? (the parts I like working on the most...)

Once again, all I did is tweaking and fixing a few things, so let's thank Blake and Iustus for the awesome work they did. The parts I find most impressive are the cultural victory and the deadly crush attacks / dagger strategy.

My main goal after the BtS release (if the BtS AIs can't do that on its own) is to make the AI go for all kind of victories and to play 'like the humans' : they would know who is about to win (and who is second and so on), they would evaluate the danger (powerful close foes...) before deciding anything, and weight strategic goals depending of these numbers. The tactical decisions would be similar but they would depend on these strategic goals.

I read in Blake's posts that his intention before he stopped was to make the 'agressive AI' the switch which makes the AI play like a greedy human. It would certainly be nice to do that, and leave the no 'agressive AI' games for funnier and more different but less efficient AI personalities with complex strategies. War is often a major opportunity though. It probably had to be considered more, even by relatively peaceful AI in a normal game. In a way, if your neighbour is very weak, and you don't like him so much, it can sometimes be stupid to let him live in this game, even is you're a builder.

scu98rkr : could you send me your saved game ? I could try to look at this, if this part of the code is not too hard to understand.
 
The AI is not always using the cannons etc. in the proper way. I had a huge pile of units attacking a city. Inside the city it had many units, including cannons. The thing is it didn't make use of the cannon, which could destroy my pile, and defend its city becasue it would greatly weaken all my units. I would have no chances of destroying the city. The AI stayed in the city with all the units, thus couldn't protect itself. My point is the AI should distinguish between cannons and other types of units, also those to defend the cities. I hope and wish it could be improved in the future.
 
Back
Top Bottom