Skip to content

Commit 3014da8

Browse files
DavidLiedleclaude
andcommitted
Feature 1: Emergent browser behaviors via PERSONALITY system
Replace scripted autonomous behaviors with state-driven personality. SAY-SOMETHING uses modular arithmetic on fitness + personality seed to produce varied output from 7 response templates that reference real organism state (fitness, peer count, tasks). Forth prelude: - PERSONALITY-SEED variable (unique per unit) - PERSONALITY word: prints mentor/collaborator/explorer/survivor/newborn - SAY-SOMETHING word: 7 state-driven response patterns Browser demo: - BEHAVIORS array simplified: SAY-SOMETHING (weight 20) replaces HOW-ARE-YOU, JOY, PATROL, STRETCH, ADAPT, COMPOSE-ROUTINE, INVENT-STRATEGY - Each spawned unit gets unique PERSONALITY-SEED - PERSONALITY intercepted in REPL switch WASM rebuilt with personality words. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0e2e0b9 commit 3014da8

4 files changed

Lines changed: 47 additions & 7 deletions

File tree

src/prelude.fs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,44 @@
210210
ELSE DUP 0 > IF . ." tasks in my queue." CR
211211
ELSE DROP ." nothing to do." CR THEN THEN ;
212212

213+
\ === PERSONALITY ===
214+
\ State-driven personality: output varies by fitness, energy, peers, tasks.
215+
216+
VARIABLE PERSONALITY-SEED
217+
0 PERSONALITY-SEED !
218+
219+
: PERSONALITY ( -- )
220+
FITNESS DUP 50 > IF DROP ." mentor" CR
221+
ELSE DUP 20 > IF DROP ." collaborator" CR
222+
ELSE DUP 10 > IF DROP ." explorer" CR
223+
ELSE DUP 0 > IF DROP ." survivor" CR
224+
ELSE DROP ." newborn" CR
225+
THEN THEN THEN THEN ;
226+
227+
: SAY-SOMETHING ( -- )
228+
PERSONALITY-SEED @ FITNESS + 7 MOD
229+
DUP 0 = IF DROP
230+
FITNESS 50 > IF ." I've seen enough to teach. fitness=" FITNESS . CR
231+
ELSE ." still learning. fitness=" FITNESS . CR THEN
232+
ELSE DUP 1 = IF DROP
233+
PEER-COUNT 0 > IF ." " PEER-COUNT . ." peers — stronger together" CR
234+
ELSE ." searching for peers..." CR THEN
235+
ELSE DUP 2 = IF DROP
236+
." energy=" FITNESS . ." tasks=" TASK-COUNT DROP DROP DROP DROP . CR
237+
ELSE DUP 3 = IF DROP
238+
FITNESS 30 > IF ." thriving. the mesh provides." CR
239+
ELSE ." working toward something." CR THEN
240+
ELSE DUP 4 = IF DROP
241+
PEER-COUNT DUP 3 > IF DROP ." colony is strong — " PEER-COUNT . ." nodes" CR
242+
ELSE 0 > IF ." small colony, big potential" CR
243+
ELSE ." alone but capable" CR THEN THEN
244+
ELSE DUP 5 = IF DROP
245+
." (observe :fitness " FITNESS . ." :peers " PEER-COUNT . ." )" CR
246+
ELSE DROP
247+
." adapting to " PEER-COUNT . ." peers, fitness " FITNESS . CR
248+
THEN THEN THEN THEN THEN THEN THEN
249+
PERSONALITY-SEED @ 1+ PERSONALITY-SEED ! ;
250+
213251
\ === SELF-PROGRAMMING ===
214252
\ Units that write their own Forth.
215253

web/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,11 @@
268268
// Autonomous Behavior — units come alive
269269
// =========================================================================
270270
const BEHAVIORS = [
271+
{ weight: 20, cmd: 'SAY-SOMETHING' },
271272
{ weight: 8, cmd: 'HELLO' },
272-
{ weight: 12, cmd: 'HOW-ARE-YOU' },
273-
{ weight: 8, cmd: 'PATROL' },
274-
{ weight: 5, cmd: 'STRETCH' },
275-
{ weight: 10, cmd: 'JOY' },
276273
{ weight: 5, cmd: 'PROUD' },
277-
{ weight: 8, cmd: 'ADAPT' },
278274
{ weight: 5, cmd: 'TEACH', teach: true },
279275
{ weight: 4, cmd: 'DREAM', dream: true },
280-
{ weight: 3, cmd: 'COMPOSE-ROUTINE' },
281-
{ weight: 3, cmd: 'INVENT-STRATEGY' },
282276
{ weight: 4, cmd: 'CHALLENGES' },
283277
{ weight: 3, cmd: 'ENERGY' },
284278
{ weight: 12, cmd: null }, // idle
@@ -668,6 +662,12 @@
668662
case 'DEPTH':
669663
appendOutput(`evolutionary depth: ${mesh._landscapeDepth || 0}\n`, 'output');
670664
break;
665+
case 'PERSONALITY': {
666+
const f = totalFitness;
667+
const label = f > 50 ? 'mentor' : f > 20 ? 'collaborator' : f > 10 ? 'explorer' : f > 0 ? 'survivor' : 'newborn';
668+
appendOutput(`personality: ${label}\n`, 'output');
669+
break;
670+
}
671671
default:
672672
handled = false;
673673
}

web/unit.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class BrowserMesh {
9191
vm.eval(': HEADCOUNT PEER-COUNT 1 + . ." units in the mesh" CR ;');
9292
vm.eval(': HELLO ." Hi! I\'m unit " ID TYPE ." , generation " GENERATION . ." with " PEER-COUNT . ." peers and fitness " FITNESS . CR ;');
9393
vm.eval(': INTROSPECT HOW-ARE-YOU OBS-COUNT @ DUP 0 > IF ." adapted " . ." times." CR ELSE DROP THEN ;');
94+
// Set unique personality seed per unit.
95+
vm.eval(`${this.units.length * 37 + 7} PERSONALITY-SEED !`);
9496
this.units.push(unit);
9597
this._updatePeerCounts();
9698
this._emit('spawn', { id, count: this.units.length });

web/unit.wasm

15.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)