The 'Spock dilemma' (aka emotions)

I have been working on a system to make NPC’s have ‘real emotion’, (farther down the line these emotions will determine actions of NPC’s) but recently all my attempts have come up with a block.

I have the emotions frame such as this.

A person can be neutral, satisfied, disappointed, elated, or enraged.  A person is usually neutral.

What I’m trying to do here is assign values to the emotions so that enraged=5, disappointed=4, neutral=3, satisfied= 2 and elated=1.
Then I’m trying to look for a way where certain actions will change the values, and therefore change the emotion.

EX.
If the player maybe takes the doughnut, add two points to Billy’s emotions. Now Billy’s emotions would be 4.
or
If the player asks George about Monopoly, subtract 4 emotion points, so the emotion would be 1 (elated)

Perhaps it would be easiest to just have:

A person has a number called the emotion. The emotion of a person is usually 3.

If you want to, you can then set up definitions like this:

Definition: a person is elated if its emotion is 1.

And you may want to set up phrases for increasing and decreasing the emotions, so you don’t have to worry about them dropping below 1 or above 5:

To improve the mood of (guy - a person) by (n - a number): now the emotion of guy is the emotion of guy minus n; if n is less than 1: now n is 1.
Is this what you are looking for?

Why do you need numbers? I believe Inform 7 allows you to define emotion as a “kind of value,” of which the possible states are defined not as numbers, but as text, and to use statements like “now the emotion is the next emotion” (I’m not sure about the precise syntax), thus avoiding the need to translate the qualitative emotional states to and from numerical terms.

I think the real complication comes not from making the process numerical, but from identifying all of the possible things that should change a person’s emotional state, and how various things vary depending on what that state is.

I used a vastly simplified version of this system in a scene in which the player is in his boss’s office getting briefed on a mission. I set up the boss so that he has a (qualitatively defined) mood; each time the player does something to annoy the boss (such as trying to leave the room during the briefing), the boss’s mood gets one notch worse, triggering the boss saying something to warn the player that he (the boss) is getting more and more pissed off. If the player ignores the warnings and keeps annoying the boss anyway, eventually the mood reaches a point where more catastrophic consequences ensue.

Robert Rothman

Not a great idea, because the “after” relation between values is circular. If you run the following program:

[code]“Test” by Victor Gijsbers

Test chamber is a room.

Emotion is a kind of value. The emotions are enraged, angry, moderate, pleased and happy.

The player has an emotion. The emotion of the player is enraged.

Every turn:
say “You are feeling [emotion of the player].”;
now the emotion of the player is the emotion after the emotion of the player.[/code]
you will find that the player progresses from happy to enraged.

Of course, you can use checks to make sure that doesn’t happen – but why would this be better than representing the emotional state as a number? Numbers are versatile and easy to use, and you can set up phrases to translate them into the prose you would like to see in the game, if that is necessary.

Don’t you effectively have that issue anyway? Since the number of emotional states that you actually allow is (presumably) finite, don’t you have to build in a check to see when you’ve reached “the end of the line” even if you’re representing the states with numbers? I suppose with numbers, you could allow a character to get more and more angry ad infinitum rather than hitting a maximum-anger state (with the result that you’d need that many additional “positive-emotion” points before you started turning around and hit the state that is one notch less angry than “maximum pissed-offedness”), but I’d think that most of the time you’d want a finite number of states.

Ultimately, I’m not sure it makes a lot of difference whether you use numbers or text; I was just wondering whether the original poster had a particular reason for the numerical approach.

Robert Rothman

Actually that’s perfect!

One quick thing:

  1. Would I just state in code that "If player [does action]:
    now the emotion of George increases by 2.

Okay, fair enough. I often like the versatility of numbers. When it makes sense to have the values ordered, using numbers is almost never a bad idea.

Kinda. That if-statement won’t compile; you probably want to write a carry out rule, or an instead rule, or sneak the statement about emotions into whatever other code you have that actually carries out the command of the player. And you don’t just want to add 2 to an emotion, because that might take it over 5, so you need to check for that. (I would write a companion for that “improve the mood” code I gave you, so you only have to do this in one place.)

Actually, any ladder of values such as the one you’re referring to is internally stored as a series of numbers beginning with 1. In other words, if you define your emotions like so:

An emotion is a kind of value. The emotions are elated, satisfied, neutral, disappointed, and enraged.

…then as far as the Inform 6 template code is concerned, you have defined an emotion as a value ranging from 1 (elated) to 5 (enraged). We can take advantage of that to write phrases that will allow us to manipulate the emotions (sorry) in either their numeric or their word form. The key concept here is “typecasting”, that is, finding out what number goes with a given word value, or vice versa. This is pretty simple:

To decide what number is (E - emotion) as a number: (- {E} -)
To decide which emotion is (N - number) as an emotion: (- {N} -)

Using these two phrases, you can essentially grab the emotion as a number (“let N be the state of the player as a number”), add 2 to it (“let N be N + 2”), and then find the emotion that is paired with that result (“now the state of the player is N as an emotion”). Pretty simple, and I think resulting in pretty much exactly what you were looking for. This approach also lets you continue to use named concepts (elated, disappointed) rather than numbers, which has obvious advantages for source code readability.

Here’s a bit of code that uses Inform’s newer “functional programming” capabilities to provide phrases that will work for any enumerated value. If you’ve also defined a brightness KOV, for example, you can modify it with the same phrase you use to modify emotions, like so:

Here’s the code:

[code]An emotion is a kind of value. The emotions are enraged, disappointed, neutral, satisfied, and elated.

A person has an emotion called state. The state of a person is usually neutral.

To decide what number is (N - value) as a number:
(- {N} -).

To decide which K is (N - number) as (type - name of kind of value K):
(- {N} -).

To decide which K is (V - value of kind K) improved by (N - a number):
let X be V as a number;
increase X by N;
if X is greater than the last value of K as a number:[i.e., if the result is invalid]
decide on the last value of K;
otherwise:
decide on X as a K.

To decide which K is (V - value of kind K) diminished by (N - a number):
let X be V as a number;
decrease X by N;
if X is less than 1:[i.e., if the result is invalid]
decide on the first value of K;
otherwise:
decide on X as a K.

To improve the emotional state of (O - an object) by (N - a number):
now the state of O is the state of O improved by N.

To diminish the emotional state of (O - an object) by (N - a number):
now the state of O is the state of O diminished by N.

[Brief Example:]
There is a room.

When play begins:
improve the emotional state of the player by 2;
say “[state of the player].”[/code]

You’ll see that I’ve also included short forms that work only on the emotions (e.g., “diminish the emotional state of the player by 2”).

–Erik

Interestingly I’ve been working on an extension alongside my game along these lines that implements the Plutchik model: https://en.wikipedia.org/wiki/Contrasting_and_categorization_of_emotions#Plutchik.27s_wheel_of_emotions allowing each person in the game to have a current mood and a perception matrix (“the way X feels about Y”) towards any other person in the game.

It’s still in a “development” status, thus not at a level that would satisfy the extensive submission requirements (absence of test commands/examples being a particular disqualification though there is an example/test game I made for testing the extension in isolation) for placing it on the inform 7 site proper. If there’s interest I could stick what I have thus far up on github (CC-BY license as required by inform 7 for extensions).

Interest! There is interest!

Ditto.

On github: https://github.com/gau-veldt/Emotion-and-Feeling

The next logical (darn you spock!!!) step I think might be some sort of rulebook setup to provide a standardized pattern for modifying behavior when a character has a particular feeling. Though the adjectives provided should already allow things like (assuming I didn’t mess the rule declarations up):

rule for an actor some-action-ing when the actor is sad:
    [...]

Or involving the matrix relations…

rule for an actor greeting some-person when the actor is loathing around some-person:
    [...]

and so forth…

what I did in my extension is take this idea the other way.
Start with the value, then define adjectives based on the value, then define relations based on the adjectives.

I provide helpers to alter the mood that could then be called by rules within a story to enact character mood or matrix (how one character regards other characters) changes.

Here’s a blog entry about NPC emotions, including Plutarch’s model:

intficpossibilities.blogspot.com … tions.html

Useful to know as well. I have not yet come up with any sort of rulebook for changing emotions (it would be a challenging endeavor that needs to set up action classes (action K is a Y behavior) and have emotions react to them). Such a rulebook also wouldn’t cover any new actions defined in the story unless the writer known to set up the appropriate MyNewAction is Y behavior…

I’ll have to work out some rudimentary change heuristics. The good news is if someone already has some sort of heuristics it could probably be easily added with via github PR since my current extension code is indeed open and available to fork/adapt/PR (from the fork) on github (as posted above).

This is a potentially huge area, but it’s fun to think about. As well as working out what affects NPC emotions, their current emotional state needs to be revealed somehow through actions and dialog. There is potential for a game with an “empath” who can tell how others are feeling – similar to video games with thought bubbles above characters.

The next blog entry will either be about NPC personality (which influences their emotions) or about relationships between characters (which change as a response to emotions, and also influence some emotions: you might be happy at your ally’s good fortune, but not your enemy’s).

Thanks for the inpiration to look at Plutarch’s model, by the way!

As things go the game I’m working on has characters that can sense emotional state or impart emotion (with limitations and much concentration and meditation) in another.

Sounds interesting! I’d love to hear how it goes.

Huge enough that I have not yet come up with a concrete set of action sets that could elicit a generalized change of perceptions in characters. Every game may want to do it slightly differently also and there’s just no way to cover all the possible ways an author would want characters to react.

One possibility is to have character values (an enumeration) and the presence of a particular value for an actor could be used in conditions for altering the actor’s regard for another. For instance:

This is off the cuff so may not be fully syntactically sound:

[code]Personal-Value is a kind of value.
Character-values relates various people to various personal-values.
the verb to value implies the Character-values relation.
honesty is a personal-value.
definition: an person is honest if she values honesty.

stealing is an action applying to one person.
understand “steal from [person]” or “pickpocket from/-- [person]” as stealing.
[…]
stealing is being dishonest.

[this sample neglects the concept of undetected theft since the scope of this example is the reaction to a detection, not the detection itself]

[furthermore in a game with multiple viewpoint characters it is possible the player
may be prohibited from stealing at all in any viewpoint character that values honesty]

after an actor being dishonest when an honest person is visible:
[this probably has to be a loop running through all honest people in the room]
[a more complete example would adjust perception incrementally]
now A is disgusted around the actor. [this is the desire/repulsion axis]
[and other complications would be things like the person being stolen from being A’s friend
or enemy (say A also values vengeance in which case this act likely yields a positive perception
rather than a negative one). A values lawfulness is yet another possible twist.]
[/code]

From the few commented parts it’s already evident there could be a number of twists in even a simple set of general values.

PS: One possible change to the extension is to make the axes floating point numbers rather than integral thus allowing fractional adjustments to a character’s mood and/or perceptions of others. It would take quite a bit of rework to adjust the perception matrix to use them (every person needs a perception kind for every other person and the matrix relations then get rewritten as evaluations to test for certain ranges). The main complication being a kind would be needed and these are only ever stored by reference (thus the infamous “FooVar is set to be a FooKind which I can’t set to any value because none exist in the world” error).