A Better AI.

Interesting behaviour by the AI in my latest game.
Parameters: 12/2 Build, Noble, Standard Size, Fractal Map, Me + 7 AI

I always play Random leaders and this time I got Montezuma. Started on a smallish continent with just me and Frederick. Soon became clear there was not enough room for us both when he founded a city that was going to block me off from much of the land. So war was inevitable.
I razed two of his cities fairly quickly and then paused to amass a Jaguar SOD for his capital. His response...
He kept building and sending out Settler/Archer pairs to refound the closest of the razed cities. I must have razed the city 3-4 times in the same spot. The thing was that the spot he chose was far more vulnerable than other sites available to him, even sites one tile away from his chosen site would have afforded better protection in the form of hills, but he kept on sending those Settlers to certain doom in the exact same location wasting vast amounts of resources and gifting me some welcome XPs in the process.

I realise that building an AI that learns from its mistakes is outside the goals of this project, (having worked on expert systems, constraint engines and limited AIs professionally I know how difficult this is!), but perhaps some limited checking that prevents repeating the exact same mistake every 20 turns would be possible and make the AI appear less suicidal in cases like this.

It ought to be possible to fix this without building any real 'learning' into the AI.

The city-site-rating code already has a term in it for the distance to each neighboring civ's borders/nearest city. And there's a term for the defensive value of settling on a hill (as noted by RJ). Just have the AI scale these terms based on some of the diplomatic modifiers. Then, if you've declared war, razed cities, etc., the AI will give your borders more respect and/or be more likely to settle on hills when near you. And that tendency will get stronger the more badly you behave.

No learning involved, and it should be fairly easy to code. Tweaking the scaling factors would be the hardest part.

Thoughts?
 
City ruins is also a terrain feature, right? So perhaps a negative value could be given to them, to try and make them found away from a ruin. Perhaps have this quite low (almost none?) during peace time, but during war time, make it much worse.
 
That's strange. I've seen the AI build cities on hills, while I would have preferred the tile next to the hill because it would have resulted in a more productive city (food, commerce, hammers). There is a preference for settling on a hill. Only when the tile next to the hill is clearly better than the hill settlement, will the AI settle next to the hill. I personally find the preference for hill settlements even too big.

AI's of course don't learn from their mistakes and I guess that it will be too hard for the team to program a learning AI. But the AI shouldn't be building many settlers during a war. And if the AI chooses to build a settler during a war, then it should defend it heavily. In my game, the AI completely stopped building settlers when at war. Weird that you had a completely different experience. Was the AI reduced to a very low number of cities, when it started building settlers? Maybe you could upload a (few) savegame(s) so that the Better-AI-team can take a look at it.

Don't get me wrong, the grassland city location was a respectable coastal site, nothing special but better than the nearby hill (which overlapped two tiles with the capital) it was purely an observation that if the AI was going to be bloody-minded and insist on building a city on my Jaguar superhighway then the 'defendability' of the site should factor in.
Whats more, there were actually many equally good (in my opinion better) sites elsewhere on the continent that the AI was ignoring as it kept coming back to this site. As you say there should normally be very few Settlers built during war but he was down to his last city so we could excuse one if heavily defended but the suicidal behaviour was unfortunate.

I'd love to post some saves but I have moved on a lot (Frederick is no more) in the game. My fault, I need to remember to save more regularly for this situation.
 
The city-site-rating code already has a term in it for the distance to each neighboring civ's borders/nearest city. And there's a term for the defensive value of settling on a hill (as noted by RJ). Just have the AI scale these terms based on some of the diplomatic modifiers. Then, if you've declared war, razed cities, etc., the AI will give your borders more respect and/or be more likely to settle on hills when near you. And that tendency will get stronger the more badly you behave.
Seems like a reasonable approach, but I'm not familiar enough with the code to evaluate it in depth.
My only concern with this approach would be to make sure the AI isn't over sensitive and ends up settling significantly inferior city sites because of a short term border dispute type war (I'm guessing this is what you mean by scaling factors). In my case he was about to be wiped out and in that situation any settler build was desperation and should have settled well away from my invading hordes.
 
Whats more, there were actually many equally good (in my opinion better) sites elsewhere on the continent that the AI was ignoring as it kept coming back to this site. As you say there should normally be very few Settlers built during war but he was down to his last city so we could excuse one if heavily defended but the suicidal behaviour was unfortunate.

I'd love to post some saves but I have moved on a lot (Frederick is no more) in the game. My fault, I need to remember to save more regularly for this situation.

Hmm, as you don't have savegames anymore, maybe you remember the location on the map. Did it have any outstanding features that might not have been visible to you but were visible to the AI (horses for instance). There would have been one reason for me to try the same as the AI did, namely access to a strategic resource.

But I guess that there is a high priority for building a settler when the AI is down to one city. I've seen Frederik of Germany do the same while at war with Alexander of Greece in my game. He was down to one city, Berlin, at some point and I saw a settler emerging from its city. I was worried that it meant another city for Greece, but the settler never got that far. I could see copper and horses at that time, so I don't think he was going for a resource. And there were no really good settling spots available closeby because it was around year 0AD and a lot of the land was already filled with cities.

I really think that if in war, the priority for settlers should be sharply reduced to avoid this sort of bad investment of production. The only exception could be to acquire a strategic resource. Of course, when an AI is winning, it could build a few settlers to settle empty territory. But especially a losing AI should not build settlers.
 
Suggestion:
what if you make the more religious AIs have a chance of starting Holy wars if the holy city of their religion is controlled by a civ that follows another religion (the war would not stop untill the holy city was owned by a civ that follows the 'right' religion again)
 
Suggestion:
what if you make the more religious AIs have a chance of starting Holy wars if the holy city of their religion is controlled by a civ that follows another religion (the war would not stop untill the holy city was owned by a civ that follows the 'right' religion again)

Good idea, but better suited for a religion mod. Blake's AI, if I understand it correctly, is more aimed at improving the AI without changing the game (which your suggestion would do, as it would change the meaning and impact of religions).

However, having the AI realize the possibly immense income and value of a holy city, and making it a key target for conquest, would be well in the scope of this mod ... I don't know whether such a feature is implemented already. Blake?
 
It's very difficult to define the borders of the development of this mod.

The AI now knows better how to attack a human or AI opponent. This means that you'll have to build more units and defend smarter. It means that AI's might be able to go for domination or conquest victories. The AI improvement does have gameplay consequences.

The AI now knows how to go for a cultural victory. This will mean that you might be forced to take it out before it reaches this stage. It does have gameplay consequences.

Blake and his BetterAI team will have to determine where the purely AI changes stop and the gameplay changes start. They might consider changing the priorities and logic with which the AI chooses opponents for a war. And the above suggestion from Gyathaar is related to that closely. Whether it is considered to be an AI-change or a gameplay-change is up to the team. We can only advice. Personally, I don't mind either way. It could be fun if the AI starts holy wars where groups of AI that share a religion join up to beat up on someone with a different religion. Too often, the AI-wars are one-on-one and if holy wars in some form could make the AI attack in clusters, then I think it's a good idea. Maybe improve the inter-AI-bribing skills to enable the forming of these clusters of AI.
 
It's very difficult to define the borders of the development of this mod.

The AI now knows better how to attack a human or AI opponent. This means that you'll have to build more units and defend smarter. It means that AI's might be able to go for domination or conquest victories. The AI improvement does have gameplay consequences.

The AI now knows how to go for a cultural victory. This will mean that you might be forced to take it out before it reaches this stage. It does have gameplay consequences.

Blake and his BetterAI team will have to determine where the purely AI changes stop and the gameplay changes start. They might consider changing the priorities and logic with which the AI chooses opponents for a war. And the above suggestion from Gyathaar is related to that closely. Whether it is considered to be an AI-change or a gameplay-change is up to the team. We can only advice. Personally, I don't mind either way. It could be fun if the AI starts holy wars where groups of AI that share a religion join up to beat up on someone with a different religion. Too often, the AI-wars are one-on-one and if holy wars in some form could make the AI attack in clusters, then I think it's a good idea. Maybe improve the inter-AI-bribing skills to enable the forming of these clusters of AI.


I guess I'd see the "idealised" (if unachievable) aim for this mod would be to make SP like MP. So the AI players should be out to win the game. At the moment, they aren't, and Gyathaar's suggestion would move us further away from that aim.
 
I guess I'd see the "idealised" (if unachievable) aim for this mod would be to make SP like MP. So the AI players should be out to win the game. At the moment, they aren't, and Gyathaar's suggestion would move us further away from that aim.
I guess it all comes down to if the AIs should act as pure powerplayers that do whatever it takes to win, or if they should act more like roleplayers and try to play a role while still trying to win
 
I guess it all comes down to if the AIs should act as pure powerplayers that do whatever it takes to win, or if they should act more like roleplayers and try to play a role while still trying to win

Exactly.
With the development of this mod we will reach a point where the singleplayer experience could be very close to a MP game.
I my self when playing SP like often to roleplay... still aiming to victory.. but not that much..
I think, if possible, this should be related to the difficulty level. On higher diff levels the Ai should use every trick to win.. while on monarch or lower ones it should offer a more roleplaying experince.. still challenging.. but victory shouldn't be the very first priority.
I know we are still far from the need to do so though.
 
I guess it all comes down to if the AIs should act as pure powerplayers that do whatever it takes to win, or if they should act more like roleplayers and try to play a role while still trying to win

I'm in favour of roleplayers that play their 'role' smart. At present, every AI has a unique personality and I think that is good. Not every personality might be equally succesfull, but it is more fun (for me) this way. And it might be true that those different personalities actually make it more difficult to win against all of them. You might defeat the warmonger only to lose the space race.
 
Hmm, as you don't have savegames anymore, maybe you remember the location on the map. Did it have any outstanding features that might not have been visible to you but were visible to the AI (horses for instance). There would have been one reason for me to try the same as the AI did, namely access to a strategic resource.
OK, attached below is a screenshot from much later in the game, the tile in question has now been settled by Cyrus (The AI really wants that city site), as you can see the only resources are two sugar. At the time Frederick kept settling this tile the north-south road was constantly travelled by Jaguars massing to attack Berlin. In addition the city sites on the left that I have now settled were available with Copper and Horses, as was another less desireable site with Corn and Sheep further South.
Looking at it now I suspect the large desert to the west, coupled with the coastal site, its proximity to Berlin and the Sugar were what made it so attractive compared to the others available. Still, I suspect a human player would have avoided that location without significantly better protection.
But I guess that there is a high priority for building a settler when the AI is down to one city.
I don't have a problem with this...just with the poor tile choice that the settler made. Ah, well its really not that important compared to the huge advances the team have made in other areas! :goodjob:

I really think that if in war, the priority for settlers should be sharply reduced to avoid this sort of bad investment of production. The only exception could be to acquire a strategic resource. Of course, when an AI is winning, it could build a few settlers to settle empty territory. But especially a losing AI should not build settlers.
Agreed!
 

Attachments

  • CitySite.JPG
    CitySite.JPG
    373.6 KB · Views: 131
... 2. Now an issue I with AI. Playing with the latest version of your mod (version of 2006-12-02). Isabella decided to attack me. Everything was well except that she landed one of the stacks on a single spot of land behind a rock. Obviously she did not realise that her riflemen will not be able to attack my city ever. I guess AI should check if the troops will reach any city after landing.

I attach (hopefully successfuly - I am new to this forum) a screenshot and savefile where Isabella did the landing behind a rock. :)

View attachment 143761

View attachment 143762

She might be attaching a lot of value to preventing you from mining that uranium?

When I reclaimed the spot where those unlucky riflemen had landed, I was suprised that they had not pillaged my mine and had not destroyed the railroad either. In fact during the game AI was destroying very little of the improvements if any at all...
So from the programming logic, AI should check whether the military stack will have a route to any of the enemy cities after landing. If there is such check now, it is incomplete. If I remember correctly comebody else also referred to a case when enemy declared war and then could not reach its target because of closed borders with other country that laid inbetween them.

A few more thoughts that came to my mind reading this forum:
1. About research priorities and how humans choose the most "tradable" techs. AI can also be programmed to assign value to techs it can research by checking its "tradability". E.g. the fewer opponents have the technology, the higher its tradability value. Combine this value with the religious and technological priorities and choose what to research. Plus a slight random factor should be involved to prevent humans from too simple guessing what the AI will research.
2. Currently AI settlers do strange things. I also had AI coming to my lands during war and settling a new city. Of course it was razed a few turns later.. :mischief:
 
I'm in favour of roleplayers that play their 'role' smart. At present, every AI has a unique personality and I think that is good. Not every personality might be equally succesfull, but it is more fun (for me) this way.

Agreed. Personally, I'd also prefer the Civ4 AI to be smart roleplayers. They shouldn't act out of character to win, but they should make smart decisions within their role to make them challenging.

One example that illustrates that quite well is the Civ3 AI during the first stage of the game, where the AI expanded rapidly and rushed settlers. In the context of the game and its rules, this was a smart thing to do. However, it also *forced* the player to do the same, otherwise he would fall behind. And I didn't like to be forced into a playing style that felt unnatural for my perception of history. I couldn't roleplay the development of a civilization any more because the game forced me to adopt non-roleplayer strategies in order to survive.

Personally, I'll welcome any AI improvement that will still let me roleplay my games. A mod that simply strives to make SP like MP will probably not ignite my interest much because this would shift the focus too much in the direction of "competing in the context of a game", as opposed to "roleplaying an alternative history".
 
As for the Holy cities, It simply could be a matter of

1. AI values having any holy city, ie If it doesn't have it then getting from another player becomes a Slight encouragement towards war
2. AI values holy city of Its religion a little bit higher than otherwise (sensible it will be spreading that religion and so should get benefits from it)

Combine these with the Religion modifiers to relationships, and the crusades will be possible. (all Christian/Muslim nations want Jerusalem for themselves, but their relationships are good enough with each other that the Muslim/Christian Civs are the only ones they are willing to go to war with over it.)
 
The relations are at +5, but he's cautious with me. I wonder if something about the AI concerning the requests might be changed. It's rather strange that he would demand support in his war efforts from me three times during one war with one enemy. If I had refused every time, I would have had a -3 diplomatic penalty with him while the other leaders don't get these penalties. Now, I understand that the AI needs some way to see if the human has a positive or a negative attitude towards them, but this seems a bit over the top. I'm really trying to get Alexander to like me, helping him in war, giving in to tribute demands and just giving away resources for free, but it doesn't help enough. He's cautious with me, while he likes the other AI players, even one of a different religion which is at 0 relations with him. Is there something in the code that makes the AI like eachother more than the human player when the aggressive AI setting is active?

You can alter the 'join war request threshold' (don't know how that's exactly called right know sorry) for any leader.
So you can mod Alex to request your aid only if you're pleased with each other or better or anything.

AI to AI relations are computed differently.
There are base values with some random additions that cause attitudes between one AI and another.
For instance Alex and Augustus will probably dislike each other in every game even if the same religion because of the 8 points difference in their basepeaceweight values while Napoleon and Alex have a good chance to be strong friends.
I've cleared the warmongerrespect values in order to make warmongers like each other a bit less and this together with the more aggressiveness in noattitudewarprobs setting there will be plenty of Genghis-Alexander wars and the such especially if they are different religion.
I like to see warmongers clash each other especially two dagger armies :) too which is heavily restricted by default settings. I understand they liked to make the life of more peaceful civs harder by this but this ended up in 'warmonger brotherhood' which is totally irreal. Sometimes warmongers and conquerors must go against each other. Additionally there are quite a few games where most of the AI civs in the game are warmongers and most surreally this would lead to an immensely peaceful game and worldwide friendship with default settings :)
 
You can alter the 'join war request threshold' (don't know how that's exactly called right know sorry) for any leader.
So you can mod Alex to request your aid only if you're pleased with each other or better or anything.

AI to AI relations are computed differently.
There are base values with some random additions that cause attitudes between one AI and another.
For instance Alex and Augustus will probably dislike each other in every game even if the same religion because of the 8 points difference in their basepeaceweight values while Napoleon and Alex have a good chance to be strong friends.
I've cleared the warmongerrespect values in order to make warmongers like each other a bit less and this together with the more aggressiveness in noattitudewarprobs setting there will be plenty of Genghis-Alexander wars and the such especially if they are different religion.
I like to see warmongers clash each other especially two dagger armies :) too which is heavily restricted by default settings. I understand they liked to make the life of more peaceful civs harder by this but this ended up in 'warmonger brotherhood' which is totally irreal. Sometimes warmongers and conquerors must go against each other. Additionally there are quite a few games where most of the AI civs in the game are warmongers and most surreally this would lead to an immensely peaceful game and worldwide friendship with default settings :)

Yes, I've read a few of your posts about the subject in this thread. You are maybe right in your assesment. The major problem that I was concerned about actually wasn't the invisible modifiers to relationships. I was wondering why Alexander asked me to join his war three times. I hadn't encountered such persistent AI nagging during one war before and wondered if it was related to the AI modifications by the BetterAI team. It did cause some negative modifiers from the Alexander AI since I refused two out of three requests. I actually think the AI should value the one time that I fought alongside him higher than the two times that I refused to join the war. But it is actually slowly forgetting about the joined war while it is remembering the refusals. I know that there are some modifiers that remain and some that slowly dissapear. If the AI asks you to join in its wars so frequently, then I think it shouldn't forget about both the joined wars and the war refusals or forget about both situations. Now it only remembers the bad and forgets about the good. With the many war requests this leads to bad relations. You can't join so many wars.

As the above is related to the AI, I thought I'd report the issue. Maybe it is just a coincidence in my game.
 
After a little more reading and experimenting I think I might be able to get WinMerge to do some of what I want. I'm looking at WinMerge diffs of the trunk and firaxis branches and they're informative. :)

I was thinking about looking at the Great General and military building code and seeing whether there's a save-file-compatible way of getting the AI to do a better job creating military buildings and instructors. I don't know whether the AI keeps track of a city with the role of "military complex" (as I've started calling it) during the game, but I don't think it would have to save that anyway. It could find one when a game is started/loaded, and if necessary re-evaluate that choice periodically.

We already have a city role that we wedged into the save file, and we have some bigger changes coming.

Another thing:

I think the "explore" AI is pretty poor. Here are some things I'd change in the early game behavior:

1) Find river tiles that are in the fat cross of the capital, and explore those rivers to their ends, as the highest initial priority
2) Explore in an expanding spiral pattern around the capital rather than forge out randomly into the wilderness (as appears to be the case now)
3) Make sure the surrounds of Really Good Spots are explored - rivers, cows, strategic resources, s on
4) Survey more of the boundaries of found civs

This is from the player standpoint - if I automate a couple of scouts I'd like them to do something sensible. But it should work well for the AI civs.

Those sound like reasonable changes, I will put them on the todo list.

-Iustus
 
Interesting behaviour by the AI in my latest game.
Parameters: 12/2 Build, Noble, Standard Size, Fractal Map, Me + 7 AI

I always play Random leaders and this time I got Montezuma. Started on a smallish continent with just me and Frederick. Soon became clear there was not enough room for us both when he founded a city that was going to block me off from much of the land. So war was inevitable.
I razed two of his cities fairly quickly and then paused to amass a Jaguar SOD for his capital. His response...
He kept building and sending out Settler/Archer pairs to refound the closest of the razed cities. I must have razed the city 3-4 times in the same spot. The thing was that the spot he chose was far more vulnerable than other sites available to him, even sites one tile away from his chosen site would have afforded better protection in the form of hills, but he kept on sending those Settlers to certain doom in the exact same location wasting vast amounts of resources and gifting me some welcome XPs in the process.

I realise that building an AI that learns from its mistakes is outside the goals of this project, (having worked on expert systems, constraint engines and limited AIs professionally I know how difficult this is!), but perhaps some limited checking that prevents repeating the exact same mistake every 20 turns would be possible and make the AI appear less suicidal in cases like this.

Two things of note here.

First, there is definitely an issue of AIs continuing to build settlers and send them into danger when in war. Another item for the todo list.

And second, fractal maps. Like most maps with a significant amount of water, the AI has some issues with sea assaults. This is another thing on the todo list. There should be a build soon, but it will not address sea warfare.

-Iustus
 
Back
Top Bottom