D&D5e: AI Project - Myth-Weavers

GM Workshop

A community-created and maintained place for Game Masters of all systems to bounce ideas around. It's a place for inspiration and sharing tips.

D&D5e: AI Project

D&D5e: AI Project

Hi, everyone. Today, I'd like to ask for help building artificial intelligence for monsters and npcs in combat in D&D5e.

What I mean by that, is a simple set of guidelines that covers the basic actions that a monster will take in combat. In theory, a player can reference these guidelines to see what a monster would do in combat, without input from a DM.

This system is inspired by the D&D Adventures board games, but because of the significantly more complex rules of actual D&D, these guidelines will likely have several more lines of code to write out.

I do want to stress that a key goal of this project is to create a simple and concise system that can broadly apply to most situations. It will almost definitely not cover all situations, but that is not our goal. For now, all we want to take is, the first step. Perhaps, we can develop this system to cover more and more if there is interest to do so, but for now lets try and cover basic combat.

What we'll be working with for the research and development of this system is the Flying Sword creature from the SRD.

Here are its stats for easy reference.

This system would assume that the player has access to this stat block.

It also assumes that the monster is hostile towards the player characters.
MAI Flying SwordDue to its
While the sword remains motionless and isn't flying, it is indistinguishable from a normal sword.
False Appearance
, The Flying Sword remains motionless until a Hero is within its speed. If a Hero enters within its speed, it gets a surprise round against the Heroes unless they have been surprised by Flying Swords within the last 24 hours.

If a Hero is within the Flying Sword's speed, it moves to be adjacent to the closest Hero and uses the attack action on that Hero with Self Slash.

Otherwise, it will use its action to dash and fly double its speed towards the closest Hero.

If an adjacent Hero leaves its reach without disengaging, it will use its reaction to make an attack of opportunity with Self Slash.
And that's it. Pretty simple right? That is the goal. The above rules would be adapted and slightly altered to fit the tactics of each individual creature you intend to use this system for. There are a couple things to note, though. The following are rules that should broadly apply to all specific Monster Tactics. Specific rules within Monster Tactics may override these some of these guidelines.
Understanding MAIMAI is meant help the DM run a smooth and consistent game. Rulings and decisions made by a DM always takes precedence over any of MAI's guidelines.

The term Hero refers to a player controlled character, and their allies. This includes NPCs who are traveling with the group, along with animal companions, mounts, familiars, retainers, and other such entities. Even if they are non-combative in nature or intention.

The term Monster refers to creatures that are hostile to the Heroes.

The term Tactics refers to the various actions and movements a Monster might perform as detailed by this system.

The term adjacent refers to creatures being within range for a legal melee attack.

Players will need access to the Monster's Stat Block in order to use this system.

To determine whether or not a creature is within a certain distance of a Hero, one should measure the distance or count the spaces in between the Hero and the Monster. Do not include the space occupied by the Hero and the Monster in your measurements. If there is an obstacle between the Hero and the Monster, include the extra distance needed to circumvent the obstacle in your measurements. If the Monster has the speed available, it will always try to avoid triggering Attacks of Opportunity. If there are multiple Heroes who are equally close to a Monster, roll a random dice to decide which Hero it will consider closest, unless noted otherwise. Assign numbers on the dice to each of the Heroes in question, as evenly as possible.

A Monster will never move towards a Hero it is not aware of, even if that Hero is within the distance of its Tactics. If a Hero can Hide (regular stealth rules still apply), and beats a Monster's passive perception, that Monster will not be aware of that Hero. If a Hero successfully uses Hide, and the Monster is not aware of any other Heroes, it will uses its action to make an active perception check to search for the hiding Hero. If it succeeds in its spot check, it will move its speed towards the Hero. These is a Tactic shared by all Monsters, unless noted otherwise.

Heroes should never act with knowledge that they do not have. (For example, a creature that is indistinguishable from a sword while motionless, should be perceived as a regular sword. Heroes should not take actions against it as if it might be an enemy, even if the player knows that it is an enemy creature lying in wait. This could be circumvented if the Hero has gained knowledge that a flying sword might be in the area.)

Unless noted otherwise, a Monster will always fight until reduced to 0HP.

A monster's tactics never grants it speed or actions it does not have. (For example, if a Flying Sword has expended its reaction for this round, it cannot use its Tactic involving an attack of opportunity.

A monster will never use disengage to move towards a Hero that is already adjacent to it.
So thoughts? Obvious flaws? Concerns? Advice? Suggestions?

Even though, I'd like to focus on the Flying Sword creature first, I encourage those with interest to think about adapting the system to a different creature. Like a creature with a ranged attack or a ranged focus.

My question is what is your purpose in wanting to do this?

Doesn't the 3.5e d20 srd already list some behaviors for most of its monsters? That might be a good reference.

That's a good question. Well there's a couple reasons.

DMless D&D.The first reason I want to develop MAI, is to maybe one day use it within a larger DMless system, like the D&D Adventures board games. However, I would consider even a fully realized MAI as just being the first step towards that. Random dungeons and random rooms would be another big step that would need to be developed. That includes monster placement, and random encounters. However, there are already precedents for those systems floating around various sources, like the DM manual.

I can imagine a rogue-like or dungeon crawler campaign, based off of these systems. However, such a game would only be successful with interesting fights. Which means that MAI would have to be expanded to make interesting encounters and unique from each other. For example a Wolf MAI would have to take Pact Tactics into consideration, and capitalize on it. That's why MAI is divided into two sets of rules. The overall guidelines, and the monster specific Tactics. Those Tactics being the interesting part of the system.
Fairness and Consistency in a regular DM run game.Another reason regards fairness and reliable consistency. It sometimes feels like DMs will build encounters that specifically target the player's weaknesses, and this can provide an interesting and fun challenge. However, if every single encounter the players run into is specifically designed to make their build have a bad day, then instead of a challenging game, they might begin to feel like they have simply made some poor choices in character creation.

Not every creature will immediately know which party member is the designated healer, or who the tank is. Building a Tank that does his job well, is something I've always had a lot of fun with, and my DMs were aware of this. As you can imagine, it has been incredibly frustrating to have all of the monsters in the encounter ignore the prospect of swinging at my huge AC score, spending extra actions to get around my character in just the right way to avoid punishment from my features that are supposed to make me sticky.

Not right away, at least. I would like to develop a simple set of rules that will help decides when and if monsters can determine which party members are priority targets.

That, all being said I don't consider this to be actually too huge of a problem. The problem I described above was never all that bad in my experience, though it did exist. I think for the most part we can trust our DM's to be good DM's and not give their creatures too much knowledge they shouldn't have. However, a fully realized MAI would in theory eliminate this problem.

Even if there is a DM controlling the creatures as in a normal game, MAI will define not only how creatures will act, but why they will choose these tactics. This can promote some creative play.

If a monster has a Tactic related to prioritizing characters that hang in the back, and the players learn this (perhaps through repeated encounters with that enemy), then they might learn to not have their vulnerable characters stand too far back. They may even have them join melee, in order to throw off the enemy's Tactics. Imagine a monster has a Tactic that involved avoiding attacking enemies with particularly high AC, or those who have a shield. Then a good Tank might chose to cast aside his shield to, to increase his chances of holding the attention of those monsters and keeping that focus off of more vulnerable creatures.

Once we have a clearly understood set of rules, we can then begin to break those rules. That's one of the goals, oddly enough.

That all being said, MAI is meant to help a DM run a smooth and consistent game. Any rulings or decisions made by a DM should always take precedence over MAI's guidelines. MAI is meant to suggest a general and broad set of behaviors that most creatures would probably take. A DM should always be free to decide when and why a creature might act differently depending on the situation, or the individual creature.
Limitations of PHB and Streamlining for the DM.One of the main reasons to develop and use MAI, is to make running the game faster and easier. This is why I'd like to keep it as simple and concise as possible, without sacrificing the elements I mentioned above.

D&D was designed to play out in front of a table, and while I'm sure most of us have come to love the benefits of PBP, I think we are all also aware of its limitations. On a table, a battle can be started and finished in one sitting. In less than one day. In PHB, a single battle could take months to finish. And how many battles does it take to level up? To get through a campaign? How many years are we planning to run our game?

If we really wanted to kick MAI into overdrive, we could have players control both themselves and monsters. Potentially, finishing combat in as fast as one post. Now this might be too much.

A healthier medium between streamlining and regular PHP play, might just ask a player to post the actions of one round, or a couple sets of rounds.

In their post, a player might describe his character's actions, and the actions of the monsters between his turn and the next player's turn. Then the next player can do the same.

Alternatively, a DM can control monsters as normal, and just rely on MAI to decide the tactics. This would not make the most of MAI, but at the very least the DM would have to devote that much less time, effort, and thought to the process of running the game. Again, this is only ideal if MAI is competent enough to provide fun and interesting combat on her own.
The way I see it, there's plenty of good MAI can do for the world of D&D and PHP, but only if she's made well.

There are plenty of uses and applications that she could potentially be made available for. Just the same, there are plenty of ways she could go horribly wrong. She perhaps will never be the perfect replacement for a DM, and certainly not on her own. However, I think there at least exist the possibility that she could become something quite fun, and isn't that why we're all here?

Sadly, as she is now, MAI does not live up to all of my expectations and hopes. That's why she needs further development.

Originally Posted by impfireball View Post
Doesn't the 3.5e d20 srd already list some behaviors for most of its monsters? That might be a good reference.
I didn't know that. Thanks, I'll be sure to check it out. I'm already found the D&D Adventures monsters to be quite helpful, so I imagine that this will be even more so helpful.
Flying Sword MAI ExpandedI purposely choose the Flying Sword, because it is not very complex or intelligent, while still pretty interesting. Even as it is, I think we could expand on its MAI further with the following Tactics. This makes its MAI more complex, but does make it a bit more interesting, and perhaps a harder challenge. At the same time, players familiar with its Tactics might develop clever strategies to counter these Tactics.

If the Flying Sword is hit with a ranged attack that originates from a Hero within its speed, the Flying Sword will prioritize targeting that Hero. If it is adjacent to other Heroes, it will use the disengage action to attempt to safely leave those Heroes' reach, and move its speed towards the Hero that attacked it with a ranged attack. Otherwise, it will move its speed towards the Hero that attacked it with a ranged attack and make an attack action with Self Slash. The Flying Sword will not utilize this tactic again, for the next three rounds.

If a Hero the Flying Sword has damaged is healed by another Hero that is within the Flying Sword's speed, and the Flying Sword is aware of this, then the Flying Sword will prioritize the Hero that healed the damaged Hero. If it is adjacent to other Heroes, it will use the disengage action to attempt to safely leave those Heroes' reach, and move its speed towards the Hero that healed the damaged Hero. Otherwise, it will move its speed towards the Hero that healed the damaged Hero, and make an attack action with Self Slash.

If a Hero adjacent to the Flying Sword uses disengage to leave its reach safely and remains within its speed, the flying sword will prioritize this target. If it is adjacent to other Heroes, it will use the disengage action to attempt to safely leave those Heroes' reach, and move its speed towards the Hero that used disengage adjacent to it. Otherwise, it will move its speed towards the Hero that used the disengage action adjacent to it and make an attack action with Self Slash. The Flying Sword will not utilize this tactic again two rounds in a row.

With these tactics, a Cleric in an encounter filled with Flying Swords might hesitate to rely on healing abilities, due to the risk of being swarmed. A ranger might decide to draw their daggers and fight in melee. Alternatively, they might decide that they need to move further away to perform their jobs at a safer distance. These tactics help paint the picture that the party is being swarmed with flying swords that make it a bit risky to stand back and use a bow or cast spells.

Additionally, a clever paladin might heal an injured ally instead of attacking, to attract attention away from other party members.

Considering these new Tactics, I decided to create a new overall guideline for MAI.

"A monster will never use disengage to move towards a Hero that is already adjacent to it."

Having some preset tactics is fine and all, but I'm not sure that it really helps PbP DMs that much since it's not like you don't have a bit of time to figure out whether to do action A or action B. I'd argue it's more useful for tabletop, if anything.

If you were writing, say, a computer game, you'd really need this, and you'd be able to do it to a great level of detail. But as it is, I don't really see why you do or that you can.

You've written your strategies like they really are pseudocode for a computer. That's great and all, but if I have to sit and read through that as either a player or a DM, it's going to take me longer and be harder that for me just to make something up on the fly.

I'd just do something like "the flying sword will attack foes in melee, prioritising those it perceives to be weakest first then those nearest, but it won't give up making an attack against a strong foe to pursue an uninjured one". Bam, I know roughly how the sword will act, that's good enough for me. Of course, as a DM I can pretty much make that up in fewer seconds than it takes me to implement it.

I guess I'm still not really sure what purpose this actually has other than being a bit of a thought experiment - and certainly not to the level of detail you're describing.

Ooh boy.

I'm not going to contribute a set of codes. But from what I've seen your logic is C-family language. So I'd suggest making a few global variables, that is to say, things that everything is doing all the time. Then create local variables for groups of class files. Then organize your tactics in forks and pointers. It'll be very long and complicated and not worth the six seconds of actions they are doing, but it'll resemble intelligence.

Now if you want some kind of heuristic evaluation process for your monsters that allow them to "learn" based on their environment, you'll need to forget everything you know about C. Start looking into LISP, and study Fuzzy Logic. This will also be a great deal of work for not much to show. But at least you'll have monsters that can learn from complexity. Might also want to take a foray into complexity as well, and probably learn something about Mandala Effect - it'll help keep you sane.

Basically what you're attempting to codify is an entire ecosystem. You can't approach it from a single tier and hope that it works for everything, there is too many moving parts. I'm not saying it wont resemble something like intelligence of you do that. Only that all things would have the same level of intelligence. IE an orc would act exactly the same as an Ogre Magi. There are obvious flaws with this.

TheFred, I've explained my reasoning as best as I can. I'm sorry, but if you don't understand, I can't explain it any better. I never intended MAI to be used by everyone. Only those who want to use her. If you see no value in her, then maybe she's not for you.

Black_Valor, you've over complicated things. Needlessly so. The goal is to keep things simple. An orc and a magi would act differently with something as simple as different Tactics. By adding more Tactics, or adjusting the variables within the Tactics I already have, I could make a more intelligent creature react to more situations, or adapt to them more efficiently and effectively. Thus simulating an increase in intelligence. Still makes things more complex, but not needlessly so.

I do like your idea for a DM-less Rogue like dungeon generator game. Maybe something that people could play as a one shot in like 4-5 hours. Limit the amount of monsters included, I'd say. Maybe try it as a Go Fund Me campaign.

Honestly I think you are approaching this problem from the wrong perspective. Instead of designing a set of behaviors for each individual monster you should instead design a framework for monster behavior. Than you can use that framework to generate behaviors for individual monsters on the fly.

Basically you would be looking at something like:
IF (stealth > X)
     try hiding

IF( party CR > monster CR modified by INT in some way)
    don't attack, run away

Else attack(select enemy())

select enemy() = function that does stuff like check for priority targets
Stuff like that.

I don't think this needs funding.

I hear, what you're saying, PPQ. I only choose Flying Sword so that we'd have something more tangible to look at.

Though, I was hoping to adapt what I wrote for Flying Sword to most monsters. The code for Flying Sword is meant to be an archetype, that could easily be adapted to most creatures.

But it does make sense for the archetype to be something open ended and designed to be adapted to specific monsters, like you describe.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
Last Database Backup 2019-02-17 09:00:07am local time
Myth-Weavers Status