Skip to content

Add player mailboxes to BASIC games - #73

Merged
treeform merged 6 commits into
mainfrom
polyworld-mailboxes
Sep 24, 2026
Merged

treeform merged 6 commits into
mainfrom
polyworld-mailboxes

Conversation

@treeform

@treeform treeform commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds one bounded inbox per player in Gods of the Arena, Call to Adventure, and Light vs Dark. Each inbox has an array of 100 numeric IDs and an array of reserved strings, with a 1024-byte message limit. Full inboxes ignore new deliveries and retain unread messages.

Each game's bots.nim defines its own BASIC callbacks and routing loop:

  • GotA supports global (-2), team (-1), and direct messages (player IDs).
  • LvD supports global and direct messages, rejecting team chat.
  • CtA supports only global chat, delivered within 16 tiles on the sender's level. It uses the game's existing Chebyshev tile distance, including the boundary at 16.

pullMailbox$() consumes the oldest message; mailboxId() reports the channel or DM sender. Games can change their own routing directly. Unsupported destinations return zero without delivering messages.

The shared mailboxes.nim is a 38-line queue with no BASIC dependency. Bassy handles string storage and reclamation through its public API. The dependency locks pin the change in treeform/bassy#4.

This is the first Polyworld PR in the split; #74 builds the LLM integration on top.

Validation:

  • nim check tests/tests.nim and the complete test suite pass with the pinned Bassy dependency.
  • Routing, rejected channels, empty inboxes, capacity, partial broadcasts, wraparound, and repeated BASIC reads are covered across all three games. CtA tests cover the 16-tile boundary, diagonals, different levels, and movement after delivery.
  • Allocation counters verify zero allocations/frees for 1,000 inbox fill/drain cycles and 1,000 GotA BASIC decisions through the mailbox callbacks and VM restart.
  • All three native Coworld builds and hosted runtime/mailbox integration tests pass.

@treeform
treeform merged commit a2b4e12 into main Sep 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant