AI that cares about itself

The challenge: make AI that cares about its own survival, like any real-world creature, but provides interesting gameplay and doesn’t simply flee at the slightest sign of trouble.

The solution:

As the about U.R.R. page notes, a major design goal for my game is the AI. I don’t want AI that just runs blindly into your sword-swings like in most games. Ultima Ratio Regum is instead populated by creatures that – while they have their own objectives, often involving killing the player – also care about their own self-preservation. An Orc will not charge into combat with a Titan by itself; if pressed, it will flee, and if pressed further, it might even lose its mind from terror. Hilarity ensues. Other activities – such as allies fighting over a good item, or rallying their team-mates – hopefully contribute to the realism and self-serving objectives of the AI.

To demonstrate something about the AI, I present to you this flowchart. Before you look, it is worth first noting this diagram is something of a simplification. For example, if a creature sees an item they want, they do not automatically go after it – there is instead an algorithm involving how much they want it, how far away it is, how good the item is, how close they are to an enemy they want to kill, and a few other factors, all of which come into play to decide if they stay where they are or make the detour. However, this diagram still demonstrates the connections between varying conditions – indicated by diamonds – and states, indicated by the shaded rectangles.

Flowchart of Ultima Ratio Regum AI
Click for a larger version.

Now, this diagram only applies specifically to creatures who are trying to kill you  – it makes no note of neutral creatures, monsters attempting to kill foes who aren’t the player, and allies. All of those will come later. Additionally, each ‘state’ – the rectangular boxes – will be examined in more detail in later blog entries. For now, however, let’s talk about a few of the most important points from that diagram.

– Starting states

Monsters – barring a few, rare, exceptions – can only be spawned as the black states. If they begin wandering, they just move themselves around the map. Monsters who begin waiting will remain where they are until they catch sight of an enemy. Guards will remain at their post until they either see a foe they despise so much they simply must come out and fight, or – much more likely – until they are attacked, or in some other way angered. Some monsters can spawn sleeping, in which case their behaviour until they are attacked, or hear something that wakes them, is pretty self-explanatory.

– Morale

This system merits several posts of its own. Firstly, and foremost –  it is not designed anything like morale systems in other games, which I’ve generally found to be aggravating, and often seem rather arbitrary. In Dawn of War, for instance, I recall lone groups of soldiers sometimes fighting to their deaths and sometimes instantly losing all their morale with no apparent reasoning. While I intend to keep the specifics of the morale system hidden, it is designed to emulate as closely as possible a player’s evaluation of the battle. Which is to say – if a monster thinks it has a good chance of winning, or something happens that reinforces this view, it gains morale. If it thinks it might lose, and something that might reinforce this view occurs, it will lose morale. Monsters – especially in larger battles – are getting increasingly skilled at judging the pace of a battle they’re involved in, and deciding whether or not it’s worth fighting you to the end, or fleeing to wait another day. Again, an entry for another day, but variables as diverse as the armour you wear, the damage to a monster’s body, your combat history, the states of your allies, and even stories of past fights you’ve won that your enemies spread amongst themselves play a role.

– Artifacts

Monsters, like players, love artifacts. If they see one – and are intelligent enough to recognise what it actually is – they are almost certain to drop anything they’re doing and make a dash for it. However, because many factions have a rigid command structure, stronger enemies will often bully/persuade weaker allies to gift artifacts to them. Disagreements can occur, and therefore battles between allies can even take place over artifacts, potentially deadly if neither party backs down…

As this forms one of the cores of the game, any feedback about logical/illogical paths in that flowchart – or other additions that seem reasonable – would be great. In the mean time:

Coming Friday: Introduction to U.R.R. items – from damage to decay, volume to weight, and material to melting point…

Coming Monday: Detail of the morale system, or: how to terrify an Orc into insanity.

Be Sociable, Share!

4 thoughts on “AI that cares about itself

  1. Monsters that are more likely to attack players they can beat seems good for realism but might make for a less fun game (hard to know). An alternative would be for monsters to be driven by XP gains. Beating a player who’s slightly stronger could be a big XP gain, whereas beating a player who’s a weakling could be low XP gain. Then monsters would be more interested in attacking players who are a good challenge, and the player would have more fun with these battles. Maybe it’s not realistic 🙂

  2. I’m glad to report monsters walk a kind-of middle ground between the two. Basically, they assess targets based on how valuable that target is, and how far away it is, and whether there are foes closer. A very important foe far away is roughly as desirable, in their eyes, as a random grunt who’s right next to them. They do, therefore, take a clear preference for going after the leaders, but they won’t ignore the footsoldiers who are much closer, and probably a more immediate threat! A way to think of it is – each side enters battle with a clear plan to go for the opposing army’s leader, but that quickly disintegrates in the heat of the battle, at least until the very last stages when there are few creatures on either side left standing…

Leave a Reply

Your email address will not be published. Required fields are marked *