Wrangling the Heroes IV AI

Part 2: Wrangling the AI

Here we will look at some ways of overcoming the limitations of the Heroes IV AI, while taking advantage of its strengths. Most of these follow directly from the analysis of the behavior of computer heroes that I presented last time. Still not having completed my map for Heroes IV, I should say that some of these techniques are essentially unproven, but I’ve done enough experiments to convince me that they should work in many situations. An additional disclaimer is that my experience is mainly with single-player games and may not always apply to multi player contests. And to those who are not inclined to scripting, I should say I’ve done my best to stick with simple scripts and settings that everyone can use.

Playing like a human

Before getting into specific techniques, I’d like to get across a critical point: the AI is never going to play like a human , much less like an experienced human. It plays the way if does, and we just need to accept that. However, this does not mean that mapmakers can’t use the AI to give human players the same challenge they would meet against other competent human opponents.

It also follows that dual mode human/computer player positions should be avoided. In a typical starting position suited for a human player, there is no chance the AI will develop a computer player into a reasonable opponent. You might get one good-sized army out of the computer player’s starting town, but it will not effectively challenge even reckless human players. It may take a town or two, but it can never execute a systematic campaign to victory. It may even manage to eliminate another player or two from the game, but unless the others launch suicidal attacks on the computer player, it simply lacks the persistence to win. And of course it will not benefit from quests, objects, clues, or other advantages that are often available to players.

I see a great many 4- and even 6-player maps where all the player positions are human/computer. But I’ve only heard of a few 4-player games and I’ve never known anyone who played with 6. I think these maps must be designed that way so the players have a choice of starting positions. This allows the mapmaker to fix the types of the starting towns, while still allowing players to choose their favorites. It also provides some replay value. Too bad it makes for awful computer players. To mapmakers who simply must use fixed town types, let me suggest this: make separate versions of your map for each starting town. But it would be better to design one or two positions to be ‘random’ so that you can offer a variety of starting towns without having to include human/computer positions.

That said, lets look at some ways to wrangle the Heroes IV AI:

- Zoning
- Mines
- Town setups
- Marshalling armies
- Defending towns

[1] Zoning

To give human players the sense that they are up against another human, a mapmaker can use the RPG technique I call zoning . To use this approach, the mapmaker divides the map into zones, each suited for player forces at different levels of advancement. The zones are separated by garrisons, quest gates, or tough monsters so that forces can’t enter a zone unless they are advanced enough to take on the opponents there. This helps hold the players’ interest since it gradually opens up new areas rather than allowing them to range freely over the entire map. It also allows players to have starting zones where they can get settled into the game before encountering tougher opponents.

In a zoned game, it is clear why dual mode human/computer players are a bad idea. How do you create a starting zone suited for a human player that can also serve as a worthy challenge when occupied by a computer player? Without some heavy duty scripting, I don’t think it can. In every L/XL map I’ve played, the neutral wandering monsters have grown into more of a challenge than any human/computer town. At best, a computer player will amass its armies for a big attack or for last-ditch defense. But because the computer player has not matched the human player in expanding its territory and developing its heroes, it is doomed to lose.

So how do you make a game challenging up to the end? Rather than having computer players start out like human players and hoping they develop by the time the humans arrive, consider how the map would look when a human player enters a zone occupied by another human player. Then set up the zone to look like that. If you think a smart human will have captured some mines, go ahead and flag them for the computer player. If you think a smart human will have stationed a scout near the entrance to the zone, go ahead and put one there. If you think a smart human would have developed a hero to a certain level, go ahead and create such a hero.

If you are concerned about the computer force running amok, set a patrol radius that will keep them where they are supposed to be. Or just box them in with quests, which you know that only human players can perform. If you want it look as though the computer player has completed a quest, use an empty quest hut. If you want it to look as though the computer player has beaten some monsters and picked up some treasure, just leave a few tough guards in places the computer player can’t reach. Don’t bother putting out treasure for the computer players—they may not pick it up. Just give it to them.

Artifacts are another matter, since they almost always will end up in the hands of human players. Mapmakers should make sure that after an opponent is Defeated, only the artifacts intended for players will convey. It’s one thing to dress up a hero with nice artifacts and another to scale up the challenge when the victorious player dons the boss apparel. It’s better, I think, to use skills and spells to make heroes more formidable. (I’m planning to do a future column on hero design, so I’ll leave this here for now.)

[2] Mines

In Part 1, I speculated that the reason computer players sometimes neglect mines after clearing the guards is that when they enter the area, they can’t see a clear path to the mine because of the guards. After they clear the guard, they are not aware that a new target has become accessible, so the mine sits ignored.

There are two rather obvious ways to deal with this odd behavior. The simplest is just to flag the mine for the computer player. Or remove the guards so that the computer player can ‘see’ the mine. But if for some reason you think the mine needs to be guarded, put the guards inside the mine instead of in front of it. That way the computer player will be able to ‘see’ the mine and also have to fight to capture it.

As to resources, I think that the AI has its computer players only go after resources that are needed for the next building project or the next creature that has a resource cost. This allows them to get what they need as soon as possible and not waste movement to get something they don’t. And remember, computer players apparently do not take into account how far it is to the next target, so they may be right next to something and decide they want something else more—and off they go.

[3] Town setups

To the extent that the town types are balanced, completely random towns may or may not be a good idea. I’m of the opinion that the balance is close enough that random towns can work in most maps. Mapmakers should bear in mind that human players can see the advantage of combining forces from towns of the same type, while computer players see all towns the same. That’s why they don’t seem as interested in retaking towns they lose as humans do—and they don’t realize that the original town is their best source of reinforcements that match their current armies.

As we observed before, computer players do not develop towns very well. They seem to build whatever they can whenever they can, so they end up buying a lot of low-cost items like levels on the Mage Guild beyond their heroes’ capacities. At the same time they often build an inferior level-4 dwelling, because its resource requirements are easier to meet. (Let’s not argue this, but I’d say Black Dragons beat Hydras, even considering their cost and low spawn rate. Yet four out of five Asylum towns developed by computer players will have Hydras. This is because the Hydras don’t call for all that Sulfur.)

The easiest way to make sure a computer player has the right level-4 dwelling is to build it for them. If you think this would allow the computer player to accumulate level-4 creatures too quickly, you can just block off the other level-4 dwelling and hope the computer player is able to gather the resources it needs. Or maybe you could set up an Event to fiddle with the resources. But as long you are doing that, why not just write an Event to build the structure when you think it’s appropriate?

As to the AI’s penchant for Mage Guilds, that can also be controlled by Events. In the map I’m working on, I have a town with a garrison hero that I want to cast a certain spell when the town is attacked. Since I don’t want him to learn some other level-5 spell and cast it instead, I’ve made sure the computer player won’t have a Guild there. So as not to cheat the player, when the town is captured a Guild is added.

The Creature Portal problem can be handled the same way by disabling it until the player takes over. Mapmakers who want to simulate its presence can add an appropriate number of creatures to the build cycle. Of course, you can’t do this for a random town.

[4] Marshalling armies

As we observed last time, a big reason why computer players put up such weak resistance is the way they form armies. Sometimes there are no heroes, sometimes only heroes. I attribute this to the ‘buy what you can’ approach to development.

There are a couple of ways to address this problem. Armies stationed outside of towns can be constructed to look like they were developed by human players. If the mapmaker is using zoning principles, it is a simple matter to envision what a worthy opponent would look like and set up the army that way. Since the human players are expected to be at a certain level of advancement before they can enter the zone, it is usually not necessary to scale the army up or down to fit the opponent. If that’s needed, creatures can be added with an Event. You might try putting a suitable dwelling within the army’s patrol radius, but the AI’s proclivity for caravanning might result in the armies being caravanned out. In that case, you need to block the caravan route.

The same approach works for armies stationed in town, but for those that are to set out to explore and conquer, some attention needs to go to party composition. The key here is managing the computer player’s resources differently. Normally, if the computer player has enough gold to buy a hero, it does so and sends it out—even if it is not accompanied by supporting armies. Or if no hero is available, it spends what it has on creatures and sends them out—again without a hero.

We did not see this problem in Heroes III due to the weekly build cycle, so the way to fix it is to set up things the way they were in Heroes III—i.e. get computer players onto a weekly build cycle. This requires two simple scripts: one Continuous Event to take away all of the computer player’s gold each turn and another a weekly Timed Event to fund the weekly builds. Since computer players never use their gold for anything else, it does not deprive them of things they might buy at the Blacksmith, War College, or so on. If those things are really necessary, they can just be given to computer player heroes when they are created. Creatures in captured dwellings will still be bought and transported by caravan.

The idea is that each week, the computer player will get its income in a lump sum, instead of daily installments that it does not know how to manage. There will always be a hero available, plus a week’s worth of armies, so the resulting army will be composed more like a human’s. These armies will be substantial enough to take on neutrals and since they contain heroes, they can flag the objects they capture. Another side-effect is that the heroes are able to advance as their armies win battles.

[5] Defending Towns

In many cases, the development of a Citadel and Castle actually impairs town defense by computer players. Instead of launching a coordinated counter attack, defenders wait behind the walls to be picked off one by one. The easiest way to improve town defense is by disabling these structures.

There are some other things that can be done to strengthen the defense. First is seeing that the computer player has the right mix of armies for defense. This means 3 shooters, one or two walkers, and two or three fliers. Better to have one strong walker than several weaker ones. Place this army near the gate (center position) in position to counterstrike against the attacker. Put the shooters in the 2-4-6 slots so as to mount the towers. Magic resistant shooters like Ballistae work best. For WoW maps, Gargantuans are very tough, and Catapults may be best of all. Harpies can also be excellent defenders since they attack the opponent and then retreat to safety. Other good defenders are Mages, Cyclops, Venom Spawn, Genies, and many level 4 creatures.

Select Magic heroes that can cast supporting spells or attack spells that do not require line-of-sight. Give them only the spells you want them to cast. In fact, take care not to give them line-of-sight spells since they can cause the heroes to start out adjacent to the wall where they can be easily picked off.

Another possibility is setting up the defense outside the town. Armies in the open are more likely to charge and engage an enemy directly. They can also be stationed there permanently so the town is always guarded and the garrison armies do not end up with a roving hero. The other advantage of outside defense is that enemy heroes are not automatically resurrected after a victory—if the defenders can eliminate the attacking heroes, they will have effectively blunted the attack.


When this battle is fought in the Castle,
the Red computer player defender loses.

When the same battle is fought on a bridge,
the Red computer player defender wins easily.

Summary

To wrap up this piece, let’s go back and see how the measures I’ve suggested are able to address the AI’s shortcomings that I brought out in Part 1.

Goal setting

The key here is reducing the number of targets available to computer players, which means laying out computer player positions differently than human player positions. Better to just give the computer players what you intend for them to have—players won’t realize this since by the time they get there, the computer player’s area will look like a human player’s. To set up a situation where computer players compete with human players, avoid distracting the computer player with secondary objectives. Bear in mind that computer players will not pursue quests, so these will be for players’ benefit only and computer players deserve some compensation.

Army formation

By pre-forming armies, you stand a better chance of developing challenging computer opponents. This has the added benefit of providing more diverse combinations of armies than the typical two-army spreads you get from monster tokens. Don’t expect computer players to send out reinforcements but do expect they will have significant attrition—make sure they start out with a strong force.

Spell selection

I’ll have more on customizing heroes later, but here the idea is to limit the number of spells available to computer spellcasters. Choose one or two good ones and assign them to the hero. If the hero has access to a town, consider the effect of a visit to the Mage Guild, which is just about guaranteed to be built up to level 5. Either match the town’s spells to the hero—or block the structures and use a simple script to build them when the player captures the town.

Also realize that computer players will also select spells randomly for spell casting monsters. Humans are much more skillful in the use of Mages, Water Elementals, etc. because there are many choices and only some really make sense in a given position. Computer players do OK with creatures that have only a few spells—like Angels, Satyrs, and the bodacious Evil Enchantresses.

Siege defense

Defending towns means building and maintain a proper garrison with an effective mix of armies and extra strength to compensate for the AI’s poor tactics. I might go so far as to say that Forts are a liability for the AI, which does better to defend the open ground in front of the town—or even a strategically placed garrison—than the town itself.

Town development

Again, when town development matters, it’s best to design it the way you want it to be when players arrive. This has the useful side-effect of allowing computer players to start accumulating armies. You might try starting with level 2-3 creature dwellings (enough to assure smart choice of key creatures) and awarding level 4 at the end of a month—just a simple timed town Event.

If you are using timed Events to pump creatures into a town, which helps assure the computer player has respectable armies, then you can just disable everything and build stuff when the player captures the town—a simple standard Event. Setting up a build this way can also avoid of the possibility of a Preserve with an untapped Creature Portal.

In closing

Before wrapping up this series, I should note that most of these techniques also apply to the handling of neutrals and computer allies. There are some notable differences, but that’s something to discuss another time.

I should also note that dedicated scripters have come up with many more techniques for managing computer players. If you are interested in these, I encourage you to visit the Mapmaker Forum.

Finally, we come back to the question: “Does the AI Cheat?” After looking at some ways for mapmakers to wrangle the AI, we now have an answer: “No, but to give the player a good game, you need to make it cheat!”

Want to talk about this some more? See you in the Forum.