Better than BTS

I was playing a game with version 0.1 of this patch today and I stumbled across some very odd city placement decisions by the AI on my island. I honestly can't say whether this is something caused by the 3.17 patch, this v0.1 patch or whether it's something that has always been in the game. Anyway, after wiping out the Mongolians and keeking their capital, Montezuma seemed to obsessively surround this new city of mine with his own new cities. Over not many turns, there were 3 cities founded right on this city's border and two of these cities had their own borders pushed back fairly quickly too. If you look at the picture, you see his capital is far over to the right.

I seem to recall someone saying the AI tended to try and make its empire more concave, but that is through conquests right? (Not city placement?) What Monty has done appears to be super aggressive expansion towards me, to the point where it's stupid.

Random personalities, nonAggAI are settings that could be relevant. Monarch difficulty.

1 city was defended with a single chariot, another with a single spearman, and another with 2 archers. All on flat ground too. Is this perhaps a result of me playing standard AI instead of Agg AI for once? If this is how a normal AI normally plays then it's pretty disappointing.

I don't know if you guys think this is an issue but something just did not feel right in this game so I was wondering whether it was this patch.

Spoiler :
attachment.php
 
We haven't looked at city placement yet and none of the closeness changes would affect city placement ... they're only calculated between cities so it's impossible for it to affect choices before the city is built.

Certainly keep a save of the game from this time (preferably before the cities were founded if you have one). I'll create a thread about in game debugging and you can go back and explore why the AI made the choices it did. It takes a little bit of time mousing around but in debug mode you can see exactly where the AI wants to place a new city at any point in time.
 
Version 0.11 is posted with two changes.

First, the first addition of Solver's unofficial patch in included. This will be a running target as there seem to be several potential issues being worked out.

Second, I removed the unneeded variable saving from AIAutoPlay ... the good news is that v0.11 is savegame compatible with Vanilla BTS 3.17, the bad news being that it is not save compatible with v0.1. My apologies for that for those of you with v0.1 games going, I shouldn't have included the variable saving here in the first place. (It's only needed to prevent an exploit in my Revolution mod)

I also updated the install instructions which now specify two ways to use Better BTS AI ... use it as a mod if you just want to try it or maintain online play compatibility with those who don't have it, replace the main BTS files if you want the changes to apply for Firaxis BTS scenarios and many other mods as well.
 
Anyway, after wiping out the Mongolians and keeking their capital, Montezuma seemed to obsessively surround this new city of mine with his own new cities. Over not many turns, there were 3 cities founded right on this city
Great that you are examining the better bts build 0.11 with so much detail. The point thus far is to examine under the microscope why the AI declares war in the first place. There have been no other major changes. Did Montezuma have a legitimate case for wiping out the Mongolians?

So far better BTS AI is all about the better behaviour of AI war declarations. Look for anything stupid happening in that and look closely for other ripple effects. Distant war declarations may be perfectly valid for diplomatic reasons so filter those out in your analysis.

For example there should be more border conflict which has not been fully tested and initial stack attack strength might need tweaking although so far so good except for "aggressive ai" I perceive.

Another thing to look out for is border conflicts that have been triggered from mutual friendly or pleased relationships and that don't seem right that sort of thing.

I know what you mean, I used to be an aggressive ai player myself, but standard is good now. I'm getting whipped on monarch standard aggression sometimes now. Cool.

Cheers

PS) Save game unusual scenarios for sure.
 
I looked into the chances for Friendly/Pleased war declarations a little more. In AI_doWar there's a odds check against AI_noWarAttitudeProb before the startWarVal is even computed ... each AI has their own % of the time they will not even consider a DOW for certain attitudes specified in XML under <NoWarAttitudeProbs>. None of the AIs will initiate a war when they are Friendly to you which is good. About half will also never start a war against you on Pleased, for the rest the odds are mostly 10% with a smattering of 20%.

The chances for a Pleased declaration of war on a neighbor if the 10-20% chance check passes are now much higher with the Closeness fixes, but the initial check makes this still a fairly rare event. On aggressive AI those 10-20% chances are more like 20-30% and the differentiation in startWarVal for close vs non-close civs means you really can't really trust your neighbors unless they're Friendly or engaged in other wars.

When the AI is Cautious towards you the odds of checking startWarVal range from 80% to only 10% for Sitting Bull. This is the scenario where most of the changes in behavior will occur I think, the AI will pick a war against a neighbor they're Cautious towards over a distant Annoyed much more often now. On Aggressive AI they will even be fairly likely to declare on a neighbor they're Cautious towards over a distant Furious.
 
We haven't looked at city placement yet and none of the closeness changes would affect city placement ... they're only calculated between cities so it's impossible for it to affect choices before the city is built.

Certainly keep a save of the game from this time (preferably before the cities were founded if you have one). I'll create a thread about in game debugging and you can go back and explore why the AI made the choices it did. It takes a little bit of time mousing around but in debug mode you can see exactly where the AI wants to place a new city at any point in time.

All saves and autosaves since 4000BC now backed up! :)

(I happen to keep 400 autosaves at 4 turn intervals before they're overwritten :D)

Version 0.11 is posted with two changes.

First, the first addition of Solver's unofficial patch in included. This will be a running target as there seem to be several potential issues being worked out.

Second, I removed the unneeded variable saving from AIAutoPlay ... the good news is that v0.11 is savegame compatible with Vanilla BTS 3.17, the bad news being that it is not save compatible with v0.1. My apologies for that for those of you with v0.1 games going, I shouldn't have included the variable saving here in the first place. (It's only needed to prevent an exploit in my Revolution mod)

:( I'll have to stick with v0.1 for now then because this game will take a while. Epic speed large map and all!

Great that you are examining the better bts build 0.11 with so much detail. The point thus far is to examine under the microscope why the AI declares war in the first place. There have been no other major changes. Did Montezuma have a legitimate case for wiping out the Mongolians?

So far better BTS AI is all about the better behaviour of AI war declarations. Look for anything stupid happening in that and look closely for other ripple effects. Distant war declarations may be perfectly valid for diplomatic reasons so filter those out in your analysis.

For example there should be more border conflict which has not been fully tested and initial stack attack strength might need tweaking although so far so good except for "aggressive ai" I perceive.

Another thing to look out for is border conflicts that have been triggered from mutual friendly or pleased relationships and that don't seem right that sort of thing.

I know what you mean, I used to be an aggressive ai player myself, but standard is good now. I'm getting whipped on monarch standard aggression sometimes now. Cool.

Cheers

PS) Save game unusual scenarios for sure.

Actually you may be disappointed when I point out it wasn't Monty who declared war on the Mongolians; it was I. But I kept their capital city and Monty in his expansion mindset built cities way too close IMO to this new high culture city (this is by the time the Mongolians were wiped out). By the way don't you love it when you see an enemy GG born in the city you're besieging! The next turn when you caputre the city you find a nice little settled GG. It's great to have the AI do the work for you! :lol:

Anyway, I'll certainly keep an eye out for all war declarations and let you know of anything interesting or odd.
 
I looked into the chances for Friendly/Pleased war declarations a little more.

Beautiful level of detail. Thanks!

By the way, I've set up a new sub-forum for discussing AI war strategy and tactics in case you want to use that. It's entitled:

[BTS] AI Strategy - war
http://forums.civfanatics.com/showthread.php?t=279953

[BTS] AI Tactics - war
http://forums.civfanatics.com/showthread.php?t=279955

A reproduction of your information Jdog is going straight in there now...
Cheers.
 
By the way don't you love it when you see an enemy GG born in the city you're besieging! The next turn when you caputre the city you find a nice little settled GG. It's great to have the AI do the work for you! :lol:

Ya know, that's a scenario where the AI could be improved! Be careful what you point out around here ... :p
 
Ya know, that's a scenario where the AI could be improved! Be careful what you point out around here ... :p

It would appear Solver has just put this feature into his patch! :)

I finally finished a game with v0.1. Sadly I didn't witness very many wars at all. However the wars that did take place were always between neighbouring civs except for the one time I was attacked from the sea by the Mayans. As usual, the escort fleet did not bother to do anything like reduce the defenses on the town, so several infantry were just suicided into a 60% city-on-a-hill machine gun. The AI doesn't even seem to pillage fishing boats anymore.

No major issues to report. :goodjob:
 
As per request of Solver, and for the interest of the authors of this mod, I have attached to this post the replay file from the game I finished in v0.1 of this patch.

Unfortunately due to the nature of the map there weren't terribly many war declarations so I'm not sure how useful a test case this game was... In the very least it showed AIs will still declare war on overseas civs. And most war declarations were on neighbours so it certainly didn't really break my expectations.

Settings:
nonAgg AI, large map, epic speed, random personalities, all vic conditions enabled, Monarch diff.

Notes:
-The war in ~1932AD between Brennus and Pericles was me bribing Brennus into war because Pericles appeared to be going for culture vic and I wanted to stall him with little effort on my part. :) This was the only war I ever bribed someone into.
-The only across-ocean war was when Pacal declared war on me fairly late in the game. He attacked one of my west cities but died horribly. It was only a few turns before he was happy to pay a lot for peace.
-I noticed no one ever bothered to capture the barb cities in the north west. I think Hannibal had landed some units before the game came to an end, but it surprised me a bit. Is this something that is possibly affected by the changes to the code?

Any other queries about this game I can answer happily, though from tomorrow I'll be unable to access the game for about 3 weeks. I'll have to recall details from memory.

P.S. lol at the shape of my empire at ~1350AD. :lol:
 
Interesting. Actually Qin was on a separate landmass, too, and he did declare war as well. This is good and I like what I'm seeing.
 
I've finished merging in the unofficial 0.17 with new changes based on the Naval AI discussion and will post a new version after a little testing this evening.

I removed the earlier change to demand for building of transports ... under most circumstances it did nothing as the bLandWar and bAssault flags are mutually exclusive (they represent different sets of AreaAIs). That section of code only fires when the AI is running AREAAI_ASSAULT, which should only trigger when the AI's only war is against a player with no cities in the area. The reduction to transport demand before galleons was therefore actually somewhat detrimental in the very rare circumstance of inter-island war before galleons. I brought this change over from my Revolution mod where I would often see the AI running AREAAI_ASSAULT in the early eras and therefore sometimes pumping out galleys that it would never use ... it turns out this was an issue with poor support for minor civs in the SDK. Minor civs are a common occurrence in Revolution and the AI was preparing to invade minor civs on faraway continents that it had never met. Now that I understand the real cause of the galley spam problem I saw a while ago (and AreaAIs a little better) it's clear that change should be removed.

Anyway, here's what the new changelog will be, I updated the format so it's a little easier to see what's going on:

Better BTS AI Changelog
_________

Bugfix
- Fixed bug in player closeness calculations causing the AI to be blind to its actual proximity to other players
- Fixed bug with needed defenders where the AI would choose to defend a recently captured holy city less than a normal city

War strategy AI
- Modified how closeness is used for determining who to attack, different settings for regular and Aggressive AI

Naval AI
- Modified bombard behavior. Priority remains on supporting player's ground troops, if none then consider supporting other troops with common enemy and spreading out stacks to increase reach of blockade.

Barbarian AI
- Barb ships will now often blockade cities for a few turns before moving on if they have no nearby targets
- Barb ships trapped by ice or around 1-tile islands are now removed so more can spawn

General AI
- Modified city closeness calculations to use population from both cities, not just pop of the other city
- Created functions for determining when cities share the same water area (lake, ocean)
- Partial implementation of a new A* solver for determining closeness, does not yet affect calculations

Debug
- Added AIAutoPlay mod
- Modified debug mode output to show relevant information for these developments

Better BTS AI also includes Solver's unofficial 3.17 patch version 0.17.
 
Wow cool. As far as I'm concerned the war strategy in the middle ages gets a big tick. The question is how to best test the naval changes....Hmmm. Looks like worldbuilder will be the place to hang out. Thanks for the efforts!
Cheers.
 
Hey guys, it's awesome that you've come in to take the reigns of this project, which I'll be following closely. I thought I'd point out another mod that has made some changes to the AI - Seven05's World Piece. In the first post of the thread, he says:

AI tweaks
The AI has undergone several changes involving countless tweaks to unit, building and technology changes. They have been made smarter and more aggressive towards each other, not just the human player(s). And, perhaps most importantly, the majority of their bonuses to production and research have been removed including a few well hidden bonuses.

The AI diplomacy has been adjusted with the major change in determining if they'll ask you to join a war or stop trading with another civ. In the case of joining their war they'll only ask you if their relations with you are better than your relations with their enemy. Their requirements to ask you to stop trading are based on your relationship with them, this value can be different per leader and mirrors their required attitude before they'll accept a request from you to stop trading with another civ.

The AI's workers (and your automated workers) should no longer attempt to improve tiles outside of the workable area (fat cross) of your cities. There are a couple of exceptions to this- they will improve tiles with resources on them if they need the resource and they will continue to build routes in tiles that can't be worked.

I know you guys are focusing on war behavior right now, but it might be useful to see what other changes he's made to improve the AI (I particularly like the diplo changes). Later in the thread he mentions wanting to create goal-based behavior for the AI, which I think would be very relevant to this project. I don't think he's updated in a while due to real life, but there's a link to his mod's thread here: http://forums.civfanatics.com/showthread.php?t=254299
 
So, does anything I did with the AI in the unofficial patch seem useful to you? :)
 
I put it all in for 0.2, definitely just based on the code many of the pieces seemed good. Moving ships and planes out of seriously threatened cities is a desperately needed behavior, I like what you have now as a first step but I think it could be improved.

As you have it now it looks like if I land a warrior next to a heavily defended city all the AI ships will leave ... for AI-AI battles this is probably okay, but the ease of flushing out the enemy ships could be exploited. It would be better to have more of a sense of the threat posed ... maybe using:

Code:
int iOurDefense = GET_PLAYER(pPlot->getOwnerINLINE()).AI_getOurPlotStrength(pPlot, 0, true, false);
int iEnemyOffense = GET_PLAYER(pPlot->getOwnerINLINE()).AI_getEnemyPlotStrength(pPlot, 2, false, false);

if( iEnemyOffense > iOurDefense/2 )
{
   move away behavior
}

The ratio of iOurDefense can be set to determine how optimistic/pessimistic the ships are. Dividing by 2 is pretty pessimistic but get___PlotStrength routines aren't perfect predictors of the odds of victory/defeat. BTW, in debug mode the game will give you the ratio of iEnemyOffense to iOurDefense for any plot while holding down ALT, it has the format "Danger: %.2f (%d/%d)" and is red.

Also, just a note that AI_getPlotDanger has the benefit of counting whether the plot is on/near a border to determine danger, which the above doesn't do ... however, it only adds the border threat if the plot is not a city, so in all the places you're using it just returns the number of nearby enemies I believe.

Right now you moved some Firaxis code for planes earlier in the AI routine, definitely a good idea but they will still only move from their base when it's threatened if there is no defender. I would say planes should be more optimistic than ships since they can injure the incoming units and ships cannot, but I would still use an approach like the above but maybe without the / 2 even up to 4/3 perhaps. When the danger fraction is above 1/2 and the planes choose to stay it might make sense for them to prioritize striking the incoming units, right now defensive air units will do airstrikes first but attack ones should as well in this situation.

Since we're on the subject, the current air unit AI doesn't take into account the player's AreaAI ... if the player is playing defense then the behavior of attack air units could be a bit different, perhaps prioritizing air strikes some fraction of the time. Currently, the priority for attack air units is to support an offensive using AI_airBombDefenses over possible running defensive airstrikes. Certainly when their base is threatened defense should take priority. But now that I look it doesn't seem like CvUnitAI::AI_airStrike currently is written with defense in mind really either, there's no boost in value if the potential air strike victim poses any threat ... from the looks of things a plane would be far more likely to airstrike an empty transport than the stack of troops it had just left next to the plane's base .... that's something else which should be looked at.

One last comment: all of this code so far is contingent on the ship/plane being in a city ... this should be updated to take forts into account by using pPlot->isCity( true ). In fact, all uses of CvPlot::getPlotCity() in these kinds of situations should be double checked since it ignores forts.

I haven't really analyzed the other changes you made ... not settling great people in endangered cities is definitely a good one (sorry to spoil the fun PieceOfMind :p) but again could perhaps benefit from some of the same ideas as above.
 
Yeah, I've thought about it - my code does make ships rather easy to scare away but the Ai doesn't really have good routines for evaluating danger and relative strength of enemy stacks. I'm very familiar with the debug mode ;), which is part of the reason why I'm dissatisfied with those AI estimates.

The considerations I added for planes are actually new, didn't move them from the existing code. But I don't think planes should be more optimistic. The check there checks for danger within a 2-plot radius of the city. Planes should get out if the enemy has broken through this close... yes, they can hurt incoming units but if they do, they have to stay in place and so will die anyway if the city is taken. Sure, it would ideally use those strength considerations, it'd be great if that algorithm can be improved.

As for forts... I just forgot about those :D
 
I simulated a full game with Better BTS AI 0.2, the replay is attached :cool:

It's a Large Terra map with fairly standard settings (not Aggressive AI). Shaka went on to win a diplomatic victory in 1980 just a couple turns after this replay ... since I was automating, I had to go back and retire right before he won to get the replay. He had like 6 vassals which is what put him over the top for Diplo, plus he was most of the way to a Domination victory. Right at the end he starts a true World War by declaring on 2nd place Asoka who had two vassals.

BTW, it says it took 10 hours, but it was open sitting there doing nothing in the background for most of that ...
 

Attachments

Back
Top Bottom