§7.11. Character Knowledge and Reasoning

A character may be endowed with knowledge and even reasoning skills. Relations form quite a good way of keeping track of such problems: for instance, we can allow characters to be acquainted with one another with a relation such as

Lucy knows Lady Cardew.

Or we might keep track of more complicated attitudes between characters, as in Murder on the Orient Express, in which some characters suspect others of the crime.

Alternatively, we might have a list of salient facts that are important in our story. We might declare these as values, and then characters could know, learn, and forget entries as appropriate:

A fact is a kind of value. Some facts are defined by the Table of All Known Facts.

Knowledge relates various people to various facts. The verb to know (he knows, they know, he knew, it is known) implies the knowledge relation.

Table of All Known Facts
fact summary
shoe-size "Lucy wears a size 9 shoe."
sunset-time "Sunset is at 8:22 PM this evening."

Lucy knows shoe-size.
Bob knows sunset-time and shoe-size.

Or again we might keep a whole database of information in a table: the characters in Questionable Revolutions know dates, countries, and a short description for each of several rebellions and popular uprisings, while in Queen of Sheba, Solomon is able to answer who, what, where, when, and why questions about a range of topics. This kind of approach is most useful when the characters need to display a deep knowledge of a particular field. The facts stored in the Table of All Known Facts, above, are comparatively sparse, because there we are designing a story in which not all data about the world is equally valuable: Lucy doesn't know the shoe size of every person in the story, because for some reason it is only her own shoe size that matters. On the other hand, the Table of All Known Facts can store different kinds of information, whereas the revolutions table has no way of storing shoe sizes or sunset times. And Murder on the Orient Express works differently again, because it is storing knowledge that concerns people and things that already exist in the world model, rather than abstract ideas. Our way of modeling character knowledge, in other words, will depend quite a lot on what kind of knowledge it is.

The possibilities of character reasoning are similarly broad, but The Problem of Edith introduces one kind: the character has a concept of how different conversation topics relate to one another, so that when she is asked about a new keyword, she picks a response that makes the question most relevant to the conversation already in progress.

We end with a longer scenario, in which we track what the character knows about the player and the conversational state: in Chronic Hinting Syndrome, the main character guides conversation in the direction he intends it to go, with the player's sometimes-reluctant participation.

* See Obedient Characters for a character who needs to be taught how to perform actions before doing them

* See Characters Following a Script for a programmable robot who can be given whole sequences of actions to perform


arrow-up.pngStart of Chapter 7: Other Characters
arrow-left.pngBack to §7.10. Character Emotion
arrow-right.pngOnward to §7.12. Characters Following a Script

**ExampleMurder on the Orient Express
A number of sleuths (the player among them) find themselves aboard the Orient Express, where a murder has taken place, and one of them is apparently the culprit. Naturally they do not agree on whom, but there is physical evidence which may change their minds...

***ExampleThe Problem of Edith
A conversation in which the main character tries to build logical connections between what the player is saying now and what went immediately before.

Suppose we want the player to ask questions of slightly more complexity - we might want to build in a system that understood "who", "what", "where", and "when", for instance. We could use a topic table for this, too:

paste.png "The Queen of Sheba"

Interrogative is a kind of value. The interrogatives are who, what, when, where, how, and why.

Current question is an interrogative that varies.

After asking someone about something: respond to the question. After answering someone that something: respond to the question.

After telling someone about something: say "You're here to ask questions and test Solomon's wisdom, not to give him a sample of your own."

Table of Wise Answers

topic

question type

reply

"rain/weather/clouds/cloud/rains"

what

"'Clouds are a disturbance made by the paths of birds,' Solomon replies. 'The air beaten by their wings becomes agitated, as when a river is stirred and the mud churns up.'"

"rain/weather/clouds/cloud/rains"

where

"'Weather is contained in a great silk bag which holds in the heavens,' replies Solomon."

"hunger/food/eating"

when

"'Sorry, are you getting hungry?' he says, and rings a bell to summon servants."

"hunger/food/eating"

why

"'Men were made to need food in order that they must farm and cook and dine together,' Solomon replies. 'Otherwise, they might live apart, each sufficient in himself. But no man can feed himself alone all through his life.'"

"Solomon/he/himself"

who

"'As you see,' he says, holding out his arms to each side."

"Solomon/he/himself"

what

"'I am an ordinary man,' he answers."

One of the nice things about this system is that it only resets the "current question" when we get a new question word. For instance, this test will produce different replies to the question about Solomon himself, because the second time he is still in the mode of answering "what" questions:

Test me with "ask solomon about himself / ask solomon what rain is / ask solomon about himself".

If Solomon is to live up to his reputation at all, his wisdom table will have to be quite a bit longer - though one also would want to be careful, because forcing the game to cycle through a really immense table could be quite time-consuming. In fact, for the sake of this example, let's reward the player for managing to stay within the (narrow) range of Solomon's knowledge:

The Hall of Almug Tree Pillars is a room. "The pillars of the room are made of almug tree, the ceiling made of silk and the floor of glass." Solomon is a man in the Hall of Almug Tree Pillars. Solomon has a number called wisdom. The wisdom of Solomon is 0.

Every turn:
    if the wisdom of Solomon is 3:
        say "Truly, Solomon has answered all your questions, and his wisdom is even as great as you had heard!";
        end the story saying "Your heart beats strangely fast".

When play begins, say "'Oh, you've arrived,' says Solomon."

In a real game we'd need to be a great deal subtler. All the same, if we have a character of quite limited resources to present to the player, it's a good idea to give the player some incentive to stay on topic, ask questions the character can answer, and generally interact within the parameters we're prepared for.

Now, this last bit requires some trickery from later chapters, particularly those on Understanding and Activities, to pull the question words out of the player's command:

After reading a command:
    if the player's command includes "[interrogative]", now the current question is the interrogative understood.

To respond to the question:
    repeat through the Table of Wise Answers:
        if the topic understood includes topic entry:
            if the current question is the question type entry:
                say "[reply entry][paragraph break]";
                increment the wisdom of Solomon;
                rule succeeds;
    say "Solomon looks blank, appalled by a question for which he was not prepared.";
    end the story saying "You have befuddled Solomon!"

Understand "ask [someone] [text]" as asking it about.

And now we have a game that will accept (though not always respond very sensibly to) questions of almost any form we might put to another character: ASK SOLOMON WHAT RAIN IS will be answered, but then again, it won't be distinguished from, say, ASK SOLOMON WHETHER THIS PERSISTENT RAIN IS A DIVINE PUNISHMENT OR WHAT.

All the same, a system that allowed the player a bit more specification of questions than simple keyword-use might be useful in a mystery game, for instance, where we might want to let our detective conduct inquiries into specific details. An alternative approach to the rather free one above would be to force the player to use only questions of the form WHAT IS RAIN? or WHO ARE YOU?: this would cut down on false-positive matches. But we might still choose to store the responses in a table of this type.

***ExampleThe Queen of Sheba
Allowing the player to use question words, and using that information to modify the response given by the other character.

Suppose we want the player to ask questions of slightly more complexity - we might want to build in a system that understood "who", "what", "where", and "when", for instance. We could use a topic table for this, too:

paste.png "The Queen of Sheba"

Interrogative is a kind of value. The interrogatives are who, what, when, where, how, and why.

Current question is an interrogative that varies.

After asking someone about something: respond to the question. After answering someone that something: respond to the question.

After telling someone about something: say "You're here to ask questions and test Solomon's wisdom, not to give him a sample of your own."

Table of Wise Answers

topic

question type

reply

"rain/weather/clouds/cloud/rains"

what

"'Clouds are a disturbance made by the paths of birds,' Solomon replies. 'The air beaten by their wings becomes agitated, as when a river is stirred and the mud churns up.'"

"rain/weather/clouds/cloud/rains"

where

"'Weather is contained in a great silk bag which holds in the heavens,' replies Solomon."

"hunger/food/eating"

when

"'Sorry, are you getting hungry?' he says, and rings a bell to summon servants."

"hunger/food/eating"

why

"'Men were made to need food in order that they must farm and cook and dine together,' Solomon replies. 'Otherwise, they might live apart, each sufficient in himself. But no man can feed himself alone all through his life.'"

"Solomon/he/himself"

who

"'As you see,' he says, holding out his arms to each side."

"Solomon/he/himself"

what

"'I am an ordinary man,' he answers."

One of the nice things about this system is that it only resets the "current question" when we get a new question word. For instance, this test will produce different replies to the question about Solomon himself, because the second time he is still in the mode of answering "what" questions:

Test me with "ask solomon about himself / ask solomon what rain is / ask solomon about himself".

If Solomon is to live up to his reputation at all, his wisdom table will have to be quite a bit longer - though one also would want to be careful, because forcing the game to cycle through a really immense table could be quite time-consuming. In fact, for the sake of this example, let's reward the player for managing to stay within the (narrow) range of Solomon's knowledge:

The Hall of Almug Tree Pillars is a room. "The pillars of the room are made of almug tree, the ceiling made of silk and the floor of glass." Solomon is a man in the Hall of Almug Tree Pillars. Solomon has a number called wisdom. The wisdom of Solomon is 0.

Every turn:
    if the wisdom of Solomon is 3:
        say "Truly, Solomon has answered all your questions, and his wisdom is even as great as you had heard!";
        end the story saying "Your heart beats strangely fast".

When play begins, say "'Oh, you've arrived,' says Solomon."

In a real game we'd need to be a great deal subtler. All the same, if we have a character of quite limited resources to present to the player, it's a good idea to give the player some incentive to stay on topic, ask questions the character can answer, and generally interact within the parameters we're prepared for.

Now, this last bit requires some trickery from later chapters, particularly those on Understanding and Activities, to pull the question words out of the player's command:

After reading a command:
    if the player's command includes "[interrogative]", now the current question is the interrogative understood.

To respond to the question:
    repeat through the Table of Wise Answers:
        if the topic understood includes topic entry:
            if the current question is the question type entry:
                say "[reply entry][paragraph break]";
                increment the wisdom of Solomon;
                rule succeeds;
    say "Solomon looks blank, appalled by a question for which he was not prepared.";
    end the story saying "You have befuddled Solomon!"

Understand "ask [someone] [text]" as asking it about.

And now we have a game that will accept (though not always respond very sensibly to) questions of almost any form we might put to another character: ASK SOLOMON WHAT RAIN IS will be answered, but then again, it won't be distinguished from, say, ASK SOLOMON WHETHER THIS PERSISTENT RAIN IS A DIVINE PUNISHMENT OR WHAT.

All the same, a system that allowed the player a bit more specification of questions than simple keyword-use might be useful in a mystery game, for instance, where we might want to let our detective conduct inquiries into specific details. An alternative approach to the rather free one above would be to force the player to use only questions of the form WHAT IS RAIN? or WHO ARE YOU?: this would cut down on false-positive matches. But we might still choose to store the responses in a table of this type.

***ExampleQuestionable Revolutions
An expansion on the previous idea, only this time we store information and let characters answer depending on their expertise in a given area.

****ExampleChronic Hinting Syndrome
Using name-printing rules to keep track of whether the player knows about objects, and also to highlight things he might want to follow up.