simmemory

package module
v0.0.0-...-9a2f946 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

README

simmemory

Dwarven memory: A pretty clumsy attempt to replicate the memory system from dwarf fortress.

Documentation

Overview

Package simmemory provides a sample implementation of toughts/emotions and their storage in short, long, and core memory, based on the Dwarf Fortress wiki: http://dwarffortresswiki.org/index.php/DF2014:Memory_(thought)

Index

Constants

View Source
const (
	IntensityVeryNegative     = -120
	IntensityNegative         = -50
	IntensitySlightlyNegative = -10
	IntensityNeutral          = 0
	IntensitySlightlyPositive = 10
	IntensityPositive         = 50
	IntensityVeryPositive     = 120
)

A range of intensities for thoughts.

Variables

ThoughtGroup maps a thought to its group.

A groupw would determine what emotions are triggered by a thought, and determine what personality traits are used to determine the intensity of the thought.

ThoughtIntensity maps a thought to its intensity. NOTE: In dwarf fortress, the intensity is a positive value, and relies on the connected emotion (which is based on the personality) to determine the actual intensity (and if the actual value is positive or negative). We don't have emotions implemented (since they rely on character traits), so we just use the intensity directly and allow positive and negative values.

This means though that we have to mask the intensity when we compare positive with negative values, which is a downside.

View Source
var ThoughtStrings = [256]string{
	ThoughtNone:       "None",
	ThoughtNewFriend:  "made a new friend",
	ThoughtNewEnemy:   "made a new enemy",
	ThoughtNewPet:     "got a new pet",
	ThoughtLostFriend: "lost a friend",
	ThoughtLostEnemy:  "lost an enemy",
	ThoughtLostPet:    "lost a pet",
	ThoughtNewJob:     "got a new job",
	ThoughtLostJob:    "lost a job",
	ThoughtPromoted:   "got promoted",
	ThoughtDemoted:    "got demoted",
	ThoughtNewBaby:    "had a new baby",
	ThoughtNewSpouse:  "got married",
	ThoughtLostChild:  "lost a child",
	ThoughtLostSpouse: "lost a spouse",
	ThoughtSick:       "got sick",
	ThoughtHealed:     "got healed",
}

Functions

This section is empty.

Types

type Group

type Group byte

Group represents a group of thoughts.

const (
	GroupNone Group = iota
	GroupSocial
	GroupWork
	GroupFamily
	GroupHealth
)

type Memory

type Memory struct {
	Short    [8]Thought
	Long     [8]Thought
	Core     [32]Thought
	AgeShort [8]byte
	AgeLong  [8]byte
}

Memory represents the short, long, and core memory of a creature. Short-, and long term memory have 8 slots, each of which can hold a thought, while core memory has 32 slots.

We also track the number of days a thought has been in memory, as we promote thoughts from short to long memory after 10 days, and from long to core memory after 255 days.

There are certain conditions that need to be fulfilled for a thought to be promoted. If promotion is not possible, the thought is discarded.

TODO: In theory we could store thoughts and their age in the same array and use a step size of 2. This might be more efficient, but I don't really know if that's true.

func NewMemory

func NewMemory() *Memory

NewMemory returns a new memory.

func (*Memory) AddThought

func (m *Memory) AddThought(t Thought)

AddThought adds a thought to the dwarf's memory. A dwarf has 8 short-term memory slots. When a dwarf has a thought, a check is made to see if a memory of that group already exists in a short-term memory slot.

If the thought doesn't fall into an existing group, the new thought will fill an empty slot, or if no slots are empty, overwrite the weakest memory (the one with the weakest emotion) in the 8 short-term memory slots - even if the overwritten memory is stronger than the new one.

If the thought already has one of its group in a memory slot the strongest memory of the two, the new thought and the existing memory, will be kept and the other discarded.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTE: Below are examples that only apply once "emotion" is implemented, which effectively changes the intensity of a thought. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

So if a dwarf is in a particularly bad mood, getting shat on by a bird might be felt more intensely than if they were in a good mood.

For example, a dwarf gets caught in the rain and is dejected (intensity 1/4). If they haven't seen rain in the last year, this will be written to their memory, overwriting the weakest existing memory of a different group.

If they have seen rain in the last year, it will overwrite the previously weaker emotion of being annoyed by the rain (intensity 1/8), or ignore the new experience if the old emotion was the stronger being dismayed by the rain (intensity 1/2).

This mostly leads to a constant cycling of the weakest of the 8 memory slots as new thoughts overwrite each other. An overwritten thought is a forgotten thought.

You can see this in the dwarf's thoughts and preferences screen, they'll mention more than 8 things that they have recently experienced, but they are only being affected by 8 of those things.

The list is not a reflection of what is in their current memory, but is a reflection of what has been in their memory recently. The consequence of this cycling is that short-term memories are mostly fleeting, with a maximum of 7 short-term memories having a lasting effect on a dwarf's mood.

func (*Memory) Log

func (m *Memory) Log()

Log logs the state of the memory.

func (*Memory) PromoteToCore

func (m *Memory) PromoteToCore(t Thought)

PromoteToCore promotes a thought to core memory. Once a memory has remained in long-term memory for 255 days, it has a 1:3 chance of being promoted to core memory and causing one or more personality changes, if the memory is of a group that can be promoted to core memory.

There are 32 core memory slots, and thoughts are promoted to the first empty slot. If there are no empty slots, the weakest thought is overwritten.

Core memories are less impactful than long-term memories, as they are rarely, if ever, revisited. However, the change that is made to the personality of the dwarf is permanent, and this can be for good or bad.

func (*Memory) PromoteToLong

func (m *Memory) PromoteToLong(t Thought)

PromoteToLong promotes a thought to long memory. Once a memory has remained in a short-term memory slot for 10 days it will attempt to be promoted to a long-term memory slot.

There are 8 long-term memory slots, and the procedure works similarly to short-term memory allocations, with one important difference.

When the attempt to promote is made, a check is first made to see if there is an empty slot, if there is an empty slot the memory will be promoted to that slot even if a memory of that group already exists in another long-term memory slot.

It is possible (but very rare) to have more than one memory of the same group in long term memory.

This cannot happen in short term memory. If there are no empty slots a check is made to see if an existing memory of the same group exists.

The promotion will fail if the existing long term memory is stronger, or will overwrite if the existing long term memory is weaker.

If there are no empty slots and no existing memory of the same group, then the weakest of the other existing memories in long term will be overwritten.

When a short-term memory is promoted (or possibly fails to promote) to long term memory it leaves an empty slot in the dwarf's short-term memory.

Due to the cycling of the weakest short-term memories, it tends to be the stronger emotions that cause memories to remain in short-term memory for long enough to be promoted.

The effect of the promotion on the dwarf's short-term memory is that it 'purges' a slot, allowing for a relatively weaker emotion to stick around without being overwritten by the cycling.

Long-term memories are important and can be particularly impactful on a dwarf's mood because: 1) if a dwarf is frequently experiencing the same thing, good or bad, the same emotion can easily exist in both short term and long term, effectively doubling its impact 2) long term memories are often revisited long after an experience has ceased to occur 3) long term memories can become clogged with thoughts that can't be promoted further

func (*Memory) Tick

func (m *Memory) Tick()

Tick advances the memory by one day.

type Thought

type Thought byte

Thought represents a type of thought in the range of 0-255 (a single byte).

const (
	ThoughtNone       Thought = 0  // No thought
	ThoughtNewFriend  Thought = 1  // Found a new friend
	ThoughtNewEnemy   Thought = 2  // Found a new enemy
	ThoughtNewPet     Thought = 3  // Found a new pet
	ThoughtLostFriend Thought = 4  // Lost a friend
	ThoughtLostEnemy  Thought = 5  // Lost an enemy
	ThoughtLostPet    Thought = 6  // Lost a pet
	ThoughtNewJob     Thought = 7  // Found a new job
	ThoughtLostJob    Thought = 8  // Lost a job
	ThoughtPromoted   Thought = 9  // Got promoted
	ThoughtDemoted    Thought = 10 // Got demoted
	ThoughtNewBaby    Thought = 11 // Had a new baby
	ThoughtNewSpouse  Thought = 12 // Got married
	ThoughtLostChild  Thought = 13 // Lost a child
	ThoughtLostSpouse Thought = 14 // Lost a spouse
	ThoughtSick       Thought = 15 // Got sick
	ThoughtHealed     Thought = 16 // Got healed
	ThoughtLast       Thought = 16 // Last thought (for random generation)
)

Predefined thoughts. NOTE: It'd be more useful to have this customizable, but for now we'll just use a few predefined thoughts.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL