Welcome to Better BTS AI

jdog5000

Revolutionary
Joined
Nov 25, 2003
Messages
2,601
Location
California
Welcome to the forum for discussions of the Better BTS AI mod!

Better BTS AI is the BTS follow-up to the great work by Blake and Iustus on the Warlords' AI. This project started with discussions on how to fix a bug in the calculation of the "closeness" between empires which is used by the AI in determining which enemy to attack. From that humble beginning the rest of this effort was spawned, we have learned quite a lot and had many good discussions since then!

Goals of the project

The main goal of this project is to make BTS more enjoyable for players looking for a challenging strategy game experience. We have a fantastic base to work with, as BTS is already quite good, particularly through the Middle Ages. There is, however, more work to be done to craft an AI which can "stand the test of time."

This simple goal has a lot of elements to it which fall under the broad category of "Better AI." Here are the main specific ways this project can make BTS more fun as I see them:

  1. Fixing bugs or unintended behavior
  2. Fixing other illogical AI behavior which breaks immersion
  3. Increasing the AI's ability to perform coordinated actions
  4. Improving the AI's handling of its economy and production
  5. Enabling the AI to better play for the win within the bounds of role playing

There are a lot of different aspects to the game which can fit under these headings. To give a better idea of how we are pursuing these different avenues, I'll describe what we've done so far and what is on the horizon for the Better BTS AI project.

A sample of what we've done so far

Here are some broad descriptions of some of the more important changes we have made so far, in roughly chronological order:

  • Closeness bug: Fixed AI calculations of the closeness or proximity of another empire to its borders. Previously, player A actually calculated how close enemy B's cities were to enemy B's cities, not to its own cities. This kind of subtle logic bug is difficult to track down, but can have wide ranging effects on how the AI makes decisions. The AI now appropriately calculates the proximity of enemy cities to its cities and the calculations of which enemy to attack had to be tweaked to balance the corrected numerical values returned by closeness calculations.
  • Retreating of sea/air units: This new behavior was started by Solver in the unofficial patch and has been adapted and repeatedly tweaked in this mod. Basically, the AI will now move ships and air units out of threatened cities so they are less likely to be lost. Air units in lightly threatened cities now run defensive bombard missions to attack the threat, only pulling out when the city is highly threatened (some fighters will stay behind to help defend the city).
  • Air defences: In vanilla BTS once a fighter decides to air patrol in a city, it will remain air patrolling their indefinitely unless the city is attacked from the air. We have modified this behavior so that the AI is more flexible and will shift its fighters to cities which need them. This required designing a consistent rule so that fighters would stick in threatened cities and run the needed air patrol missions, as each time a fighter rebases is a lost turn of air patrol. In addition, when the AI has extra fighters it will now use them to clear out enemy defensive fighters so its bombers survive longer.
  • Bomber basing: The BTS AI used bombers which happened to be nearby to support its stacks in enemy territory. Now, it also chooses where to base its bombers according to where it have land troops attacking. This is a one example of improving the coordination of actions between different pieces of the AI to make it far more potent in war.
  • Air combat mechanics: This is the one change we have made so far which really changed the mechanics of the game, not just the AI's choices. Air combat now works a bit more like land combat, making veteran air units more valuable and longer lived. This makes air combat behave more in line with the player's expectations based on the importance of experience in land combat. This change can also be disabled in GlobalDefinesAlt.xml.
  • Naval invasion logic: Successfully launching naval invasions requires coordination between city production, transport and escort motion, and loading of groups of land troops. Reworking the AI's invasion system has been one of the primary pushes in this project so far. The biggest addition is the ability of the AI to reinforce its initial invasion fleet with subsequent waves, previously it basically waited to build up a brand new full invasion while its initial invasion force was whittled away. When the AI does build up enough troops to launch a second invasion (instead of just a reinforcement), it now sends the second wave near the first wave instead of often spreading out to two distinct fronts. The AI can also now time multiple invasion flotillas to show up at nearly the same time. If the AI has no land path to its enemy, it will now use the invasion production logic and load its troops into transports, previously the enemy would see at most one initial invasion wave. A related important new behavior for the AI is the ability to pickup troops which get stranded on islands or on other places around the map, something which previously could break immersion. Also, a bug where AI transports would loiter trying to pick up the units they already had onboard has been fixed, this previously could cause partially full transport flotillas to get stuck indefinitely on small islands.
  • Voting for peace: The AI's voting on AP/UN resolutions for peace has been improved to better take into account how the AI is doing in war. Other new considerations for AIs that are third parties to the war are whether they want the war to continue for selfish reasons, because they share a war with one side or are about to join the war.
  • Privateer production bug: Fixed a bug blocking the main AI logic for producing Privateers. Previously a check for whether privateers were obsolete was made using unit class type where unit type was intended. As a consequence, the function never actually checked any naval units and always blocked the logic to produce privateers. The AI now builds Privateers but since they haven't really done it before, more work remains in making sure they get value from these units.
  • Attack stack tactics: AI attack stacks will now minimize the number of turns they spend in enemy territory or along enemy borders. This increases the surprise factor for the assault and reduces losses from counter attacks. Attack stacks with overwhelming odds will now skip bombarding and attack directly, sacrificing perhaps a couple of units for keeping the enemy from having time to reinforce the city.
  • Vassals prepare for war: Vassals of AI players will now begin their own preparations for war when their master does, meaning they'll have troops available both to defend themselves and contribute offensively when war breaks out. Vassals of human players will default to building more offensive units generally and you can also signal to the AI your war plans by pressing SHIFT+ALT and clicking on enemies in the scoreboard. This toggles your warplan state against enemies so you can get the same benefits during war from your vassals as the AI does. Vassals will now even be able to participate in naval invasions which require a fair amount of buildup, don't be surprised to see them send their troops to the cities you've captured on another continent and set out to make conquests of their own.
  • Settler bug: In vanilla BTS, if there were sites where the AI wanted to settle cities available on the same continent as the settler unit, the AI would never load the settler into a transport. Since AI settlers will not move through other player's territory even with open borders (fixing an annoyance from Civ3), this would stunt the AIs growth if it was cutoff from those potential city sites by another player's territory or mountains. The AI now properly loads settlers into transports if they cannot reach the target location over land.
  • Capitulation decisions: Tweaks and adjustments to both sides of the capitulation decision making process, so that war mongers will sometimes annihilate enemies instead of seeming to always accept capitulation. AI will, however, still always accept capitulation when there's a danger of the enemy capitulating to someone else or of another player gaining valuable land from the mutual enemy. Fixed issue where small-size of previously capitulated civs would influence when a civ losing a war would capitulate.
  • Empire defense: Added greater awareness of how wars are going for the AI. When the AI now feels it is losing, it will put an empire wide emphasis on defense and counter attackers to try to hold on.
  • Cottage/Workshop cycling: Fixed some AI valuation bugs which led to a propensity to alternate tile improvements between cottages and workshops. These bugs would block some AI cities from getting to Towns, thus hindering the civ's tech rate.

As mentioned, this is not an exhaustive list but the more important pieces done so far. To see a list of all the changes made to date, check out the thread for the most recent version or see the change log in the download.
 
Future directions for the project

The bulk of the focus through version 0.6x was on unit action decisions and city construction to support naval invasions. Going forward, the focus will shift to cities and grand strategy, with particular emphasis on how to make the AI run a better economy and how to get the AI to coherent play towards a victory condition. Specific targets include making better choices for placement of national wonders, stopping workers from oscillating between cottages and other improvements, and having worker improvement decisions influenced by a city's special bonuses.

Version 0.9
- Expand AI strategies for going for victory
- Refine central wonder decisions for national wonders to have AI create better specialized cities
- Escorts for stranded naval pickup
- Stop extra transports chasing a flotilla that's already heading for an assault

Version 1.0
- Opportunistic war plans to allow low power AI players to team together to start war against stronger enemy
- Attack stacks pick sea vs land path based on approximate length
- "Early" rushes from aggressive AI
- Central planning: Switch wonder and other large project decisions from individual cities to a centralized auction system

Further directions:
- Active defense: have AI more readily shift extra defensive units to threatened cities
- State religion logic
- Have AI press advantage when winning war
- Picking a naval invasion launch point
- Give AI better understanding of connectivity of map using graphs with cities at the nodes
 
I'd like to see the AI do a few things:

  • Make better use of chokepoints. I tried doing this myself, but I couldn't think of a good way to calculate it without putting a real strain on system resources.
  • Build its navy according to its needs. If the AI has a lot of far-flung possessions on multiple islands and continents with valuable resources on them, they should build a lot more ships than a country with all of their possessions on one continent and more effectively distribute their naval power to the most vulnerable locations. Civs who are also alone on their continents should place a great emphasis on the navy since it'd be their first line of defense and a necessary means of expansion to other continents.
  • It would be interesting if the AI used more deception. If they sent an initial force against one city to force other players to divert units to that city, and then move their main force against their real target for example. I haven't really explored this enough to decide whether this is really feasible.
  • The AI should wage better economic warfare. The AI needs to target an enemy's resource supplies more effectively. For example, I noticed that in calculating a city's target value, the AI takes into account its own need for the resource, but it doesn't take into account the enemy's need of the resource.

I'll add more as I think of them.
 
Hey DPII, long time no see!

Thanks for posting some good ideas ... one thing the AI really doesn't handle well is when it has ports on two oceans or two sides of a continent. It's embarrassing sometimes really, if an AI owns a long skinny continent and its chosen enemy can only be reached from one side, there's a 50% chance that when it decides to launch an invasion it will be sending its boats all the way around the continent ... so yeah, distributing the navy has gotten a bit better already, but much remains to be done.
 
Hey DPII, long time no see!

Thanks for posting some good ideas ... one thing the AI really doesn't handle well is when it has ports on two oceans or two sides of a continent. It's embarrassing sometimes really, if an AI owns a long skinny continent and its chosen enemy can only be reached from one side, there's a 50% chance that when it decides to launch an invasion it will be sending its boats all the way around the continent ... so yeah, distributing the navy has gotten a bit better already, but much remains to be done.

Shouldn't you be able to use the function for determining the nearest city or path generation to determine if the city is closer to the enemy area the fleet wants to reach?
 
Could something be added to the naval invasion routine such that an initial small scale plan is used. For example, given a primary target city A and a secondary target city B, which is >= k distance away (to force a split in the defender's forces) the attacking AI could split its forces into x groups (say x = 3 for this example). Then you could have a probabilistic distribution on possible invasion strategies:
(1) wp 0.30 -- Feint: group 1 -> city B -- 5 turns later, groups 2-3 -> city A
(2) wp 0.30 -- No Feint: groups 1-3 -> city A
(3) wp etc -- more elaborate designs as desired, with different targets and different delays to keep the human guessing -- is this the main invasion point or not? ala Calais or Normandy, WWII
 
The Principles of War are always a good wish list for any AI behavior: (many of these already been implemented in the AI to some degree...)

Objective – Direct every military operation toward a clearly defined, decisive and attainable objective. The ultimate military purpose of war is the destruction of the enemy's ability to fight and will to fight.

Offensive – Seize, retain, and exploit the initiative. Offensive action is the most effective and decisive way to attain a clearly defined common objective. Offensive operations are the means by which a military force seizes and holds the initiative while maintaining freedom of action and achieving decisive results. This is fundamentally true across all levels of war.

Mass – Mass the effects of overwhelming combat power at the decisive place and time. Synchronizing all the elements of combat power where they will have decisive effect on an enemy force in a short period of time is to achieve mass. Massing effects, rather than concentrating forces, can enable numerically inferior forces to achieve decisive results, while limiting exposure to enemy fire.

Economy of Force – Employ all combat power available in the most effective way possible; allocate minimum essential combat power to secondary efforts. Economy of force is the judicious employment and distribution of forces. No part of the force should ever be left without purpose. The allocation of available combat power to such tasks as limited attacks, defense, delays, deception, or even retrograde operations is measured in order to achieve mass elsewhere at the decisive point and time on the battlefield.

Maneuver – Place the enemy in a position of disadvantage through the flexible application of combat power. Maneuver is the movement of forces in relation to the enemy to gain positional advantage. Effective maneuver keeps the enemy off balance and protects the force. It is used to exploit successes, to preserve freedom of action, and to reduce vulnerability. It continually poses new problems for the enemy by rendering his actions ineffective, eventually leading to defeat.

Unity of Command – For every objective, seek unity of command and unity of effort. At all levels of war, employment of military forces in a manner that masses combat power toward a common objective requires unity of command and unity of effort. Unity of command means that all the forces are under one responsible commander. It requires a single commander with the requisite authority to direct all forces in pursuit of a unified purpose.

Security – Never permit the enemy to acquire unexpected advantage. Security enhances freedom of action by reducing vulnerability to hostile acts, influence, or surprise. Security results from the measures taken by a commander to protect his forces. Knowledge and understanding of enemy strategy, tactics, doctrine, and staff planning improve the detailed planning of adequate security measures.

Surprise – Strike the enemy at a time or place or in a manner for which he is unprepared. Surprise can decisively shift the balance of combat power. By seeking surprise, forces can achieve success well out of proportion to the effort expended. Surprise can be in tempo, size of force, direction or location of main effort, and timing. Deception can aid the probability of achieving surprise.

Simplicity – Prepare clear, uncomplicated plans and concise orders to ensure thorough understanding. Everything in war is very simple, but the simple thing is difficult. To the uninitiated, military operations are not difficult. Simplicity contributes to successful operations. Simple plans and clear, concise orders minimize misunderstanding and confusion. Other factors being equal, parsimony is to be preferred.
 
Some contributions on economy

Build queueing
I've seen the AI build wonders and spaceship parts in low production cities, greatly reducing their buildspeed. This makes the AI far less competent at space race, and less effective at grabbing wonders. The algorithm for deciding where to build a wonder should work with empty build queues, exempting wonders and spaceship parts.

City Specialisation (CS) & National Wonders (NW)
As it is now, I've seen tons of AI build Moai in their capital (probably because it's the earliest NW), with hardly any benefit.
For players, CS and NW are closely related to terrain improvements and the terrain itself. That leads me to believe the only way to improve the AIs economic competency requires interdependance between the four, which seems to be lacking now.

Terrain Improvement (TI)
Hills need mines when food is plentiful, windmills when food is scarce, the AI does this. All other terrain is a disaster, and AI workshops over towns without ever looking back, and never gets the potential out of their terrain. This is closely tied to CS&NW, since difference cities should have different terrain inprovements.
If improving terrain is tied to the governor the player too can select, improving the governor first, then giving the AI a production/commerce city ratio based on their personality might be a huge step forward.

Improving CS&NW and TI;
How does a human player do this; The player would rank cities for production and commerce based on the terrain when reaching a set number of cities, in two seperate lists. Then divides them on a preset ratio decided by their personality, then adheres to this template, improving them and constructing infrastructure to that end.

e.g. city A gets a rating with two variables, [A,1,3] would be the best available production city, and the third best commerce city.
Say you have 6 cities {[A,1,3],[B,2,2],[C,3,4],[D,4,1],[E,5,6},[F,6,5]}.
You'll devide them 50/50, starting, because I feel like it, with commerce. Choose best commerce, then best production, then commerce again, and so on. You'll end up with D, B and F as commerce cities, and A, C and E as production cities.


So, how could this work for an AI? I'm not familiar with the game mechanics, so I might be very wrong here. If the AI uses the governor to improve land, running an algorithm to achieve the ranking and dividing should improve their use of land. Since it's a relatively rare operation, and probably wouldn't take place for all the AI at once, it shouldn't make the game run smuch slower.
There remains the problem of adding cities afterwards, or losing cities. There's probably a solution, but I don't feel like thinking about that before I know there's some feasability to this idea. Let me know.
 
Future directions for the project

There has been a large focus to date on unit motion and city construction to support naval invasions. Going forward, the focus will shift to cities and how to make the AI run a better economy. Specific targets include making better choices for placement of national wonders, having worker improvement decisions influenced by a city's special bonuses.

Version 0.7
- Defense construction: when the AI is losing a war, have cities build defenders/counter attackers at high priority
- Fix bugs in city plot selection at 100% culture/esp, golden age
- Safe motion for missionaries and great people

Version 0.8
- Central planning: Switch wonder and other large project decisions from individual cities to a centralized auction system
- Escorts for stranded naval pickup
- Stop extra transports chasing a flotilla that's already heading for an assault

Version 0.9
- It's the economy, stupid AI! Add limited city specialization, integrating national wonders with worker improvement decisions

Further directions:
- War alliances: Allow low power AI players to team together to start war against stronger enemy
- Picking a naval invasion launch point
- Give AI better understanding of connectivity of map using graphs with cities at the nodes
- Active defense: have AI more readily shift extra defensive units to threatened cities
- State religion logic
- Have AI press advantage when winning war
- Add some amount of awareness of game winning conditions to AI decisions to declare war, make peace

Sounds good! :goodjob:
Thanks for the 100% slider fix by the way. :)
 
I see a fair few changes to AI air warfare have been made. :goodjob:
I don't use Better AI currenly so I have a few things i'm wondering whether they have been done, will be done or could be done:

AI tech paths, they need to be more goal driven and diverse, right now they all gimp themselves by researching the same tech line :(

On techs, is there a way the AI could recognise the threat posed when the player goes into a beeline for a tech like Steel or Flight and adjust to it by swapping research or whatever?

Fort logic, the only AI forts I have ever seen have been the ones on resources outside of BFCs that auto workers place, can it be made to consider the benefits of canals (formula based on time saved, coastal production and existing naval assets perhaps?).
Theres also the trade port aspect, this isn't a huge deal as it almost exclusively happens on Archipelago tiny islands games and probably has more to do with AI not shuttling workers around on boats.
Air slots too but thats in the next bit :p

Air warfare logic, in Better AI does the AI actually consider, and manipulate the density of its, and opponents air force slots in an area? i.e. will it build forts and Carriers to increase its air capacity, and will it attempt to destroy an enemies forts and carriers to reduce theirs? Personally, I think the lack of this in 3.17 is the most damaging factor in AI air warfare.

On the Privateers fix, its fantastic that AI will now build these, and I know its been mentioned that new fixes will be needed. One possible outcome may need checking, as Privateers can be built with copper making them the strongest available naval unit in some cases.
Would it even try to use them for war, or would it keep trying to use the Pirate mission?
Would the AI actually have a clue how to use the things in a war siuation? This is considerably more complicated to do compared to normal naval warfare (speaking form experience :lol:) as you need to be aware that Privateers are effectively at war with otherwise neutral parties too! I found using forts to hide in vital in these instances.


Special uses for units, I rarely see AIs deviate from standard "Swordsmen are for attacking cities" or "Must DOW before entering borders" logics, this seems to hit certain UUs hardest.

I've never seen an AI using the fact that Carracks and East Indiamen stay withing a rivals borders when declaring war allowing for first strikes deep in enemy culture on core cities like capitals. Probably blocked entirely by 3.17 AI DOW logic. Does this change in Better AI?

The Gallics and Jags that I see always have either CR or Combat and counter promotions, allowing the AI to consider the stack defense and 2 moves from G2 or W2 may improve them a bit.
 
Actually I consider the Carracks & East Indiamen not being auto-expelled by DOW declaration to be the problem.

I've never seen an AI using the fact that Carracks and East Indiamen stay withing a rivals borders when declaring war allowing for first strikes deep in enemy culture on core cities like capitals. Probably blocked entirely by 3.17 AI DOW logic. Does this change in Better AI?
 
wow this mod looks like a must have!
 
Future directions for the project

Version 1.0
- Opportunistic war plans to allow low power AI players to team together to start war against stronger enemy

Further directions:
- Active defense: have AI more readily shift extra defensive units to threatened cities

I really like these ideas, particularly the first one!


- Give AI better understanding of connectivity of map using graphs with cities at the nodes

I'm not quite sure what benefits this would bring, but it sounds promising.


I have a small wishlist:
-Have the AI create several naval groups that seek to permanently blockade coastal cities throughout a war.
 
Does this mod work with other mods and scenarios like Rhye's and Fall of Civilizations, and Final Frontier?
 
Top Bottom