Nick’s learning mapper
by Nick Gammon (February 2020)

Updates
I have made various improvements since making this original post. Later versions have a lot more features, as described in further posts below.
To check if you have the latest version go to the Learning_Mapper plugin page on GitHub and check the version number (line 15 of the file). At present it reads:
version="2.1"
The latest version of the mapper (1.8 onwards) shows the version when the mapper starts, like this:
[Learning_Mapper version 2.10]
The version number is also shown when you type “mapper help” (right at the top of the help information). Also at the end of the mapper help are links to the two files mentioned below.
If you don’t have the latest version please download it from here (two different files):
- https://github.com/nickgammon/plugins/blob/master/Learning_Mapper.xml
- https://github.com/nickgammon/plugins/blob/master/Learning_Mapper.lua
As mentioned below, RH-click on the “Raw” button on those pages, download the raw files, and save them in your MUSHclient / worlds / plugins directory.
Links for the actual raw files (the ones you should download) are:
- https://raw.githubusercontent.com/nickgammon/plugins/master/Learning_Mapper.xml
- https://raw.githubusercontent.com/nickgammon/plugins/master/Learning_Mapper.lua
RH-click on those two links to download the actual files for the mapper.
Links on this page
- Video showing how to train the mapper
- Fuzzy vs Boolean logic
- Exposed functions
- Testing on various code bases
- Database management tools
- Do your own analysis
- Convert another mapper database to this one
What is a mapper?
A few years ago now (2010) I released a generic mapper module which was intended to allow you to (fairly) simply map the MUD you are playing. This has since been incorporated into various MUDs by me, and other enthusiastic people.
An example from that post shows how you can get a good idea of where you are, and where and what the surrounding rooms are:

You can zoom in or out, and colour various important rooms, like shops:

The mapper can be dragged around, and resized to your convenience.
You can LH click on any visible room to speedwalk to that room by the shortest route.
Speedwalking is “throttled” so that it only moves from one room to the next once you arrive there. Even then you can add in a configurable delay, in case the MUD requires it.
Speedwalking auto-cancels if it detects it has ended up in an unexpected room number enroute.
There is a generic “room finder” built in. For example, nearby shops, trainers, portals, or match on text in the room name. Found rooms can be walked to by just clicking on the hyperlink in the list of found rooms.
You can RH click on a room to do other actions, like marking a room as a shop, or adding some free-format notes (eg. this room has quests)
If you hover over a room with the mouse a message appears (room name, exits, first sentence of description)
Recently trod paths are shown with a thicker line, so you can see where you have come from.
How do you add a mapper to your own MUD?
In the past this has been tricky, as the mapper needs to “know” what room you are in, what the exits are, and where they lead. I did a post in 2014 describing how you could adapt the mapper to your MUD, with a considerable amount of work adding triggers and aliases to detect rooms, exits and movements. As a lot of MUDs have different styles of output it has not been really practical to take a plugin from one MUD and use it on another.
The two major things the mapper needs to know are:
- A unique way of identifying what room you are in (so it can tell one room from another one)
- What exits a room has, and where they lead
Enter the “learning” mapper
After fielding yet another request to adapt the mapper to a MUD, I thought of the idea of making a generic interface, where you (the end user) don’t need to write any code, nor add any triggers or aliases, but just “teach” the mapper what the MUD output looks like.
This is done by Bayesian analysis of the incoming text, after a short training period, where you “teach” the plugin what lines represent what line types. This is very similar to how some spam filters work. Basically you mark email messages as “spam” or “not spam”. Then each word in the message is added to a list with a count of how many times it appeared in spam, and how many times it appeared in not spam. For example:
Spam words
- winnings
- lottery
- inheritance
- millions
- guaranteed
- revenue
Not spam
- mirror
- cupboard
- children
- visit
- weather
Neutral
- and
- the
- is
- are
- then
Of course, some emails may have both spam and not spam words, along with neutral ones. However if the majority of words are spam, then an overall rating is given to the email, and it is classified as spam.
References
How does this help?
If we know the line types then we can do some useful things:
The description of a room can be used to generate a unique identifier for that room. We do that by “hashing” up the room description to get a 25-character hex string like this: “7CDA6EAED3A94997F6DF9F364”. If the description doesn’t change then a room with that description will always have a unique hash.
The exits line can be used to work out which exits the room has.
The room name can be used to add room names to the mapper window.
The prompt line can be used as a trigger to display the room in the map. If we hit a prompt line, and we also had a description and exits, then we know enough to redraw the map with the current room centered.
How do you train the mapper?
First you install the mapper plugin, and put its associated Lua file into the “plugins” directory for MUSHclient. The plugins directory is located under the “worlds” directory, which will be a directory under where MUSHclient was installed.
How to install the mapper
Go to this link: https://github.com/nickgammon/mushclient/blob/master/lua/mapper.lua
RH-click on the “Raw” button and save the file mapper.lua to your <MUSHclient installation folder> -> lua directory.

Note: This will overwrite an existing file. This updated mapper.lua file has two lines of bug fix in them.
Then go to this link: https://github.com/nickgammon/mushclient/blob/master/lua/serialize.lua
RH-click on the “Raw” button and save the file serialize.lua to your <MUSHclient installation folder> -> lua directory.
Note: This will overwrite an existing file. This updated serialize.lua file has a bug fix re serializing the words “true” and “false”.
Then go to this link: https://github.com/nickgammon/plugins/blob/master/Learning_Mapper.xml
RH-click on the “Raw” button and save the file Learning_Mapper.xml to your <MUSHclient installation folder> -> worlds -> plugins directory.
Now go to this link: https://github.com/nickgammon/plugins/blob/master/Learning_Mapper.lua
RH-click on the “Raw” button and save the file Learning_Mapper.lua to the same directory (the plugins directory).
You should now have those two files in your plugins directory (along with other ones that came with MUSHclient).

The Lua file has the code for the learning mapper. The XML file has the plugin information, such as aliases, help information etc.
Open the world file for your MUD. This is where you will add the mapper plugin.
Go the MUSHclient File menu and choose Plugins:

Click on “Add” and then select the file Learning_Mapper.xml (not Learning_Mapper.lua) that you downloaded, and click Open. After you have done that the mapper plugin should appear in the plugins list.

Close the Plugins dialog.
You should now see the mapper window and the training window below it.

Starting training
Then log into your MUD and type look to see the room you are in. Select the room name, or part of the room name. Double-clicking on a word in the room name will do that.
Then click on the “Room name” -> “Yes” button as shown:

(If you don’t see a room name, just skip that step)
Then select all of the description lines as shown (click and drag over all the lines) and click on “Description” -> “Yes”.

Then select the exits line (or lines) as shown and click on “Exits” -> “Yes”.

Then select the prompt line as shown and click on “Prompt” -> “Yes”.

If you walk around the MUD you should see other rooms automatically recognizing the trained line types. If not, repeat the training for other rooms.

Correcting mis-recognized lines
As you walk around keep an eye on the “status window” on the right. That shows what line types the mapper has deduced. If it is wrong then train it to correct it. For example:

In this case it hasn’t recognized the room name. So, select the room name and click on “Room name” -> “Yes”.
It also thinks the line “A guard of the city stands at the ready.” is a description when it isn’t. So select that line and click on “Description” -> “No”.
Do this a few times and it should recognize both the words, and the line colours for different line types.
Watch for missing descriptions
You will probably find in the early minutes of training that description lines are not always fully recognized. This is bad because the room description will appear to change, and therefore its hashed room number will change, as learning progresses elsewhere. For example:

The middle line there was not recognized, so select the entire description and click on “Description” -> “Yes”. The more words you train the better, so it is better to train a paragraph rather than one line.
Once you retrain a line type, the map may make the current room seem to be disconnected from other rooms. You can fix this by visiting nearby rooms and going back again, to re-establish the links with the exits correctly.
Differences between MUDs
It would be nice if the mapper worked “out of the box” for every MUD. However since various MUDs present their room information in different ways you may need to change some of the mapper configuration items. This is done by typing:
mapper config <option> <value>
The current settings can be found by typing “mapper config”, for example:
All mapper configuration options
------------------------------------------------------------
mapper config when_to_draw prompt
mapper config activate_description_after_exits No
mapper config activate_description_after_room_name No
mapper config add_newline_to_prompt No
mapper config blank_line_terminates_line_type Yes
mapper config exits_on_room_name No
mapper config include_exits_in_hash Yes
mapper config exits_is_single_line Yes
mapper config prompt_is_single_line Yes
mapper config exit_lines_start_with_direction No
mapper config status_background black
mapper config status_border #1B1B1B
mapper config status_text lightgreen
mapper config uid_size 4
mapper config show_info No
mapper config show_warnings Yes
mapper config show_room_and_exits No
------------------------------------------------------------
Type "mapper help" for more information about the above options.
Number of times line types trained: 31.
Type "mapper corpus info" for more information about line training.
Show mapper training window and status: Yes
Type "mapper learn" to toggle the training windows.
The options between the hyphens can be directly typed into the command window. Or, you can copy one of them, paste into the command window, and change it (for example, change “Yes” to “No”).
You could also share these options with other players, so that if you find a certain combination works best, tell them to use those options (copy and paste).
You can see from the information line above that it took 31 training clicks to train the mapper for this particular MUD.
Multiple exit lines
Some MUDs have multiple lines for exits, for example:

In this case, just select all the exits line when training them to be exits.
However if the exits line is always a single line then it is better to tell the mapper that:
mapper config exits_is_single_line YES
When to draw
Many MUDs show lines in this order:
- Room name
- Description
- Exits
- Prompt
In this case we want to draw the room when the exits arrive. So you want the option:
mapper config when_to_draw exits
(The room is actually drawn when the next non-exits line arrives after the exits line, in case there are multiple exits lines).
Some MUDs however show the exits line after the room name, like this:

- Room name
- Exits
- Description
- Prompt
In this case we want to draw after the description has (fully) arrived. So you want the option:
mapper config when_to_draw description
Force drawing on exits line
A problem with timing can occur if you get an exits line, and then a prompt which is not terminated by a newline. In that case the mapper waits for the prompt line to be terminated. If you are sure that exits are always on a single line, then you can activate this option:
mapper config exits_is_single_line Yes
Ignore bogus description lines
MUDs may have bogus description lines appear during normal playing, so it is best to tell the mapper to ignore lines that look like descriptions, until after a room name arrives:
mapper config activate_description_after_exits Yes
It can also be helpful to disable description lines until after a room name arrives (this won’t apply if your MUD doesn’t show room names):
mapper config activate_description_after_room_name Yes
Add newline to prompt
If the last thing received was a prompt, and the prompt did not have a newline, then the mapper may not recognize the line-type change, and still show the previous room. There are various ways of fixing that:
Try activating world configuration -> Appearance -> Output -> “Convert IAC EOR/GA to new line”
If the MUD has prompts, try forcing a newline after a prompt (the suggestion above might do that)
For example, on some MUDs you can change the prompt like this: PROMPT %hH %mM %vV>!
In that case the “!” tells the MUD to send a new line. See your MUD documentation for details.
You can also try activating the automatic adding of newlines after simple prompts. Type:
mapper config add_newline_to_prompt YESIf you have an MXP-enabled MUD this might not be a good idea, as MXP uses < and > symbols a lot. In that case use one of the other suggestions above.
Exits on room name line
Some MUDs may put the exits on the same line as the room name, for example:

In this case you want to activate the options:
mapper config exits_on_room_name YES
mapper config when_to_draw description
The first one tells the mapper to pull the exits from the room name, and the second to redisplay the map at the end of the description.
Include exits in hash
The mapper includes the exits in the room as part of the hashed room ID. This is to help navigate through parts of the MUD with identical descriptions. Without including the exits they will all appear to be the same room. With the exits included they become different rooms, providing the exits are different.
However some MUDs change the exits shown (for example, if you unlock a door). In that case you should not include the exits in the hash, otherwise the room will seem to be a different room every time the number of exits changes. To do this type:
mapper config include_exits_in_hash NO
What you can do with the map
As you walk around in the MUD you are both training the mapper to recognize line types, and also mapping. Keep an eye on the training information window on the right, to make sure room names are recognized, all lines of the description, and exits. If not, select them and train the appropriate type. If you are happy with the training you can close the training window (click the X) or type “mapper learn” to toggle the learning and information windows.
Sometimes it helps to go back and forwards between rooms to learn the exits which go each way (to and from the room).
You can mouse-over any room to see a pop-up box to tell you the room name, and the first sentence of the description.

You can RH-click on any room to mark it as a certain type (shop/trainer/bank), add a free-format note, or view the full description for it. You can also delete any exits that were erroneously added by the mapper.

The free-format notes are intended for you to add any useful information you might want to, for example that this room has a:
- Healer
- Quest-giver
- Repairer
- Food or water
- Guild
- Portal
Finding things
Free-format search
Type “mapper find
mapper find shop

Three things are searched:
- Room name
- Description
- Notes
Thus, you can search your own notes with this.
The links shown can be clicked on to speedwalk to that room.
Finding shops, trainers and banks
mapper shops --> find nearby shops
mapper trainers --> find nearby trainers
mapper banks --> find nearby banks
Find where a room is
Each room has a “hashed” ID which is displayed in the room information when you mouse-over the room. Only some characters are displayed, you can control how many by the configuration option “uid_size”, for example:
mapper config uid_size 4
You may want to remember important location IDs, because then you can find where they are like this:
mapper where 55e
The mapper will respond (if it can):
Path to 55E is: 2n 2e 5s w
Go to a room by ID
You can also go directly to a room by typing “mapper goto
mapper goto 55e
Find all rooms with notes
You can type “mapper notes” to display all nearby rooms which you have set a note for:
mapper notes
Exporting and importing the map and learning corpus
If you want to share your map or corpus, or use them for a different character, you can export them:
mapper export map
mapper export corpus
And then you, or someone else, can import them:
mapper import map
mapper import corpus
You cannot import a map on top of existing mapped rooms, so if you plan to import one, you must first clear out your existing one:
mapper reset map
The same applies to the corpus.
Suggestion: Use the export feature above to back up your map database, if you have explored many rooms.
Disclaimer
This mapper was designed to work with many MUDs, without needing any coding or adding of triggers and aliases. Basically, to be useable by anyone who is prepared to spend 15 minutes training its line type recognition.
Having said that, some types of MUDs are just not suitable for it. In particular MUSH games like PennMUSH tend to have free-format exits, for example:
<ET> Enter Tavern <BN> Building nexus <IN> The Inn <ROPE> Climb the rope
These sorts of exits do not conform to the usual north/south/east/west paradigm, and thus the mapper will have trouble recognizing them, or indeed, drawing a map of them.
Similar remarks apply to MOO codebases.
Basically, your MUD will probably work if it conforms, at least to a large extent, to the examples above.
In particular you would want to see something like this:

That is, well-defined and separated:
- Prompt
- Room name
- Description
- Exits
As explained above, it is OK if the exits come before the description. What would throw the mapper out is if a MUD mixes up room information with exits, the people in the room, and the contents of rooms, all in one large paragraph. It would be hard then to separate out what is fixed description and what is variable (like, if someone enters or leaves a room).
Tips
If the mapper seems to lag behind drawing a new room, make sure that you get a complete line after the exits line.
You can try activating the automatic adding of newlines after simple prompts. Type “mapper config add_newline_to_prompt YES”.
You can also activate the option “exits_is_single_line” if your MUD always has exits on one line.
If the MUD supports colours, then use them. The mapper uses the colour of lines to distinguish them from each other.
Try activating world configuration -> Appearance -> Output -> “Convert IAC EOR/GA to new line”
If the MUD has prompts, try forcing a newline after a prompt (the suggestion above might do that)
For example, on some MUDs you can change the prompt like this: PROMPT %hH %mM %vV>!
In that case the “!” tells the MUD to send a new line. See your MUD documentation for details.
If room descriptions are not shown every time you enter a room (but only the first time) turn that option off in the MUD configuration (eg. “toggle brief”). Consult your MUD help files for how to do that, or ask in general chat.
Also try training prompt lines (they are not otherwise used, but a prompt line helps terminate a non-prompt line)
If the MUD shows a minimap on the left or right side of description lines, turn that option off in the MUD configuration (eg. “toggle minimap”). Consult your MUD help files for how to do that, or ask in general chat.
It is important that temporary things (like mobs in a room, people in a room, items on the ground, chat messages) are not considered part of the description. If they are select that line and click “Description: No”.
If the MUD shows everything in one colour, try activating colour output (eg. “term ansi”). There may be configuration options to colour certain types of lines (eg. “ansi roomshort light green”). This will help with recognition of line types. The exact options will vary from MUD to MUD.
An exit line like: “South: A Room in Mud School” will give an erroneous link to the “in” direction. You can delete unwanted exits by RH-clicking on the room and selecting “Delete an exit”.
If you have a MUD which you think should work, but doesn’t, please reply and provide a link to the MUD (IP address and port). Also show your current configuration choices:
mapper config
Also, describe in what circumstances it is not working (eg. a screenshot). This forum does not support uploading images, you can upload them to https://imgur.com/ or similar.
View the corpus
If you want to see what “learning” the mapper has been doing, type “mapper corpus”. That will show you a lengthy lot of information along these lines:
========================================================================
Description
========================================================================
----------------------------------------------------------------------
Foreground colour of first style run
----------------------------------------------------------------------
Value Yes No Score
------- --- --- -----
white 4 0 0.70
gray 17 0 0.74
olive 5 0 0.71
silver 2 0 0.67
----------------------------------------------------------------------
First word in the line
----------------------------------------------------------------------
Value Yes No Score
------- --- --- -----
2 0 0.67
character 2 0 0.67
delete 1 0 0.63
down 1 0 0.63
east 1 0 0.63
happening 1 0 0.63
however 1 0 0.63
kidnapping 1 0 0.63
mud 2 0 0.67
north 1 0 0.63
please 1 0 0.63
school 1 0 0.63
some 1 0 0.63
surrounding 1 0 0.63
surrounds 1 0 0.63
swamp 1 0 0.63
the 3 0 0.69
theme 1 0 0.63
time 1 0 0.63
towering 1 0 0.63
we 1 0 0.63
west 1 0 0.63
will 1 0 0.63
----------------------------------------------------------------------
All words in the line
----------------------------------------------------------------------
Value Yes No Score
------- --- --- -----
a 6 0 0.71
adult 2 0 0.67
advanced 1 0 0.63
all 2 0 0.67
almost 2 0 0.67
an 2 0 0.67
and 9 0 0.72
anytime 1 0 0.63
are 2 0 0.67
area 3 0 0.69
as 1 0 0.63
ask 1 0 0.63
at 1 0 0.63
bases 1 0 0.63
basic 1 0 0.63
be 1 0 0.63
beginnings 1 0 0.63
You can see that description lines usually start with the colour gray. The word “and” appears a lot (as expected).
However exits look quite different:
========================================================================
Exits
========================================================================
----------------------------------------------------------------------
Foreground colour of first style run
----------------------------------------------------------------------
Value Yes No Score
------- --- --- -----
silver 3 0 0.69
----------------------------------------------------------------------
First word in the line
----------------------------------------------------------------------
Value Yes No Score
------- --- --- -----
3 0 0.69
----------------------------------------------------------------------
All words in the line
----------------------------------------------------------------------
Value Yes No Score
------- --- --- -----
east 1 0 0.63
exits 3 0 0.69
north 2 0 0.67
south 1 0 0.63
southwest 1 0 0.63
up 1 0 0.63
west 1 0 0.63
Clearly exits in this MUD are in silver colour, and consit exclusively of compass direction words. The difference between the corpus entries is how the mapper works out the line types.
In the examples above lines have been trained by clicking “Yes” rather than “No”. An example of both is:
========================================================================
Exits
========================================================================
----------------------------------------------------------------------
Foreground colour of first style run
----------------------------------------------------------------------
Value Yes No Score
------- --- --- -----
teal 4 0 0.70
silver 0 8 0.28
In this case we can see that exits lines are shown in teal but not silver. If the mapper identified a silver line as an exit line then by selecting that line and clicking “Exits” -> “No” then it has learned that silver lines are not exits.
Other line types will be different again. For example:
- A prompt line is unlikely to have “kidnapping” in it. It will be more likely to have numbers, and short words like “hp”, and “mana”.
- Chat messages are likely to have player names in them and general conversation.
- Lines listing room contents will be likely to have objects in them, rather than room descriptions.
- Lines listing what mobs or players are in a room will have mob or player names, rather than room descriptions.
- Combat lines will have action verbs like “slashed” and “hacked” rather than descriptive words.
Saving the map
The mapping database is saved in the plugin’s “state” file which is automatically saved when you save the world file. Thus you must make sure to save the current world file, in order to save the map (and the mapping corpus). Also you might want to save them separately as shown below just in case.
mapper export map
mapper export corpus
Video showing how to train the mapper
Updates
Since making the video above, I have been making various improvements in order to make the mapper work on a wider range of MUDs. The following differences will be obvious:
The line information (shown on the right of the output) is no longer retrospective. It was getting too complex (and too buggy) to work out how a line might have been processed. So now it remembers how each line is actually processed and shows that. So, if you teach it something (like “this line is a description”) it will no longer update the screen further up for earlier lines.
There are now more configuration options, at present:
mapper config when_to_draw prompt mapper config activate_description_after_exits No mapper config activate_description_after_room_name No mapper config add_newline_to_prompt No mapper config blank_line_terminates_line_type Yes mapper config exits_on_room_name No mapper config include_exits_in_hash Yes mapper config exits_is_single_line Yes mapper config prompt_is_single_line Yes mapper config exit_lines_start_with_direction No mapper config status_background black mapper config status_border #1B1B1B mapper config status_text lightgreen mapper config uid_size 4 mapper config show_info No mapper config show_warnings Yes mapper config show_room_and_exits NoIf things are not behaving as expected you could try activating ‘show_info’ and ‘show_room_and_exits’ for a while.
You can now interact with the mapper from your world file by making triggers to mark certain lines as definitely of a certain type (eg. this is definitely an exit line). This can help in some cases as the Bayesian analysis can be a bit dodgy with short lines. Details for this will be covered in a post below.
There are more training line types:
“Ignore” - ignore these lines (useful for marking a line as definitely not a different type. For example: “You are carrying:”
“Can’t move” - for messages that you can’t move (eg. “The door is locked” / “You are exhausted” / “You are not allowed in there”). Such lines will, if noticed, cancel any speedwalks.
The training line types are in a more logical order: Room name / Description / Exits































