You must be logged in to post messages.
Please login or register

The University

Hop to:    
Welcome! You are not logged in. Please Login or Register.No replies
Age of Kings Heaven » Forums » The University » How to make your RMS script more AI-friendly
Bottom
Topic Subject:How to make your RMS script more AI-friendly
marathon
Squire
posted 11-19-20 06:47 PM CT (US)         
This article should be read by RMS scripters who are interested in making AI-friendly maps, or are simply interested to know if their map is AI-friendly or not, so that to inform users. Some of the info should be of interest for Scenario makers as well.

I am an AI scripter, having tested various scripts across mods and on many, many maps. I don’t usually deal with water maps so I somewhat lack knowledge on this type of maps. I have also created some maps myself, usually heavily based on existing ones since my RMS skills are very limited. I have only played with UP1.5 maps or 1.0c maps. I don’t own DE, so some info in here may be inapplicable for DE.

A RMS scripter who wants to know if his creation is playable by AI, he should have a minimum arsenal to test: a collection of AIs, some tool to speed up tests for UP (Cheatengine is fine) and some experience to tell when an AI is going off. For this, he should have some knowledge by experience about the AI’s behavior. Good, reliable AIs should be used for the tests: Promi, Barbarian, Maiar, Tribal, Ulysses are good examples of WK AIs that can play “any map type”. For 1.0c, AllianceThundaEmpire and the old versions of Horde and IS_Machine are good examples.

A basic understanding of AI mechanics is also essential to promote the understanding between RMS and AI creators. In the following list of examples, the term “DUC” will appear often. This refers to “Direct Unit Control”, a method of handling individual units that was impossible before Userpatch, and that it only became fully functional with Userpatch 1.5. It is similar to human left-click and then right-click. It is practically impossible to create codes for all cases, so an AI scripter only creates codes based on an arbitrary function of difficulty and code size vs usability.

-By default, AIs place their building with 1 tile space between them. Exceptions to this rule are farms and walls. In Userpatch and DE, dropsites and TCs can be placed adjacent to resources or other buildings simply by setting a SN. But there is also the option to drop anything anywhere with the powerful command up-build-line. This command is tricky to use and most AI scripters only allow it for very specific cases (like for walling a tower’s base), so normal build commands are most common. To understand how this peculiarity of AIs affects their available space, let me say that in a 8x8 completely open area, a human can place 16 houses while an AI normally only 4 with ideal placement (which is never guaranteed). So, if a RMS has limited space, it will affect AIs earlier and stronger than humans. Examples of maps with limited space: City of Lakes, Salt Marsh, RMC_wild_woods. Also SS_Liana and other maps with too fuzzy borders may cause problems sometimes. Extreme proximity team together maps may cause problems for AIs for this reason, so it is advised to use higher base sizes for team together (perhaps replace lost forests with straggler forests). On nomad, the presence of outposts may cause AI teammates to drop at same location. The same may happen with extreme scattering of villagers. Finally, a woody map like Yucatan but with trees having huge amount of wood each may lead to room problems in later game. Example: some Fencrazy seeds.

-AIs cannot normally place their dock wisely. All they know is that, if they attempt to drop a dock with sn-minimum-water-body-size-for-dock equal to, let’s say, 500 square tiles, then if dock is dropped there is a water body at least 500 square tiles in area. But they have no idea if it is connected to where other docks are. Or, to be more accurate, it is very hard to create a code for this and, AFAIK, no one has done it yet. However, there is a way to only allow warboats to be trained in docks that lie on water bodies that have enemy naval units/structures. So, maps with multiple water bodies of similar size will cause problems for AIs. Example is, again City of Lakes.

-Narrow passages cause pathfinding problems for AIs and may lead to lag in MP or even SP. The gap between a forest and water is an example of such a tiny 1-tile-wide gap (and I have even seen maps where trees occasionally touch water). Trade may also be problematic on such maps. Walls can be deleted in late game and many AIs do so, so walls should not be considered a major problem.

-Long obstacles between opponent towns cause pathfinding problems for AIs, lag, or even the inability to attack if using Town Size Attack. Example: Yucatan. Most modern AIs can evade this problem. So this is a minor problem for a map but it still affects many AIs.

-Bog terrain on WK does not allow AIs to build on it, except with up-build-line. Only Barbarian can play Bog Islands properly, from what I have seen. We AI scripters prefer to say “Bug Islands” instead of Bog Islands.

-Extreme proximity maps (like Border Dispute or Sandy Crater) can be really fun, but for AIs it may be a disaster. They have problem handling attacks in dark age, or even trushes in feudal.

-Migration maps are hard for AIs. I think that there is not a single AI that can play Pilgrims. There is the potential for AI scripters to detect the map and launch a specialised code, but neither a detection system nor such a code exist to this day in my knowledge (DE AI can play Earth map somehow, but it does not do the same on Pilgrims; so there is solution theoretically). Too bad, the popularity of some of these maps should have led to AIs that can play them.

-Border Stones is a map that spectacularly manages to bug all AIs regardless of the experience of their creators. This line of items makes the AI unable to detect that… it dropped a barracks to the other side. This makes them block their entire build plan. I saw Maiar, a very good AI, stay housed at 40 pop forever on this map. I also saw a seed of Hyperrandom with rocks between town and forest. AI did not detect that forest was unreachable and it dropped lumber next to rocks. Villagers tried to reach the closer tree to that lumber by direct distance and not by path distance. The result was a ridiculously slow and weak feudal age for all AIs in the mix.

-A map should generally have enough wood in range. Line Formation is a very nice map that looks extremely interesting (and I like it) but it has too little wood in range. Even on nominal map sizes I have seen top AIs stay housed at 70-100 pop because they ran out of wood. Solution would be to test AIs and then drop some straggler forests, or just a bunch of fat stragglers, or increase the wood of forest near the meridian. AIs use a SN called sn-camp-max-distance. Too large values of it lead to lumbers behind forests, which is very counterproductive. So, most AIs monitor their camp distance closely but they can fail if there is close wood and then nothing.

-Besides wood in range, which should cover the AI until mid-late castle age, there is also initial wood in the form of stragglers. Certain maps lack stragglers (Sunburn for example). It is guaranteed that some old AIs will underperform there because back then it was the meta for AIs to drop mill before lumber. Modern AIs may lack the code to drop lumber at 4-5 tiles from TC and instead drop it to the side. So, extreme proximity of forests puts most AIs in disadvantage compared to humans. But there are other maps with high distance of closest forest and no stragglers to compensate, like quaternary and an old map called Blue Arabia.

-Gold and other resources being even partially engulfed by forest is a problem for humans and a bigger one for AIs. Map revealers in forest can help combat this for UP. Hidden Cup Arabia is a map that uses map revealers (in DE there is a command to avoid forest; a simpler and clearer solution that should be preferred).

-Unfair water. Maps like Scandinavia position players at various distances from water. You never know if the water is completely to the back of the team or split between teams. AIs should be able to check this parameter but I am unaware of any AI that does this. Also, AIs may be tricked to send a villager in dark age to walk miles, often through enemy territory, just to drop a wild dock. This is hard to prevent. So, it is best to make water symmetrical. Two/four lakes map, cross, Mediterranean (usually) and pants are examples of fair water.

-Forest Prison. This map is like Forest Nothing (FN) but its base has a radius of 7. Considering that AIs normally reserve a perimeter of 4 tiles around TC for farms, and that the largest gap between TC edge and forest is 6, this means that AIs cannot normally drop a single house. They can normally drop a lumber and I also think that they can drop a mill. But to drop house without using up-build-line, the minimum base radius should be 9. However in my tests, even with a base radius of 12, I encountered problems with some AIs. The only AIs that can somewhat play forest prison are the handful of FN AIs. FN is even more popular than forest prison, but the challenges that it poses makes it impossible for normal AIs to play it. There are only 4 specialised AIs that can play there.

-ECL maps modify tribute techs and initial tribute inefficiency. First, it is impossible for AIs to detect this beforehand. Second, I tested that disabling and re-enabling a research makes up-research-status not work properly for AIs. Certain crashes I have had could be attributed to this, but I am not sure. This needs testing, but for now it should be noted that messing with researches like this may cause problem for AIs. Perhaps DE fixes this, but Userpatch has not.

-Michi is hard. A handful AIs can play it but not very well. Those onagers rarely manage to cut properly. But at least, once a cut is there, they flood through the gap (and we get the “long obstacle” lag, perhaps also the chokepoint lag).

-Double-base maps like Budapest are actually harder for AIs because villagers walk too much. It is theoretically possible to discipline them (and actually even better than humans can) but such a demanding code does not exist yet. If the map has 2-3 TCs close together, then walking has less of an impact and AIs may even be relatively stronger there.

-Initial explorers or fighters. Humans, even the most ignorant ones, know what to do with them. AIs cannot use them well. AIs cannot task as explorer any unit that has a speed below 0.8. Some AIs have specialised codes to use wild initial units such as saboteurs or cavalry archers to also harass enemy but most AIs just don’t follow their explorer closely and they are not prepared to use a super unit from start to do laming.

-Starting with your initial villager force split in 2 isolated land masses can cause funny problems for AIs. For example, if 2 of your villagers are in a wide wood inlet, isolated from your TC, you can drop a lumber with them (the AI should either detect this peculiarity or hope that, in time, a lumber appears there) and have them chop wood until there is a hole. But once in castle age, the AI may be tricked into dropping a TC or castle in their area, in which case the AI will try to task the desired number of builders on it. But most AIs task multiple villagers for these buildings and if the AI discovers that there are not enough vills that can touch the foundation, it is deleted. And then it may try to drop on same spot, with same result, indefinitely or until the said building randomly chooses another spot. Also, in the case of 2 TCs, AI may choose the wrong TC to drop first house with 2 vills, resulting in cancelling it forever. Example: Inception. Possible solution is to give 2-3 villagers per base or just one house, to avoid such problems. AI may still fail to fully utilize both villages efficiently but at least it will play.

-Iron Boars are tricky but avoidable by prepared AIs… to some extent at least. Lions and other atypical predators will bug the AI villager and TC defense system for unprepared AIs. Solution is to upgrade a typical predator into the desired atypical one using RMS effects.

-Relics on other islands are hard for AIs to grab. Such a code is doable but it does not yet exist. Solution would be to use a smaller distance between relics or between relics and player areas, so that they are not forced to the edge of the landmass. Examples of maps that make relics inaccessible for all current AIs are an old map called Atlantean Relics, LF Sceleton Coast, and maps with a giant central island and a thin outer perimeter (relics tend to generate there).

-El Dorado has deep sea on hybrid terrain under TC. AIs cannot task villagers to gather deep sea fish without DUC. But you can’t DUC for every possible case.

-AIs cannot build incomplete fish traps with fishing ships (they auto task villagers instead… if accessible) nor use fish traps in general (without DUC).

-Spawning trees or forage bushes through modifying corpses is a huge problem for AIs. Example: Zebra Nothing. Trees are not recognised by AI villagers and the only solution is DUC. Zebras, however, are recognised.

-Buildings or other immovable objects with a radius that is not 0.5, 1.0, 1.5 etc. cause unsolvable problems for AIs that can, in some cases, result in a total disruption of build plan. To be honest, I have only seen it once, but it was Barbarian the AI that failed because the fact (can-build-line) was true, but the mill was never placed.

-If there is gold (or stone, but especially gold) that is inaccessible, AIs will spam camps. Examples are maps with all gold in a different isolated area. Holy Line has not shown this effect in my tests.

-Convertible Feitorias, or starting with 1 villager only, can trick some otherwise top AIs into early resigning. Examples are Feitoria Fiesta and a version of Sunburn that I came across. Also heavily asymmetrical starts may have this effect.

-Units such as heroes with high ID (like 2000+) cause memory leaks when the AI tries to target enemy with them, resulting in crashes.

-Gold or stone that is only one pile and relatively close to TC may be ignored forever by AI camps.

-Sheep that are spawned or trained or present under player color since start are not auto-recognised by AI villagers. Fortunately, most modern AIs have sheep management code that use DUC.

-AI lumberjacks cannot target a tree that already has 2 lumberjacks on it. So, maps with very few but very fat trees cannot be played smartly by AIs.

-Battle Royale-like maps are impossible for AIs to detect. Fortunately, the new Battle Royale mode in DE is detectable.

-Normal AIs are based on the assumption that they can build TC and train villagers from it. They assume that TC costs wood-stone, villagers only food and dropsites only wood. So, certain maps (like Commie Games) that change those costs or take away the ability to train/build certain items are guaranteed to force all AIs into inefficient play and AIs may even bug out.
Unlike humans, AIs can detect the work rate of villagers or other hidden but RMS-modifiable attributes. But I am not aware of any such AI.
AIs have no way to read that, for example, knight-line is not available due to map or scenario restrictions. Humans may be surprised but they adapt. AIs will never adapt. Furthermore, blocking certain researches is unreadable as mentioned above.

-AIs burn wood. If your map has really little wood (example is several of default maps in ToME mod) then AIs will fail there because they do not have a plan for this case.

-If your map has new units enabled in a new building, then an AI can train them only if it already prepared. Examples are those Unique Utopia maps.

Keep making innovative maps. If a certain map is unplayable by AI, then so be it. No map should be critically modified just to be AI friendly. But there are many players who love both AIs and maps, and diverting some of the energy of the RMS community into this direction would benefit the community as a whole.

Even though this is a long article, it still has room for additions, so feedback is welcome.
You must be logged in to post messages.
Please login or register

Hop to:    

Age of Kings Heaven | HeavenGames