[Pathfinder 2e] Monster AI Components

This article describes the components of Pathfinder 2e Monster AI. For the steps of making AI, please refer to separate article.

For the full content about Monster AI for Pathfinder 2e, please refer to the main page.

Table of Contents

Monster AI – Components

The current version of Monster AI consists of 3 sections/components:

  1. General Strategy
  2. Special Tactics
  3. Basic Tactics

General Flow

  1. Start with Special Tactics section top to bottom

    Continue to next subsection until the monster’s all available turn actions for the monster are complete i.e. 1 action, move and +/- bonus action/reaction.
  2. If Special Tactics section does not complete the monster’s turn, follow Basic Tactics section top to bottom.

    Refer back to general strategy section whenever appropriate e.g. look for default target, default movement or AI defined keyword etc.

If there are more than one option i.e. tie breaker is needed, a player/GM makes the choice based on the preferred difficulty level.

Difficulty
EasierPlayer’s benefit
HarderMonster’s benefit
RandomRoll a die or use top and right rule

General Strategy

This section defines the general strategy of the monster. Usually, more specific so I call tactics are provided in following sections and that will override this section.

This section consists of following 5 entries:

  1. Adaptation
  2. 🎯(Target)
  3. 📍(Position)
  4. 👣(Movement)
  5. Other notes

Adaptation

For detail of this section, please refer to the dedicated article written for D&D 5E version of Monster AI making.

The section specifies adaptation capability of the monster when encountering the target PC having immunity, resistance or weakness against the monster’s attack. I learned this during my own play with original version of Monster AI in 5E system not incorporating this element. Without this section, monsters kept hitting non-silver physical damage immune character without switching to spell attack or changing to another target. Basically, a paradigmatic example of low artificial intelligence.

This section will specify adaptation category and optionally order of adaptation.

Adaptation [Adaptation Category] [Adaptation Order]
Adaptation category

The category is determined based on the Monster’s intelligence ability score as detailed in the table below. The original table was developed for D&D 5E basing on the Monsters Know What They’re doing book/website.

The current version directly translated the intelligence ability score values to the equivalent modifier values as the Pathfinder 2E depicts monster stat block based on modifier values rather than actual ability scores.

CategoryINT ModifierDescription.
None≤ -2Fixed
Immunity-1 or 0If this attack is a hit & target has an immunity to the attack, adapt.
Immunity, Resistance1If this attack is a hit & target has an immunity or resistance to the attack, adapt.
Immunity, Resistance, Weakness2-4If this attack is a hit & target has an immunity or resistance to the attack, adapt. After (6-INT Modifier) turns, start using the best total damage option.
Instant>4Use the best total damage option every turn.

The category defines presence of keyword that could trigger adaptation. For example, if a monster with immunity category adaptation attacks a target with “immunity” to its attack, it realizes something is not right and try to adapt. However, the same category monster attacks target with resistance to its attack won’t notice anything and just keep attacking.

The last two categories, “immunity, resistance, weakness” and “instant” are for monsters who have high enough intelligence so they will try to assess target’s vulnerability. If it finds one and able to use it against the target, it will do so as soon as possible.

The difference in two categories are the timing when they discover the weakness. The “instant” category monsters are so intelligent, it supposedly have a superpower to even find the hidden weakness. I interpreted this as to see the weakness immediately from the instance the monster sees its foe.

The “immunity, resistance, weakness” category monsters are intelligent enough to actively look for weakness but there is assessment period. I defined this as X turns based on the number of intelligence modifier where X is 6 – INT Modifier. If the monster has almost superpower level of intelligence, it takes only 6-4 = 2 turns. Whereas, if it has 2 intelligence modifier, it takes twice as long (6-2 = 4 turns).

Adaption order

When there is adaptation category and the monster has multiple types of attack options, one should specify adaptation order based on the strike types: melee (⚔️), ranged (🏹) or spellcasting (🪄).

Adaptation: Immunity, Resistance, Vulnerability | ⚔️ > 🏹 > 🪄

Order of adaptation

When adapt is triggered follow the order below.

  1. Top to bottom in special tactics section entry for the failed attack’s action type.
  2. Move to the highest available attack action type specified in the adaptation section
  3. Switch target excluding the current and previously determined to be unable to damage target(s).

For example, if the target PC is immune to a specific type of ranged attack by monster who has Adaptation category of Immunity, the monster tries another ranged attack option that shows up top in the special tactics section if available.

If that’s also fails and there is no more ranged attack option, the monster moves to the next type of attack action option based on the adaptation order. Let’s say the order is ⚔️ > 🏹 > 🪄. In this case, the monster moves to melee (⚔️) attack as it is preferred over spellcasting (🪄).

Switch target

If all types of attack options are exhausted and none can damage the PC, it starts to search for alternative target. For the actual choice of another target, follow the regular target selection rule with failed target(s) excluded from the list.

Target

Target (🎯) section defines the default/preferred combat target choice for the monster.

Examples:

🎯Closest – the closest foe in the attack range from the monster.

🎯 X gather – This monster and X gathers on the same target. E.g. “Up to 2 other melee allies gather” means choose a target that up to 2 other allies are melee attacking.

🎯 In X range – Consider target in a specific range. E.g. In 2 strides range means consider any target within 2 strides distance to this monster as equally valid target.

🎯Most # – the most number of target party members that can be included in the area of effect (AoE) attack.

🎯Most wounded – target with most wounded counter (see below for more detail)

🎯Random – roll a die to determine the target

Most wounded

🎯Most wounded – If the monster’s Wisdom ability modifier is > 0, add this.

These monster preferentially select more wounded target as one would expect of the monster be doing by their natural instinct.

In tabletop RPG, monsters nor PCs won’t thematically know remaining hit points of each other. Also, if one is to use absolute hit points i.e. lowest HP, spell casters tend to become default target almost always.

You have been seriously injured. If you lose the dying condition and do not already have the wounded condition, you become wounded 1. If you already have the wounded condition when you lose the dying condition, your wounded condition value increases by 1. If you gain the dying condition while wounded, increase your dying condition value by your wounded value.

The wounded condition ends if someone successfully restores Hit Points to you with Treat Wounds, or if you are restored to full Hit Points and rest for 10 minutes.

Pathfinder 2E Core Rule book 2nd Edition – Wounded p623

Given Pathfinder 2E having built in rule for tracking degree of wounded status, this is used.

Multiple criteria

The target may be specified with combination of above with the order of priority being left to right with the left being the highest priority.

🎯 closest > most wounded

In this example, the closest foe from the monster (distance in feet) is chosen as the attack target. If there are two or more foes that are at the equal distance, then use the second criteria to break a tie. In this case, choose the most wounded foe.

🎯 most wounded  > closest

On the contrary, the reversing the order means the monster targets the most wounded foe. So it may end up using multiple actions for movement to the point it may even use all 3 actions just to reach the target. If two or more foe’s are at the same degree of wounded, then choose the closer one.

🎯 In 2 strides range > up to 2 other melee allies gather > closest

On the contrary, the reversing the order means the monster targets the most wounded foe. So it may end up using multiple actions for movement to the point it may even use all 3 actions just to reach the target. If two or more foe’s are at the same degree of wounded, then choose the closer one.

*If there are still tie after checking all criteria, the DM or player (in case of solo play) needs to make own choice. For harder experience, think from Monster’s perspective i.e. what would benefit the monster the most. For easier experience, think from player’s perspective. For true randomness, roll a die. My personal preference is the last one to minimize subjectivity in Monster AI.

Movement

Movement (👣) section refers to the default movement strategy of the monster.

👣Safest – Take the path with the least damaging potential to the monster i.e. avoid inciting opportunity attack and hazardous terrain that can damage the monster.

👣Shortest – The path with shortest distance, which accounts/adjusts for difficult terrain. If difficult terrain path requires total 25 feet travel distance and going around the difficult terrain has 20 feet, shortest path option uses 20 feet option.

👣Direct – The path is near [linear] direction even if there is difficult or hazardous terrain. 

👣Adjacent to X – End next to the X.

E.g. Adjacent to ally with the same 🎯. When attacking the same 🎯 in melee combat, this creature will choose the square next to the ally over the other squares if able to.

As in the other sections, the priority is defined from left to right.

👣 Safest > shortest path

In this example, the safest path refers to the monster avoiding to go through the area inciting foe’s opportunity attack or terrain effects that can damage it. Amongst those path, it chooses the shortest path to reach to the target.

👣 Shortest > safest path

On the contrary, reversing the order means the monster finds the shortest path to the target even if it includes the dangerous terrain. Only if there is two or more path with the same distance, it choose the safest one.

Position

Unlike melee attack options, ranged attack including the spells that has a range will require more information than just target. These additional information include distance from the target, preference/priority of the target against cover, and sometimes even a distance relative to the friendly monsters. This is basically a position (📍) of the monster, which is different from next to the target in the melee combat situation.

📍 Adjacent to ally

Choose square adjacent to ally.

📍 Flanking

Flanking with other target.

📍 ≥ X ft – The best position is actual distance from the target (🎯) being X but any number above is acceptable.

E.g. ≥30 ft means the best is 30ft, if not possible 35, 40ft etc. are acceptable. If there is a specific range, one can specify the range as well with left being more preferred distance than the right e.g. 30-60ft prefers closer to 30ft over closer to 60ft but any distance between 30-60ft is acceptable. If it is not able to get 30-60ft, then it rather prefers <30ft than >60ft. If the order is reversed 60-30ft, it prefers closer to 60ft than 30ft.

📍 [X]cover – Prefers to position itself with a cover. X may specify type of cover e.g. lesser, standard and greater.

📍Converge with X – Choose a position that is the closest to the X.

E.g. Converge with friendly goblins with the same 🎯. Each goblin targeting the same PC will gather together in one area i.e. attack the target from same directions.

📍 Diverge from X – Choose a position that spreads the furthest from X.

E.g. Diverge friendly goblins with the same 🎯. Each goblin targeting the same PC will to position furthest from each other i.e. attack the target from multiple directions.

The target may be specified with combination of above with the order of priority being left to right with the left being the highest.

Examples: 

📍 30-40ft > Standard Cover

In this example, the monster will try to position itself 30ft from the target. If there is a choice of cover, it choose the position with standard cover or greater cover. 

📍 Diverge from ally goblins with the same 🎯 > 30-40ft

In this example, the monster will first choose the position where it can be furthest away from the ally goblins attacking the same target. If there is options to choose, then it prefers 30-40 ft distance. 

Multiple 📍options

When a monster has multiple actions with each requiring own optimal position, use📍(name) to indicate specific ones.

Example:

📍(shortbow) 30-40ft > Standard Cover
📍(retreat) stride max possible distance away from 🎯

In basic or special tactics section when these are used, also use the name to refer to specific one.

1.📍(shortbow)
2. 🏹shortbow

Keywords

To keep the monster AI cleaner, one can consider defining keywords for some of commonly used action sequence here.

For example, if the creature has specific way to “flee”, this can be defined here.

Flee: Move away from target carefully i.e. use step if needs to. 

Remainder of monster AI could use flee as a keyword. Alternatively, you can use coding syntax for defining keyword.

Flee:
  While in melee combat: step
  While actions available: stride away from target

Text description

This is a succinct text description of the AI tactics. This section should provide the player/GM a big picture of how this monster acts during the encounter.

Start by putting all quick traps (trap tactics). Then throw spears (ranged tactics). If all spears are consumed or PC reaches to this, shift to hit & run melee combat (basic tactics).

Above is a text description example of beginner’s kit specific creature, Kobold Trapmaster. It has three modes of operation. So above paragraph describes the linear flow from trap tactics to ranged tactics then finally to the melee tactics per the beginner’s guide suggestion.

Special Tactics

This section defines trigger based response of the monster.

The general format is

While/At/If/When [Event/Condition/Trigger]

Detail of the actions

Example of event/trigger can be

  • If HP < 3: Triggers if the monster’s hit point becomes less than 3.
  • If in melee combat: Triggers if the monster is being involved in melee combat i.e. one or more foe is next to the monster
  • If leader/boss is slayed: Triggers if the leader/boss is slayed.

Let’s take a specific examples.

If HP < 3:
    Flee

This means if the monster’s hit point reaches 2 or below, the monster flees.

At vs. If vs. When

I have decided to use “while”, “at”, “if” and “when” to differentiate the timing of the special tactics is being checked.

  • At – Used when a very specific timing during the combat. E.g. At the beginning of this turn, At the beginning of the first round etc.
  • If – This condition is checked during the monster’s own turn.
  • When – This condition triggers as soon as the condition is met. This is useful for triggering reaction etc.
When it takes the first damage: 
    Do something!

In the example above, as soon as the Monster takes the first damage i.e. mostly during player’s character turn, the event triggers.

If it took the first damage:
     Do something!

This looks similar to the other but this is an “if” condition, so Monster checks this when its next turn comes.

While/Until

In 3 action system of Pathfinder 2e, loop type statement simplify AI writing.

  • While/until – actions will continue until the condition is met. Both conditional words achieve the same result but one is more natural than another depending on the circumstance.
Until this reaches to 🎯: 👣(stride)
While this has not reached to 🎯: 👣(stride)

I prefer until statement in the above case.

While action is available:⚔️ jaws
Until all action is used up:⚔️ jaws

I prefer “while” statement in above case.

Subcategories

You can consider switch condition type format from programming language when applicable to keep the design cleaner.

In above case, it may be easier to see the specific condition check relates to low HP, but not specific enough. Under the category, there are two entries with each essentially having own if statement. If 3 or 4 HP: and if <=2 HP:.

Section

Sometimes, there is a block/subsection of tactics that are independent. Prototypical example is creatures that switch melee and ranged attack. Unless specific switching event occurs, these creatures use ranged or melee tactics independently.

This is defined with the section name and separator.

All the codes following below the separator is part of the given section. Switching one section to another section must be explicitly indicated.

If in melee combat:
	Swap to longsword (2 actions)
	Use melee attack tactics

Above is a code from ranged attack tactics section. The particular block of codes cover the situation when the monster is forcefully put into melee combat by PC.

After the end of the section, if 3 actions are not completed just as normal flow AI continues to basic tactics section. Designing soldiers are good example using this syntax.

Basic Tactics

If no special tactics applied, or special tactics did not complete the monster’s turn, “Basic Tactics” section will define the actions for the monster during its turn.

This is essentially a default sequence of actions for the monster and in many cases most frequently used section.

This section could still have [event/trigger/condition] actions format if there are more than one equal likelihood sequence of actions the particular monster can take.

Shortcut Emoji

One of key for designing good, usable monster AI is elegancy in the coding. As in computer programming, one can code AI in many different ways to do the same, but the preferred/better implementation is “simple/shorter” coding achieving the same. This is especially important as user of AI here is ourselves so we want to quickly identify exactly what section we should be reading.

Keyword/emoji aids visual skimming and cleaner code. I do recognize this creates a learning curve, familiarization to my monster AI format so I am trying to balance the use.

Followings are list of icons I currently use.

⚔️ = melee attack

🏹 = ranged attack

🪄= spell casting

🎯 = target

👣 = move/movement

% = Probability

📍= position

⬜ = Square (a grid space)

Single Line, multiple action

A ➡️ B = First perform A then B.

In contrast, A + B means A ➡️ B or B ➡️ A based on the situation.

This notation allows single line multi-step action writing.

Reserved action

1️⃣/2️⃣/3️⃣=First/second/third action.

This is specifically developed for Pathfinder 2E system. Its 3 action system allows new level of flexibility and tactic that was not possible in 5E system. Using with loop statement e.g. while, this allows cleaner coding and acts as reminder/flag to the user..

Specifically, this has been developed for hit & run tactics where the third action is usually reserved for retreat.

Coding this using just top to bottom order format, multiple scenario need to be covered. Move-Hit-Retreat, Hit-Hit-Retreat, Move-Move-Hit, Move-Move-Move, and Hit-Hit-Hit (when cornered). This approach will need at least couple if statements. Having reserved action, this could be simplified to single 4 line block.

Until this reaches to 🎯: 👣 (stride)
While
	3️⃣ If used ≥ 1 jaws & able to retreat:📍(retreat) 
 	⚔️ jaws

As a user of this AI, 3️⃣should get your attention but that only applies to the third action.

When reading the while loop section, and on the third action of the monster, you check the condition. It states at least one jaws strike has been used, so the monster won’t do move-move-retreat, which is clearly wrong thing to do.