Scripts and tiles
HoMM games are based on adventure maps that are made up of tiles. Each tile can hold an adventure map object, or alternatively only terrain like a rock or part of a road, and these adventure map objects define what can happen in the game. Or more precisely the interactions that can occur on the adventure map.
In a pure strategy game the definition of these interactions presents also the rules of the game. You don't need more. Chess is a good example.
In addition HoMM has more complex rules that govern how its adventure map objects work internally, for example what you can do in a town, like recruiting, building up your castle, researching spells and the like. These rules are also defined mathematically. For a dedicated strategy player this matters a lot, because it makes everything in the game predictable. The same goes for the AI. The rules form the basis of lookahead and prediction.
In practical terms a hero moves forward tile by tile on the adventure map. On each new tile the hero enters, the game performs checks what will happen here.
Game state
Naturally there are many things that the game has to track, the objects, their states, whether they had been visited already, the terrain, the movement cost per terrain tile, plus the more advanced attributes of heroes, creatures and towns.
But in terms of game logic this is straightforward. The game has at any point of time a well defined state, and the interactions modify the state.
In principle there is no difference between the game state per se, what the actors, i.e. the players and their heroes, can do, regardless of whether they are human or AI. But there is one notable difference. Whereas the human players look at the game and make predictions in their head, the AI has to do a simulation, or lookahead, of what can potentially happen while heroes move over the adventure map. As long as the rules are well defined, everything is fine. The intelligence of the AI lies in how well it can understand and interpret the game state.
Scripts change the game state
Scripts can modify mostly any property of any object on the adventure map.
As soon as you enter the realm of scripts, the game stops to be a pure strategy game, because technically you add new rules that make the game work differently.
Nevertheless skilled map creators can restrict their use of scripts in a way that doesn't change the balance of power between the players. For instance scripts could change the creatures you can recruit from a dwelling, or provide a hero with a free boat at a shipyard, instead of charging a cost of wood and gold.
It is even possible to restrict and allow access to regions on the adventure map once a hero enters a specific tile. Changes like that can augment a map's asymmetrical nature to craft outstanding strategic challenges.
But to do this properly without jeopardizing the strategic nature of the game requires enormous forethought.
It also requires special considerations in respect of the game state, as the AI needs to know what can happen to make its predictions successfully. The vanilla AI handles this by simulating the hero movement tile by tile, and simulating the end of turn each time all heroes have done their simulated moves. This simulation includes the triggering of scripted events when a hero enters a tile or interacts with an object, and when a turn ends.
As you can imagine this type of simulation requires the probing of a manifold of potential realities, each consisting of different actions any hero can take. Computationally this is slow and limited, hence the limited foresight of the AI in the vanilla and its slow response times. But to its credit, it can handle mostly any script action correctly.
Optimized lookahead and advanced AI
If you truly want an AI that is fast and has a lookahead that allows it to do strategic planning successfully, you cannot simulate hero movement on a per tile basis.
One of the first optimizations I introduced was to upgrade the pathfinder. Instead of looking at movement cost per tile, the upgraded pathfinder tracked the distance between objects on the adventure map. For the strategy game in its pure form this is sufficient, as interactions only occur at interactive objects. Computationally this is many magnitudes of order faster.
But this approach has problems in relation to scripts. For example if a script allows or disallows access to a region by tracking a hero's movement to a given tile, this is simply lost in this type of optimized lookahead. The same is true for most other script actions triggered at various adventure map sites. With other words, scripts and the advanced AI don't work together.
Now, you may ask why I had chosen this approach nevertheless.
In principle, with the strategy game in mind, a script action that alters a rule and/or interaction compared to the AI not knowing about a rule has very much the same effect: it compromises the strategy game.
In practice it amounts to the advanced lookahead being worthless, and once an AI hero triggers a script action, the situation on the adventure map changes. The AI notes this and redoes its lookahead.
Besides the obvious problems this creates for the strategy game, there are also technical implications.
The current limitations the AI has, that it reports a script error, have its root cause in the AI not detecting the changes a script caused. Each type of script function has different consequences. For example script events triggered by a hero entering a marked region versus script events that provide a hero with additional troops need to be accounted for and handled differently. These types of handlers are simply not there yet.
Towards a solution
Developmentwise it isn't difficult to solve the problem of the AI detecting modifications of the game state triggered by a script.
The much larger problem is to accomodate for these modifications in a strategic framework that is sound. This is possible. But as a prerequisite it requires the larger strategic framework that comes with the implementation of strategic planning proper in the AI.
As such we have a roadmap roughly like this:
- Strategic planning to unify all aspects of AI decision making
- Combat AI to augment the strategic performance of the AI
- Assessment and planning of the use of hero equipment (artifacts)
- Implementation of smart hero skilling that takes strategic aspects and combat into account
- Integration of script functionality
It doesn't make sense to try to integrate the script functionality before the other milestones are met.
There is one notable exception. I am currently going over the LotA missions to ensure that these play well with the advanced AI. But the situation here is that LotA smartly uses scripts only in a very restricted way that augments the strategic gameplay. Book 1 and 2 should become playable relatively quickly. Book 3 needs investigating.
Why not let the players choose?
It is a valid question whether a modded game that doesn't handle scripts correctly but at least allows all maps to be played is preferable.
This is technically the situation with our older work, version 3.1j released in 2011. Its AI was never meant to work with heavily scripted scenarios and it truly doesn't, it is downright broken, but if you are just used to the vanilla's standard you possibly won't notice much of a difference.
The reason why I don't want our current advanced AI to play in scenarios in which it won't work go much deeper.
The main reason why this project exists, why I do all this work, is to show the world what a difference a truly competent AI that is capable of strategic planning brings to strategy games in general. I simply believe, once people see and understand what it truly can do, they will love it and won't exchange it for anything else. It would be kind of a milestone for the genre at large.
But first impressions matter. If this AI would be showcased first on maps where it doesn't work, people will just think, in general this is a nice mod but the AI is so-so and close the chapter. With other words, it will leave us with an uphill struggle all the way. It wouldn't serve the project's goal.
I rather prefer someone knowing that something doesn't work than someone getting a wrong impression.
What does it mean for you, as a player of Heroes V?
If you look forward to all maps being playable, the only thing you have to do is wait until we reach this point on the roadmap.
There isn't a shortage of what you can do. You can follow along playing LotA. These are gorgeous maps offering plenty of replay value.
There is also the upgraded random map generator which supports HotA-style map templates. Currently the choice of template parameters is limited by the RMG implementation, but there is a sizeable chance that we can upgrade further to use HotA map templates directly soon. This will give you a wealth of high-quality random maps.
I am also going over the vanilla scenarios and selected maps from maps4heroes.com to ensure that these are playable. Maybe, if enough people chip in and report maps that they confirm as playable, we can create a list of the currently playable maps, so that people have a good choice of maps known to play well. If someone would organize this, we could also give recommendations of the quality and playing style individual maps offer.