A Better AI.

First... Thank You for these improvements, the save game compatability, and
your commitment to this project which results in such rapid build releases.


I don't know if this is a bug or just something I haven't noticed before...

Builds 11/24 and 11/26

After making a tech trade with Saladin, relations immediately dropped from Cautious to Annoyed. I gained older techs (Archery, Horseback Riding, Construction, Monarchy) while he gained a more advanced tech (Philosophy). I didn't know if our relations would improve, but I definatly didn't expect them to worsen. I was now only ahead by Machinery; and Philosophy had brought him into the same 'era' as me. Shouldn't relations have at least remained the same?


Screenshots...
Spoiler :



A side note about the game and attached save...
Spoiler :
I was Viking but was unfortunatly isolated by ocean and could only settle two cities pre-Astro. I had no Copper or Iron but I did have Horses. Barbs couldn't spawn on my little islands, and the other Civs couldn't threaten me until Astronomy. So I only had one Warrior in each city. My second city didn't have much potential and so I delayed it to focus on early wonders. I think The Great Lighthouse was the only one I missed. I had founded and adopted Buddhism. I also adopted the Civics of Representation and Pacifism. Great People were arriving every 10-12 turns and most of them I turned into super-specialists. At the time of the save I had 7 of them (including the 2 from GL and 1 from Artemis). After finishing a Temple I completed The Parthenon and went onto building other wonders. I played to the point of learning Liberalism which I used to learn Astronomy so I could finally expand my humble empire.

Fortunatly I had been constructing Galleys between Wonders, and then upgraded all four of them immediatly after learning Astro. By this time I still had only one lone Warrior in the Capital (working on a Settler) and just a Longbow and Warrior in the second city (working on a 2nd Longbow). A couple turns after upgrading the Galleys, Napoleon suddenly attacked with two Galleons full of troops. If I had not been able to sink them he would have surely taken my second city and prolly captured my capital a few turns later. Also fortunate for me was that I was first to circumnavigate the globe, and had built Trading Post before building the Galleys. If not for this extra movement I would not have been able to attack his Galleons. Now I must make the decision to continue my capitals Settler build so I can gain some Iron; or if I should delay the Settler until I build a more Horse Archers and Longbow. I think I will gamble and go for the Iron since Napoleon is sure to have Knights and Macemen on the way. And since this all occured before the Naval Unit fix in the 12/26 build, I can be certain that Napoleon will have no shortage of Galleons :cringe: I also think I will drop my religion so I can improve relations with the other Civs in the hopes that I can ally with a neighbor of Napoleon. With Better AI it is sure difficult to maintain good relations. The goodwill from my recent Tech Gifts have already worn out and everybody 'cept for one backward Civ hate me.

Prior to Better AI, I would have felt reasonably safe in this situation with the Monarch AI. But now I have dropped the difficulty to Prince and am still very worried for my survival. This situation of having no Copper nor Iron, and only having two settlement sites pre-Astro would have been challenging enough for me. But not I am genuinely concerned and I find this to be exciting indeed :goodjob:
 
When you say city defender infantry, they were given the UnitAI of CITY_DEFENDER? If so, they wont attack, ever on their own. They need to be grouped with a city attack stack, lead by a city attack unit, before they will attack.

It was a stack of about 20 Infantry with the City Garrison I promotion, some of them also having Combat I. None had City Raider. As the turns progressed, the stack was augmented with artillery -- don't remember if they had any promotions.

I mentioned this because I've never seen a stack come up and just sit there like that. They would have been more effective had they parked in a city. At the time I thought that they had been stripped from cities to make this "attack" force and that they had not just been wandering around purposelessly. I don't know that for a fact.

EDIT: Forgot to say that there were plenty of friendly cities for them to defend.
 
Thanks for the screenshots. I understand what you are getting at here, but in reality, I think the choice of city locations is pretty good right now, good enough for our 1.0 release. What you are talking about would involve huge changes in how city placement works.
Thanks for the explanation, Iustus. That helps a lot and also confirms my suspicions.

I don't have a huge problem with it as is. And, I completely understand about getting the 1.0 release out. I would, however, appreciate if you would add this to the "wish list" for release 2. :)

Wodan
 
Thanks for the screenshots. I understand what you are getting at here, but in reality, I think the choice of city locations is pretty good right now, good enough for our 1.0 release. What you are talking about would involve huge changes in how city placement works.

How does it work? (This is in 1.61 all the way through 2.08 and Better AI)

Each plot on the map is scored for 'Founding a City' value for each player. Locations that are not revealed yet get a zero score. Bonus resources that are not revealed by techs do not count for that player.

When an AI has a settler, it basically does the following (danger issues aside):

  1. If a civ has zero cities, and it can found on its current plot, it does so, always.
  2. If there is a plot with a non-zero value within 6 in any direction, it sends the settler to the best spot (once it gets there, it will check again)
  3. If it is on the best spot within 6, then it founds a city
  4. If there is no non-zero score within 6, it checks everywhere on the map it can path to, and picks the best spot, weighted by the distance to get there, and sends the settler there. (once it gets there, it will make all the checks again)

Now, what Blake did, is make some huge improvements in how plots are scored. If you think this score is off, we can look into it. But at least for 1.0, I do not think we are going to change the logic of going for the best score.

I agree with Wodan that it would be nice if the AI would build the cities so that they nicely fill the map. And I see how that might be difficult for the AI. Especially since it builds cities one by one without any planning ahead.

I have a suggestion that might help the AI a little and might be possible to fit into the existing code.

What if you gave certain plots a bonus value for continuous borders. What I mean is that if a city would be positioned in such a way that it wouldn't leave unused plots, then it would gain an additional value. This could be done by scoring the tiles bordering (but not included in) the fat crosses of your cities slightly higher than a normal tile of that type. Then a city center plot that would include these border tiles would gain a slightly higher value and thus become more interesting for the AI. If the values would be chosen with care, then it might just work. Of course desert and mountain border tiles should still be valued at 0.

Something similar could be done with founding cities on small islands. Just give the tiles bordering the sea a slightly higher value so that the AI is inclined to build cities on the sea-borders of these islands and make optimum use of the island.

Could that work or do I have the wrong idea about how the AI selects a city founding tile?
 
I agree with Wodan that it would be nice if the AI would build the cities so that they nicely fill the map. And I see how that might be difficult for the AI. Especially since it builds cities one by one without any planning ahead.

I have a suggestion that might help the AI a little and might be possible to fit into the existing code.

What if you gave certain plots a bonus value for continuous borders. What I mean is that if a city would be positioned in such a way that it wouldn't leave unused plots, then it would gain an additional value. This could be done by scoring the tiles bordering (but not included in) the fat crosses of your cities slightly higher than a normal tile of that type. Then a city center plot that would include these border tiles would gain a slightly higher value and thus become more interesting for the AI. If the values would be chosen with care, then it might just work. Of course desert and mountain border tiles should still be valued at 0.

Something similar could be done with founding cities on small islands. Just give the tiles bordering the sea a slightly higher value so that the AI is inclined to build cities on the sea-borders of these islands and make optimum use of the island.

Could that work or do I have the wrong idea about how the AI selects a city founding tile?
A good idea, Roland.

A huge boost should be given to founding a city on the coast (it probably already does this). Thus, coasts will tend to be founded first. That is necessary because otherwise the AI will found on the resources, which will as often as result in huge overlap with the city that has to "fill in" on the coast. As long as the coast bonus isn't bigger than the distance penalty, this should work (otherwise the AIs will settle all along the coasts and ignore the interiors).

And, instead of your idea of contiguous borders (which has problems especially with the capital which might be bigger than the fat cross), how about simply giving a bonus for tiles that are the "right" distance away (5/0, 5/1, 5/2, 4/3, 3/4, 2/5, 1/5, 0/5)?

Wodan
 
This is outside the scope of this project. There are already mods out there that do this. I would encourage the makers of those mods to integrate the Better AI into their mods.

-Iustus

Excuse me. I meant to contribute to the discussion of a problem, not suggest more work for Blake.
 
After making a tech trade with Saladin, relations immediately dropped from Cautious to Annoyed. I gained older techs (Archery, Horseback Riding, Construction, Monarchy) while he gained a more advanced tech (Philosophy). I didn't know if our relations would improve, but I definatly didn't expect them to worsen. I was now only ahead by Machinery; and Philosophy had brought him into the same 'era' as me. Shouldn't relations have at least remained the same?

Quite odd.
Never seen something like this.
I can only think that rank changed that way that hidden negative modifiers kicked in.
Anyways you made a good deal. You can smash him now :D
 
A good idea, Roland.

A huge boost should be given to founding a city on the coast (it probably already does this). Thus, coasts will tend to be founded first. That is necessary because otherwise the AI will found on the resources, which will as often as result in huge overlap with the city that has to "fill in" on the coast. As long as the coast bonus isn't bigger than the distance penalty, this should work (otherwise the AIs will settle all along the coasts and ignore the interiors).

And, instead of your idea of contiguous borders (which has problems especially with the capital which might be bigger than the fat cross), how about simply giving a bonus for tiles that are the "right" distance away (5/0, 5/1, 5/2, 4/3, 3/4, 2/5, 1/5, 0/5)?

Wodan

Thank you. I might have been a bit vague by mentioning contiguous borders. I meant contiguous fat cross borders, not contiguous culture borders.

To make it a bit more clear, I made a few screen shots using the world builders to create an example. The city border tiles that could get a bonus would be exactly those tiles that are at distance 3 from a city center and not inside the fat cross of any of your cities. And of course desert and mountains should not get this bonus.
The tiles bordering on the ocean could also use a similar bonus so that the AI fully uses the land placing 8 cities in an area that is large enough for 8 cities instead of placing 6 cities in such an area all around the best resource spots.

The screenshots below show a +1 in the tiles that should get a small bonus according to the above suggestion. The actual bonus to these tiles could of course be very different depending on how high the value of other map tiles are. The effect of being a border tile should be influential but not dominating.

Spoiler :


Spoiler :


Spoiler :


I see that I forgot one +1 on the jungle with resource in this last picture and one +1 in that picture was placed to high in the sea instead of on land. Been placing them a bit to quickly I guess. Sorry. I hope that the idea is still clear.
 
hey all,

quick, stupid question ~ does Blake's .dll file merely need to sit in the custom assets folder or should it be in a sub-folder in that directory?
 
Couple of thoughts.

Founding on a desert is often ideal. This turns an otherwise unproductive tile into a usable tile.

I'm afraid I don't "get" the exactly-3 away... many of the tiles appear to be 4 or more away. Plus, personally I would think 3 away is too close.

Let me see if I can edit your image to what it would be with my suggested algorithm.

Also, the +1 (or +6 or whatever numbers are used) should be determined based upon the relative bonus of other parts of the scheme. +1 might be too small to have an effect.

Ok, here it is. I used a bigger number to show how much priority I think should be given to coast tiles of the proper distance (I used +6 to illustrate this), followed by +4 for coast tiles of slightly less proper distance, and lastly inland tiles of the proper distance. Actually, the inland bonus should be bigger, to give proper precedence when coast isn't even in question. So, instead of 6/4/2 something like 10/7/4 would be good.

Note that all tiles will still be modified by all the other bonuses of the algorithm. Thus, a desert tile should be given a +1, tiles with resources in "range" should be given a bonus, total potential food of each site should factor in, etc. The 10/7/4 is purely the + modification given for coast and "range".

Wodan
 

Attachments

  • Border_bonus_3.jpg
    Border_bonus_3.jpg
    200.1 KB · Views: 110
hey all,

quick, stupid question ~ does Blake's .dll file merely need to sit in the custom assets folder or should it be in a sub-folder in that directory?
Just throw it into the main custom assets.

Wodan
 
After making a tech trade with Saladin, relations immediately dropped from Cautious to Annoyed. I gained older techs (Archery, Horseback Riding, Construction, Monarchy) while he gained a more advanced tech (Philosophy). I didn't know if our relations would improve, but I definatly didn't expect them to worsen. I was now only ahead by Machinery; and Philosophy had brought him into the same 'era' as me. Shouldn't relations have at least remained the same?
Quite odd.
Never seen something like this.
I can only think that rank changed that way that hidden negative modifiers kicked in.
Anyways you made a good deal. You can smash him now :D
I did notice and expected that my Power Graph would increase due to suddenly gaining three military techs. Perhaps this is why our relations dropped even though there was no immediate change to my unit strength? But then three turns later I learned Civil Service and the Power Graph did not rise (I had Machinery). Perhaps that was due to not having Iron for my Beserkers?

I guess it makes sense that I could be viewed as a greater threat after gaining access to Horse Archers and Catapults and so relations would be affected. But it doesn't seem right that it should have this much impact. Especially considering that we were seperated by impassable Ocean and my entire military consisted of only 2 Warriors, a single Galley and 2 Caravels. It would be a very long time before I could muster an offensive force and then actually be able to deploy them upon his shores. My lack of military was only a threat to me. I don't know how the Power Graph is valued or how it affects relations, but I wonder if its not based on realistic threat but rather on an implied threat due to technological access? If this is the case then perhaps this aspect of the game could be refined by placing more importance on actual unit strength. So when a Civ starts amassing units, only then would relations drop accordingly. A builder Civ shouldn't be viewed as a military threat just because it learns techs like Construction and Engineering. And maybee factors like unit proximity and an actual abilty to deploy troops could affect relations as well. A civ with no land or naval access shouldn't be viewed to be the same threat as a bordering civ. So relations with a distant civ wouldn't drop as much as they would with a neighboring civ?
 
Couple of thoughts.

Founding on a desert is often ideal. This turns an otherwise unproductive tile into a usable tile.

I'm afraid I don't "get" the exactly-3 away... many of the tiles appear to be 4 or more away. Plus, personally I would think 3 away is too close.

Let me see if I can edit your image to what it would be with my suggested algorithm.

Also, the +1 (or +6 or whatever numbers are used) should be determined based upon the relative bonus of other parts of the scheme. +1 might be too small to have an effect.

Ok, here it is. I used a bigger number to show how much priority I think should be given to coast tiles of the proper distance (I used +6 to illustrate this), followed by +4 for coast tiles of slightly less proper distance, and lastly inland tiles of the proper distance. Actually, the inland bonus should be bigger, to give proper precedence when coast isn't even in question. So, instead of 6/4/2 something like 10/7/4 would be good.

Note that all tiles will still be modified by all the other bonuses of the algorithm. Thus, a desert tile should be given a +1, tiles with resources in "range" should be given a bonus, total potential food of each site should factor in, etc. The 10/7/4 is purely the + modification given for coast and "range".

Wodan

Clearly we're still talking about different things. You're talking about the total value of a city center tile, while I'm talking about the components that create that total value. The value of a founding point could be something like (all just some made up numbers and made up modifiers):
6 grasslands in fat cross: 12
2 floodplains in fat cross: 6
3 grassland hills in fat cross: 6
bonus cow: 5
bonus incense: 4
3 coastal tiles: 6
2 ocean tiles: 2
3 tiles already in fat cross of other cities: 0
1 desert tile: 0
Bonus: at least 2 production tiles within fat cross (the hills): +2
Penalty: Incense on city plot: -2

Total value of city location: 12+6+6+5+4+6+2+2-2=41
(founding tile is not counted in this valuation and thus implicitely increases the value of settling on desert)

I would like to increase the value of those tiles that are at a distance of exactly 3 of the center tile of an already founded city and not within the fat cross of another city. If you do that, then cities founded at distance 5-6 of your present cities will get a bonus to their valuation because they would contain these border tiles. (With distance, I mean the way that the game calculates distance, i.e. diagonal tiles count as 1.5 distance rounded down.).

With the valuation of tiles as high as in the example above, a +1 bonus to the border tiles might be a bit too low to get the desired effect of the AI not leaving unused tiles inbetween its cities. But I never intended that to be an exact value as I said in my previous post. It was just used in the screenshots as a representation.

In the pictures, I also added a +1 to all tiles bordering the ocean. That was a bit vague as you should only get those +1 valuations when you actually settle there and not when those tiles are inside the fat cross of your city. Sorry for any confusion. And of course that valuation should be even larger to have any influence at all.

I hope that this explanation of my intentions is all clear now. If not, I should maybe create some more detailed screenshots of what I mean.
 
I did notice and expected that my Power Graph would increase due to suddenly gaining three military techs. Perhaps this is why our relations dropped even though there was no immediate change to my unit strength? But then three turns later I learned Civil Service and the Power Graph did not rise (I had Machinery). Perhaps that was due to not having Iron for my Beserkers?

I don't know the mechanics that much just know there is a worserank and a betterrank attitude modifier for leaders but what actually they do i don't know :)

Just was an idea why this anomaly could have happened.

I suppose it compares score rank and by that gives the modifiers. That's just a feeling.
 
I would like to increase the value of those tiles that are at a distance of exactly 3 of the center tile of an already founded city and not within the fat cross of another city. If you do that, then cities founded at distance 5-6 of your present cities will get a bonus to their valuation because they would contain these border tiles. (With distance, I mean the way that the game calculates distance, i.e. diagonal tiles count as 1.5 distance rounded down.).

With the valuation of tiles as high as in the example above, a +1 bonus to the border tiles might be a bit too low to get the desired effect of the AI not leaving unused tiles inbetween its cities. But I never intended that to be an exact value as I said in my previous post. It was just used in the screenshots as a representation.

In the pictures, I also added a +1 to all tiles bordering the ocean. That was a bit vague as you should only get those +1 valuations when you actually settle there and not when those tiles are inside the fat cross of your city. Sorry for any confusion. And of course that valuation should be even larger to have any influence at all.

I hope that this explanation of my intentions is all clear now. If not, I should maybe create some more detailed screenshots of what I mean.
Yes, that helps tremendously. Let me go back and look at your screenshots.

I believe I'm understanding your suggestion, but I'm not understanding the effect. Or, not agreeing with it. Looking back at the 1st screenshot, the plains tile 4n1w of Timbuktu would seem to contain the biggest number of +1 modifiers within the fat cross. Therefore, that would be the preferred new city site. Yet, this is not even on the coast To properly boost a coastal city site, wouldn't we need to assign a +1 to all coast and ocean tiles, in addition to all tiles that are on the coast (which you have already done)?

Also, do you have any comment on my alternate suggestion?

Wodan
 
Using the latest AI, is it normal to have Montezuma send massive SoDs to explore my land? He never attacked. In fact, we were quite close with each other, often pleased or friendly, depending on my civics.

I regret I have no screenshots, but I often had large (six or more units) Aztec stacks simply wandering aimlessly through my empire. Catapults, trebuchet, macemen, cavalry; you name, I saw it. It looked like a normal SoD, but it would just content itself to garrison inside my cities or walk around. I've never seen this behavior before. Usually, when they explore, they just send one or two units, in my experience.

I never noticed anyone else doing this. Just Montezuma, with whom I shared a small border.
 
I'll confirm that something is amiss with the "stack attack" code. I'm playing this in multiplayer mode with a friend (11-26 release) and stack attack works for me but it does not for him. We've played countless games with each other before and I can pretty much say that this is not user error. He selects all units, chooses to attack the city, then only one unit attacks. If he captures the city with that one unit, all units move into it.

Not sure if we installed the DLL in the wrong spot, but both of us have placed it in the following location:

C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Warlords\Assets

We renamed the original DLL that was there, just in case we need to revert back to it.
 
Not sure if we installed the DLL in the wrong spot, but both of us have placed it in the following location:

C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Warlords\Assets

We renamed the original DLL that was there, just in case we need to revert back to it.
Here is a direct quote from the instructions:

"Place the BetterAI folder in the Mods folder and load as a mod, or place the CvGameCoreDLL.dll file in your CustomAssets folder so that the mod is always in effect (recomended)."

My suggestion would be to follow the instructions. ;) Undo what you did, and then put the new file into the CustomAssets folder (not the assets folder).

Wodan
 
Yes, that helps tremendously. Let me go back and look at your screenshots.

I believe I'm understanding your suggestion, but I'm not understanding the effect. Or, not agreeing with it. Looking back at the 1st screenshot, the plains tile 4n1w of Timbuktu would seem to contain the biggest number of +1 modifiers within the fat cross. Therefore, that would be the preferred new city site. Yet, this is not even on the coast To properly boost a coastal city site, wouldn't we need to assign a +1 to all coast and ocean tiles, in addition to all tiles that are on the coast (which you have already done)?

Also, do you have any comment on my alternate suggestion?

Wodan

As said in my previous email, I should not have put those +1 valuations on the land tiles bordering the ocean. There should just be one big +5 or something if you found a city on the coast.

I think that I will make a new screenshot explanation tomorrow with proper valuations that could better demonstrate the effect.

I perfectly understand your suggestion (at least I think I do). It's the way a human looks at the map, so it's actually easier to understand I think. I was trying to stick with the valuation method that is apparently used by the AI (which is a quite understandable way fot the AI to do it). I guess that you would give a valuation bonus to the city when it is at a certain distance. However, that is not exactly the same as trying to minimize the number of lost tiles. The distance to 2 or 3 cities would give all kinds of bonusses at various tiles that are at 5-6 tiles distance but I bet I can make examples where many tiles will still be lost.

Just imagine a square based setup with 3 settlements at the corners of the square of cities are already build. The fourth city would get a big bonus to be build at the fourth corner. But that would leave many tiles in the center between the four cities unused.

It's actually difficult to find a balance between lost tiles and overlap between cities. Since this is difficult for a human who can plan many cities ahead. it will be very hard for a computer to do a reasonable job. But I agree that something must be done to stop the cases where the AI builds 1 (good) city on an island that can easily sustain 3 (fairly good) cities.

Let's see how you like my screenshots of tomorrow. You can then use a version of your method on them and we can compare the results.
 
Top Bottom