The 'Spock dilemma' (aka emotions)

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).

Interesting stuff …

It sounds like you are writing a general library for social interactions. Originally I understood you were saying the PC in your game was someone/something that could read and influence emotions telepathically. If that was the idea, then maybe that could be all the PC can do, which would not only make the implementation easier, it would focus the player on what the game is about (manipulating emotions).

I appreciate Emily Short’s comment in another thread:

I agree that it would take a very long time, but I do believe it would work. I can’t prove that to someone else though.

But I totally agree with focusing on what is most appropriate for the story at hand, not only to keep the implementation manageable, but also to communicate to the player how they are meant to interact with this particular game.

That said, I think a general social engine could still work. It looks like someone has already attempted something like this for the Unity engine. From the description, it tracks relationships between NPCs (with emotions influenced by NPC personalities), though the application that calls it is responsible for triggering it when needed and acting on its responses.

Here are a few of the challenges around building a general system:

– Completeness. Can you list all the social actions that exist even in your own culture? What about in other cultures? What about the fact that some of those verbs are much larger-scale than others (e.g. “smirk at X” vs “blackmail X” – the one being a fleeting momentary gesture, the other an extended interaction)?

– Context. The same behavior can mean radically different things in different situations. Resolving this is likely to require a knowledge base and sophistication on nearly the scale of that required to resolve natural language input; you’re probably going to need to do some machine learning.

– Resulting states. In addition to figuring out everything the player can do or any of the other characters can do, you would also have to work out what effects those interactions are going to have.

— What’s your model of human relationships? It might seem like you could have a bunch of relationship names and assign them between characters: “boss”, “parent”, “friend”, etc. But some of those relationships are objectively existent and others are subjective – I might think of you as a friend while you don’t agree that we are friends, for instance. And multiple relationships can exist between people at the same time: if you’re working in a family business, your boss might also be your uncle. So you’re going to need superpositions of possible relationships, rules for how those relationships change, rules about reciprocity and officialness of change, and so on.

— How about mutual opinions? Versu allowed characters to form opinions about others on multiple axes at once, so a character could think that another was attractive but foolish (for instance), or friendly but of low status.

— And emotional states? Often our feelings are superpositions of other, simpler emotions: you might be a little annoyed and a little amused by the behavior of a noisy toddler. Games tend to simplify that a bit, but I think a straight-up positive-negative axis is going to be way too simple for the kind of system we’re talking about here, so we need something more complex.

– Response. Are you automating your characters doing specific things in response to their emotional/relationship states? Are those actions are going to be suitable in all possible story contexts? (Hint: no, they are not.) If you’re leaving it up to authors to write in all the ways that people can react to situations, that poses a substantial authoring burden for using the engine; but finding even an acceptable set of defaults can be pretty challenging.

– Scaling and skewing the engine’s behavior for different story contexts. One of the things we had to deal with Versu was that we wanted different levels of NPC response in different stories. In a realistic drama with a two-hour running time, you want the characters to have fairly moderate, cumulative reactions to emotional inputs, so you can gradually work your way up to being close to someone. In a ten-minute farce, you want every move to be amplified to and to produce cascades of comedic results. You might think, “oh, we can just slap a scalar multiplier on any numerical changes,” but in practice there were lots of other tuning effects we had to look at.

Okay. So let’s imagine you’ve managed to model all that. Now you also have to make that model transparent enough to the player that they can act with agency and never feel like your simulation is buggy. To (very loosely) paraphrase Aristotle, game systems must appear plausible, where real life is confined only to the possible.

If you’ve ever played the game Oblivion (or any of the Elder Scrolls series of RPGs) you would know that as a player you could converse with NPCs (in Oblivion it’s a minigame) and raise (or lower) their regard for the player. Raise it high enough they sold you rare items, offered to tag along, gave you you discounts as vendors or even ignored criminal acts (when observed since you could try to sneak and be undetected). Lower it and you got the opposite effects, perhaps even the NPC initiating an attack (which could be important in order to complete a quest to kill an NPC in a manner that does not constitute a murder catching attention of the authorities).

As far as the extension goes the goal is to provide the framework but very likely will leave it up to the game to specify what should actually happen. So the rulebooks or whatever I end up using will be provided by the extension, leaving the game to set up rules, specific character values, and whatnot. The extension just provided all the glue so the game itself does not need massive boilerplate type code to get such a system going.

If I really wanted to go for broke I’d use something like support vector machines, neural nets such as LSTM (long short term memory [Schmidhuber et al.] which are likely better for this kind of time series problem) and train them to recognize patterns of actions then have their outputs deciding the character’s moods and perceptions (you would train each character’s net by using examples of how that character would react in several predefined (eg: concept) situations, then have the net extrapolate on (filtered) events as they transpire in an actual game). Inform doesn’t have them but one could add such a module to one of the glulx terps and have glulx extension opcodes for accessing the previously-trained nets.

In my own game it’s basically going to boil down to character-value rules that react to observation of various actions (or kinds of action) with each particular value handling its effect on mood and/or perception (which of course may test for the presence of other values on the observer). Then assign the character-values onto each person as appropriate. I don’t have a full-blown telepath in the game. I have a healer type character who is affected by strong feelings around her because they naturally radiate outward (as one may suspect she’s kind of shy as a result) and her powers may affect a person externally (wounds) or internally (all the other priesty type stuff). Though when her power evolves she could in theory focus on a person then concentrate to access that person’s mind (think like how Prof. Xavier can sense or influence a person via Cerebro if he focuses and concentrates on a specific person). It’s not an all-the-time thing like Deanna Troi can do in Star Trek TNG. It’s also something that can be painful since a person’s natural tendency is to defend against the intrusion and breaking down that shield causes injury. This power is obviously something that needs to be used with care, even to a willing subject (an important first step is to make sure the target is in a deeply relaxed state). Another character has a related kind of empathic power (blue mage roughly approximates her powers but there are also elements of communication, mostly in dreams) towards creatures/animals rather than people.

Emily is right in that a generalized system is too large a project since it frequently will require far more effort to cover a decently complete generality when the game the creator actually makes only uses a tiny fraction of the possibility. Not that such a project couldn’t be done but it’s a huge undertaking and would require collaboration from several authors. It’s not something one creator would make as a step in a specific game since the interaction component will consume 99.9% of the author’s available time for the project leaving none for the actual game the author wishes to make.

That’s something I’m looking at right now – what goes into a relationship between people, and how that affects their behaviour. Roles like “mother”, “friend” or “king” have an effect, but there are clearly a lot of other things too.

And there is also the interaction between emotions (as immediate reactions to events), attitudes / opinions (more constant but in flux as well) and personality (more or less fixed).

That’s a really good point; the user of such an extension would need access to enough of the system to tune it properly, too.

Here I have a slightly different vision, I think.

An alternative “use” for NPCs is just to make the experience richer and deeper, without necessarily needing to get something out of them (e.g. get them into a certain emotional state). This doesn’t imply a sandbox environment, though.

I can imagine a companion NPC that has all kinds of interesting reactions throughout the story – not enough to derail the plot (unless the player deliberately pushes the NPC towards some kind of extreme behaviour), but enough to feel like you are dealing with a real person. Not totally unlike playing a multiplayer game.

My game will be using Plutchik (via the extension) to model emotions and a character-values system (extension may provide the relation and any glue but the game itself has to define specific character-values) to model behavior/reactions. Anything needing to be more specific will be handled in a per-character manner. I’ll also be using scenes to set up/remember context (eg: global economy currently bad) since the game can activate and deactivate them at will. Properties on regions can represent localized contexts such as cultures (so non-specific NPCs may act a certain way in a particular region unless individual properties on a particular person override them).

I’ve added a follow up blog post to the previous one on emotions: NPC Emotions, part 2. It covers emotion intensity, the focus of emotions, moods and emotional openness.

This has been really interesting to look at; I’d love to know people’s thoughts if they have any.