Skip to content

Releases: oisee/psil

Z80 Sandbox Evolutionary Upgrade — Phase 1

04 Mar 17:40

Choose a tag to compare

Z80 NPC Sandbox v2: Real Evolutionary Mechanics

Major upgrade to the Z80 sandbox simulation with 9 actions, real sensors, and tournament GA.

What's new

  • 32×24 world with separate tile + occupancy grids
  • 5×5 neighborhood scan — NPCs sense nearest food, NPC, and item (distance + direction)
  • 9 actions: eat, attack, heal, harvest, terraform, share, trade, craft, teach
  • Tournament-3 GA with single-point crossover and 3 mutation types (point/insert/delete)
  • Dead NPC respawn — GA clones+mutates survivors to refill population
  • 128K bank switching — genomes in Bank 0 ($C000), SP at $BFFE in Bank 2
  • Item system — pickup on movement, drop on death, bilateral trade resolution

Stats

  • Binary: 4,669 bytes (was 2,818)
  • Population stabilizes at ~9 NPCs with sustained eating behavior
  • Fitness grows from 146 to 426+ over 256 ticks

Run

mzx --run sandbox.bin@8000 --console-io --frames DI:HALT --max-frames 2000000

Sample output

NPC Sandbox Z80 v2
T=16 A=16 F=146 E=9
T=32 A=16 F=172 E=6
T=48 A=2 F=158 E=6
T=64 A=3 F=184 E=1
...
T=224 A=10 F=394 E=1
T=256 A=4 F=426 E=0

Phase 2 (items/economy) and Phase 3 (WFC biomes) coming next.

v0.3.0 — Evolving Bytecode Brains

27 Feb 23:00

Choose a tag to compare

NPC Sandbox: Evolving Bytecode Brains

A genetic programming sandbox where NPCs with micro-PSIL bytecode genomes live in a 32×32 tile world, sense their environment, make decisions, and evolve. Runs on both Go and Z80.

What's New

  • Go sandbox (pkg/sandbox/) — full simulation with 20 NPCs, tournament selection, instruction-aligned crossover, and 6 mutation operators
  • Z80 sandbox (z80/sandbox.asm) — 2,818 bytes of machine code running 16 NPCs with evolution on a Z80
  • GA engine (pkg/sandbox/ga.go) — point mutation, insert, delete, constant tweak, block swap, block duplicate
  • CLI runner (cmd/sandbox/main.go) — configurable population size, tick count, gas limit, evolution frequency
  • Seed genomes — forager, flee, and random walker programs in testdata/sandbox/
  • Cross-validation — identical Ring1 outputs verified between Go and Z80 VMs
  • VM enhancements — Ring0R/Ring1R/Ring1W/Gas/Yield opcodes in Z80 dispatcher, per-step gas limiting, mute flag

Quick Start

# Go sandbox
go run ./cmd/sandbox --npcs 20 --ticks 5000 --seed 42 --verbose

# Z80 sandbox
sjasmplus z80/sandbox.asm --raw=z80/build/sandbox.bin
mzx --run z80/build/sandbox.bin@8000 --console-io --frames DI:HALT

Prebuilt Binaries

File Size Description
sandbox.bin 2,818 B Z80 NPC sandbox (load at $8000)
vm.bin 1,674 B Z80 micro-PSIL VM with Ring0/Ring1/Gas/Yield (load at $8000)

Test Results

  • 11 Go tests passing (9 unit + 2 cross-validation)
  • 4 Z80 test programs passing (arithmetic, hello, factorial, npc-thought)
  • Z80 sandbox runs: NPC Sandbox Z80 → T=128 A=2 → T=256 A=0 → Done

See docs/npc-sandbox-journey.md for the full story.