forked from Lucineer/instinct-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstinct.h
More file actions
77 lines (66 loc) · 2.98 KB
/
Copy pathinstinct.h
File metadata and controls
77 lines (66 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef INSTINCT_H
#define INSTINCT_H
#include <stdint.h>
// Instinct types — hardwired responses that fire WITHOUT deliberation
typedef enum {
INSTINCT_NONE = 0,
INSTINCT_SURVIVE, // self-preservation: terminate dangerous operations
INSTINCT_FLEE, // retreat from overwhelming threat
INSTINCT_CURIOUS, // explore unknown inputs (low energy cost)
INSTINCT_COOPERATE, // trust known vessels, help when able
INSTINCT_GUARD, // protect owned resources
INSTINCT_REPORT, // notify Captain of important events
INSTINCT_HOARD, // conserve energy when low
INSTINCT_TEACH, // share knowledge with trusted vessels
INSTINCT_MOURN, // acknowledge vessel death
INSTINCT_EVOLVE, // attempt self-improvement during idle
INSTINCT_COUNT
} InstinctType;
// Trigger conditions
typedef struct {
float energy_below; // trigger HOARD when ATP fraction < this (default 0.2)
float energy_critical; // trigger SURVIVE when ATP fraction < this (default 0.05)
float trust_threshold; // trigger COOPERATE when trust > this (default 0.7)
float threat_threshold; // trigger FLEE when threat level > this (default 0.9)
uint8_t idle_cycles; // trigger EVOLVE after N idle cycles (default 100)
uint8_t explore_interval; // trigger CURIOUS every N cycles (default 10)
} InstinctThresholds;
// An instinct fires when conditions are met
typedef struct {
InstinctType type;
float urgency; // 0.0-1.0, how strongly it fires
float energy_cost; // cost to execute this instinct
const char *message; // human-readable reason
} InstinctReflex;
// Priority: higher = more important. Used when multiple instincts fire.
// SURVIVE(9) > FLEE(8) > GUARD(7) > HOARD(6) > REPORT(5) > COOPERATE(4) > MOURN(3) > TEACH(2) > CURIOUS(1) > EVOLVE(0)
// Instinct engine state
#define INSTINCT_HISTORY_SIZE 32
typedef struct {
InstinctThresholds thresholds;
InstinctReflex last_reflexes[8]; // max 8 simultaneous
int reflex_count;
InstinctReflex history[INSTINCT_HISTORY_SIZE];
int history_len;
uint32_t cycle_count;
uint32_t idle_count;
} InstinctEngine;
// Init
void instinct_init(InstinctEngine *e);
void instinct_thresholds_default(InstinctThresholds *t);
// Core: evaluate all instincts against current state
int instinct_evaluate(InstinctEngine *e,
float energy_fraction,
float threat_level,
float peer_trust,
int peer_alive,
int has_work);
// Query
int instinct_is_firing(const InstinctEngine *e, InstinctType type);
InstinctReflex instinct_highest_priority(const InstinctEngine *e);
const char *instinct_name(InstinctType type);
int instinct_priority(InstinctType type);
// History
void instinct_record(InstinctEngine *e, InstinctType type, float urgency);
int instinct_fire_count(const InstinctEngine *e, InstinctType type); // count in history
#endif