Monster Artificial Intelligence
The intelligence of the DM monsters is contained almost wholly in a
function named ProcessTimers29to41. As the name implies, it
processes timer entries of type 29 through 41. The original
function was a mass of spaghetti code with gotos all over and even into
the middle of 'while' loops and god-knows-what. See
Shape of Original AI Function . In an
attempt to understand monster behaviour I first decided to unravel this
function so that it could be drawn on 2-dimensional paper. As I
redrew the function, I rewrote it, often duplicationg code and turning
large pieces of it into separate functions (albeit with
terrible-looking parameter lists). The results are seen at
First Approximation,
Second
Approximation, and
Third Approximation.
After each small step I replayed three complete DM games and one rather
long CSB game to make (kinda) sure I had not changed the actual
operation of the function (I caught several mistakes this way).
Then I began adding some trace code, enabled with the Misc Menu item
'MonsterAI Trace'. The trace is intended to be used as follows:
- Play a game with recording enabled.
- Identify some part of the game that contains curious monster
behaviour.
- Edit the recording and enable the AI trace
(#AITraceOn-#AITraceOff) during the curious behaviour.
- Replay the game to get the trace listing.
- Edit the trace listing to delete all monsters other than the one
of interest.
- Study the trace listing in combination with the flowcharts to see
what is happening.
- Ask Paul to fix the flowcharts, fix the trace, explain the
strange nomenclature.
- Repeat at step 4 until full understanding is obtained.
- Add a section to this documentation to make the new understanding
public.
The entire sequence of steps ought not to take more than a couple
of months. Then you can begin studying another curious
behaviour. The first thing I wanted to see was how simple
movement was accomplished in monsters on a level different from the
party level. It taught me several things. See
Simple Movement on Non-party level.
Here are some 'sub-problems', starting with the simplest.