From 8c86bd2a3ef843107774223ac4d9c1e4961a21de Mon Sep 17 00:00:00 2001 From: epochryphon Date: Fri, 13 Mar 2026 10:02:44 -0500 Subject: [PATCH] base framework made --- Makefile | 72 ++++++++++++++ .../emotional_simulator.c | 96 +++++++++++++++++++ .../emotional_simulator.h | 86 +++++++++++++++++ .../internal/private_emotional_simulator.c | 11 +++ .../internal/private_emotional_simulator.h | 11 +++ .../tests/test_emotional_simulator.c | 0 .../tests/test_emotional_simulator.h | 0 src/main.c | 12 +++ src/main_test.c | 0 9 files changed, 288 insertions(+) create mode 100644 Makefile create mode 100644 src/MODULE_emotional_simulator/emotional_simulator.c create mode 100644 src/MODULE_emotional_simulator/emotional_simulator.h create mode 100644 src/MODULE_emotional_simulator/internal/private_emotional_simulator.c create mode 100644 src/MODULE_emotional_simulator/internal/private_emotional_simulator.h create mode 100644 src/MODULE_emotional_simulator/tests/test_emotional_simulator.c create mode 100644 src/MODULE_emotional_simulator/tests/test_emotional_simulator.h create mode 100644 src/main.c create mode 100644 src/main_test.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cda7ed9 --- /dev/null +++ b/Makefile @@ -0,0 +1,72 @@ +# Makefile for emrys_emotional_simulator +# POSIX-compatible bmake build system + +# Program name +PROG = emrys_emotional_simulator + +# Source files (relative to project root) +SRCS = main.c \ + emotional_simulator/emotional_simulator.c \ + emotional_simulator/internal/private_emotional_simulator.c + +# Header search paths +CFLAGS += -I. +CFLAGS += -Iemotional_simulator +CFLAGS += -Iemotional_simulator/internal + +# Common compiler flags (POSIX-compliant) +CFLAGS += -Wall -Wextra -std=c99 + +# Debug build (optional) +# CFLAGS += -g -DDEBUG + +# Optimization (optional) +# CFLAGS += -O2 + +# Object files +OBJS = ${SRCS:.c=.o} + +# Default target +all: ${PROG} + +# Link the program +${PROG}: ${OBJS} + ${CC} ${LDFLAGS} -o ${PROG} ${OBJS} + +# Compile C source files to object files +%.o: %.c + ${CC} ${CFLAGS} -c $< -o $@ + +# Clean build artifacts +clean: + rm -f ${OBJS} ${PROG} + +# Dist clean (remove all generated files) +distclean: clean + +# Install (optional) +install: ${PROG} + install -d ${DESTDIR}/usr/local/bin + install -m 755 ${PROG} ${DESTDIR}/usr/local/bin/ + +# Uninstall (optional) +uninstall: + rm -f ${DESTDIR}/usr/local/bin/${PROG} + +# Run tests (if tests exist) +test: ${PROG} + @echo "Running tests..." + @# Add test commands here when tests are implemented + +# Show help +help: + @echo "Available targets:" + @echo " all - Build the program (default)" + @echo " clean - Remove object files and binary" + @echo " distclean - Remove all generated files" + @echo " install - Install to DESTDIR" + @echo " uninstall - Remove from DESTDIR" + @echo " test - Run tests" + @echo " help - Show this help" + +.PHONY: all clean distclean install uninstall test help diff --git a/src/MODULE_emotional_simulator/emotional_simulator.c b/src/MODULE_emotional_simulator/emotional_simulator.c new file mode 100644 index 0000000..f9f077f --- /dev/null +++ b/src/MODULE_emotional_simulator/emotional_simulator.c @@ -0,0 +1,96 @@ +#include "emotional_simulator.h" + +#include +#include +#include + +emotional_state_struct* +alloc_emotional_state(struct emotion_vector_struct initial_base_emotion_vector, + float initial_homeostasis_strength, + float initial_context_weight, + float initial_sentiment_bias, + float initial_volatility) +{ + emotional_state_struct* new_emotional_state = calloc(1, + sizeof(emotional_state_struct)); + + new_emotional_state->base_emotion_vector = initial_base_emotion_vector; + new_emotional_state->homeostasis_strength = initial_homeostasis_strength; + new_emotional_state->context_weight = initial_context_weight; + new_emotional_state->sentiment_bias = initial_sentiment_bias; + new_emotional_state->volatility = initial_volatility; + + return new_emotional_state; +} + +emotion_vector_struct* +alloc_random_emotion_vector(void) +{ + srand((unsigned int)time(NULL)); // seed random number based on time. + emotion_vector_struct* new_emotion_vector = calloc(1, + sizeof(emotion_vector_struct)); + + for(int i = 0; i < NUMBER_OF_EMOTIONS; i++) + { + new_emotion_vector->values[i] = (emotion_intensity_type)rand() % 256; + } + + return new_emotion_vector; +} + +void +dump_emotion_vector_values(struct emotion_vector_struct* emotion_vector_to_dump) +{ + const char* emotions_names[NUMBER_OF_EMOTIONS] = + { + "admiration\0", + "adoration\0", + "aesthetic_appreciation\0", + "amusement\0", + "anger\0", + "anxiety\0", + "awe\0", + "awkwardness\0", + "boredom\0", + "calmness\0", + "confusion\0", + "craving\0", + "disgust\0", + "empathetic_pain\0", + "entrancement\0", + "excitement\0", + "fear\0", + "horror\0", + "interest\0", + "joy\0", + "nostalgia\0", + "relief\0", + "romance\0", + "sadness\0", + "satisfaction\0", + "sexual_desire\0", + "surprise\0", + }; + + for(uint8_t i = 0; i < NUMBER_OF_EMOTIONS; i++) + { + puts("================================================="); + printf("| %s: %d\n", + emotions_names[i], + (int)emotion_vector_to_dump->values[i]); + puts("================================================="); + + } +} + +void +free_emotion_vector(struct emotion_vector_struct* emotion_vector_to_free) +{ + free(emotion_vector_to_free); +} + +void +free_emotional_state(struct emotional_state_struct* emotional_state_to_free) +{ + free(emotional_state_to_free); +} diff --git a/src/MODULE_emotional_simulator/emotional_simulator.h b/src/MODULE_emotional_simulator/emotional_simulator.h new file mode 100644 index 0000000..e94cf4e --- /dev/null +++ b/src/MODULE_emotional_simulator/emotional_simulator.h @@ -0,0 +1,86 @@ +#ifndef EMOTIONAL_SIMULATOR_H +#define EMOTIONAL_SIMULATOR_H + +#include +#include + +#define NUMBER_OF_EMOTIONS 28 +typedef uint8_t emotion_intensity_type; + +// Used to index into emotion_vectors. +typedef enum emotions_enum +{ + admiration = 0, + adoration, + aesthetic_appreciation, + amusement, + anger, + anxiety, + awe, + awkwardness, + boredom, + calmness, + confusion, + craving, + disgust, + empathetic_pain, + entrancement, + excitement, + fear, + horror, + interest, + joy, + nostalgia, + relief, + romance, + sadness, + satisfaction, + sexual_desire, + surprise, +} emotions_enum; + +typedef struct emotion_vector_struct +{ + emotion_intensity_type values[NUMBER_OF_EMOTIONS]; +} emotion_vector_struct; + +typedef struct emotional_state_struct +{ + bool burnout_flag; // Active if threshold is passed for long. + uint8_t burnout_threshold_countdown; // Which runs while threshold is passed. + uint8_t burnout_threshold; // Threshold for emotion + + uint8_t volatility; // The rate at which emotions can change per step. + float context_weight; // How much context influences change. + float sentiment_bias; // Global sentiment modifier. + float homeostasis_strength; // Homeosstatis stat between (0.0 to 1.0) + + emotion_vector_struct base_emotion_vector; // The default emotion vector. + emotion_vector_struct current_emotion_vector; // The current emotional state. + emotion_vector_struct* interactor_emotion_vectors; + /* Array of emotional vectors of the interactors in the given context. + * emotional vactors are from the "disposition" one of each tracked for each + * person emrys interacts with. Influenced by interactions over time. + * */ +} emotional_state_struct; + +emotional_state_struct* +alloc_emotional_state(struct emotion_vector_struct initial_base_emotion_vector, + float initial_context_weight, + float initial_sentiment_bias, + float initial_homeostasis, + float initial_volatility); + +emotion_vector_struct* +alloc_random_emotion_vector(void); + +void +dump_emotion_vector_values(struct emotion_vector_struct* emotion_vector_to_dump); + +void +free_emotional_state(struct emotional_state_struct* emotional_state_to_free); + +void +free_emotion_vector(struct emotion_vector_struct* emotion_vector_to_free); + +#endif // EMOTIONAL_SIMULATOR_H diff --git a/src/MODULE_emotional_simulator/internal/private_emotional_simulator.c b/src/MODULE_emotional_simulator/internal/private_emotional_simulator.c new file mode 100644 index 0000000..c58b806 --- /dev/null +++ b/src/MODULE_emotional_simulator/internal/private_emotional_simulator.c @@ -0,0 +1,11 @@ +#include "private_emotional_simulator.h" + +#include +#include + +int +nothing() +{ + printf("nothing"); + return EXIT_SUCCESS; +} diff --git a/src/MODULE_emotional_simulator/internal/private_emotional_simulator.h b/src/MODULE_emotional_simulator/internal/private_emotional_simulator.h new file mode 100644 index 0000000..0a31eed --- /dev/null +++ b/src/MODULE_emotional_simulator/internal/private_emotional_simulator.h @@ -0,0 +1,11 @@ +#ifndef PRIVATE_EMOTIONAL_SIMULATOR_H +#define PRIVATE_EMOTIONAL_SIMULATOR_H + +struct placeholder +{ +}; + +int +nothing(void); + +#endif // PRIVATE_EMOTIONAL_SIMULATOR_H diff --git a/src/MODULE_emotional_simulator/tests/test_emotional_simulator.c b/src/MODULE_emotional_simulator/tests/test_emotional_simulator.c new file mode 100644 index 0000000..e69de29 diff --git a/src/MODULE_emotional_simulator/tests/test_emotional_simulator.h b/src/MODULE_emotional_simulator/tests/test_emotional_simulator.h new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..b6ccf7b --- /dev/null +++ b/src/main.c @@ -0,0 +1,12 @@ + +#include "emotional_simulator/emotional_simulator.h" + +#include + +int main(void) +{ + emotion_vector_struct *emotion_vector = alloc_random_emotion_vector(); + dump_emotion_vector_values(emotion_vector); + free_emotion_vector(emotion_vector); + return EXIT_SUCCESS; +} diff --git a/src/main_test.c b/src/main_test.c new file mode 100644 index 0000000..e69de29