Skip to main content
🧙‍♂️ Kris Kowal 🐘 🐙 🧛 📌 📬 Book Store

Lobster Quest, Part 1: Langton’s Ents

Langton’s Ents (also on YouTube)

This is the first of three parts from the devlog I kept on Patreon while Josh Corbin and I wrote the first Emoji Quest, in Lobster, from the fall of 2019 to the summer of 2020. “Lobster Quest” is a name in hindsight. We called the game Emoji Quest, and it was renamed Lobster Quest to tell it apart from its heir apparent, Emoji Quest on the web, the one you can play today, in JavaScript. This part is how we found Lobster and the first thing I made with it.

Josh Corbin and I met Wouter van Oortmerssen at Roguelike Celebration 2019. Wouter was demoing a game over lunch. I believe I asked him “How does one make a game” or something equally ridiculous, and his answer was “Well, in my case, you first write a programming language to write games in.” Kindred spirit, to say the least, but it did take us a moment to establish that, yes, we do indeed want to talk about the esoteric details of his pet programming language. Our kind grow accustomed to lulling people to sleep.

The language in question is Lobster. It’s not merely hot to touch, but molten from surface to core. Handle it with æsbestos mittens. That said, Josh was at least immediately intrigued, and we’ve been doing experiments to assess whether it’s a viable foundation for Emoji Quest.

Lobster #

Lobster is delightfully odd. It has a nice combination of opinions to make it fit for purpose.

To highlight how these features compose, here’s an example of how to adjust the 2D render context such that a unit square fills the center of the window, regardless of its aspect ratio:

// center_unit_square projects a unit square coordinate system over
// the center of the window, regardless of its aspect ratio.
def center_unit_square():
    let size = float(gl_window_size())
    let scale = xy_1 * min(size)
    gl_translate((size - scale) / 2)
    gl_scale(scale)

The window size is a struct with X and Y fields. There’s an overload on the float converter that accepts arbitrary vectors, including structs of “buoyant” fields, if you will. The standard library provides some convenient constants for unit vectors like xy_1, (1, 1). The min function similarly will take the minimum of the fields in a vector or homogeneous struct. You also see subtraction is overloaded for vectors. With these primitives, it’s concise to scale down the viewport to fit the unit box, then offset by half of whatever margin is left.

I’ve never tackled GL programming, but Lobster has made it accessible to me.

Digression. When I was in college, I finally got personal instruction in music. I play the euphonium, which is a cousin of the trombone. My teacher was a renowned trombonist and decided it was time for me to learn another instrument. What followed was the most bizarre combination of aptitude and ineptitude. I could play with a beautiful tone, but I stumbled awkwardly with the slide. This is how I feel programming with Lobster. I’m simultaneously incompetent when it comes to graphics programming primitives, but find linear algebra relatively accessible. So, I get to reëxperience some of the joy and frustrations of learning anew.

As I’ve been learning Lobster, I’ve been leaving a trail of breadcrumbs if you choose to follow. I’ve had to be a nuisance in the chat channel, so it seems fair to repay Wouter’s forbearance by contributing examples of how to use Lobster. There are a bunch of great examples in Lobster, most of which show how to “draw the rest of the owl”, so to speak. These illustrate some basic usage:

A window titled Lobster Cube: a black cube in perspective on a gray field, with a lobster drawn in red line art on its top face, in green on its left face and in blue on its right.
The cube example, with Lobster’s own lobster on its faces

Also, thankfully, Josh contributed a Vim plugin for Lobster lexical highlighting!

Emoji in Lobster #

Specifically for evaluating viability for Emoji Quest, I had an important question: How much trouble is it to render emoji in Lobster? Lobster embeds FreeType in its standard library and can render monochrome from most fonts. It also surfaces font metrics, but we would have to contribute something for text flow. We were unable to render color emoji; they degrade to monochrome equivalents. However, we have everything we need to render emoji as images and build our own stencils from the ones we need. We could just as well integrate our emoji rendering into the text flow engine. Immediate mode mixed content flow will be interesting, to say the least, probably surfacing as a sequence of function calls to render each word and image, conditionally advancing or returning the cursor behind the scenes.

Langton’s Ents #

One of Josh’s katas is to implement Langton’s Ant. One of mine is to implement a cellular automaton. Langton’s Ant does not require a full cellular automaton, but based on pri-or exp-eri-ments (Hilbert World and World in a Bottle), I’ve been meaning to implement a multi-agent automaton as a cellular automaton.

The scheme is thus. Create an automaton with intermediate “images”.

  1. Give every mobile entity an opportunity to bid on the cell it would like to move toward, then distribute these bids into the neighborhoods of each cell.
  2. For each neighborhood, find the neighboring agents that have bid to move toward the central cell and choose one winner. This can be random, but for determinism, each cell can have a unique priority. I chose to give each entity a priority and have it follow them around, but that is not necessary nor necessarily desirable. Priority numbers, for example, could climb hills to produce a system for elevation advantage.
  3. Based on the winners for each cell, create a symmetric translation table. The translation table moves the entities that moved from one position to another, but also moves whatever other state was on the target cell to the void they filled. Mass is preserved.

The first emoji we rendered was the Fir Tree from the Emoji Two font, as a PNG. So, the demo at the top of this article illustrates what I very deliberately call “Langton’s Ents”, for the triple pun score.

Wouter accepted this demo into Lobster, with one modification. Per a hint from Bill Westlin, I reframed the automaton in terms of Lobster’s single texture asset and renamed it “Langosta de Langton”, for the alliteration score.

The automaton is written in such a way that it doesn’t care much about the order the cells are laid out. With a different set of points and neighborhoods, they could be in Hilbert or Z-order, but are currently in row-major order. That implies it would work equally well on the surface of a cube, but I leave this as an exercise for the reader for now. Suffice it to say, it’s one working approach to managing movement with many agents, regardless of how they choose to make bids, one that could potentially be run on a compute shader or sharded with deterministic results.

I carried this auction forward to Emoji Quest, the JavaScript game. It still resolves every turn by gathering the intents of every creature and holding an auction for each contested tile.

Next, Langton’s Ents wander a cube.


Lobster Quest:

  1. Langton’s Ents
  2. Stitching a Cube
  3. The Devlog, from Roadmap to Sky Box

First published on Patreon, November 10, 2019.

The ents are the Fir Tree of Emoji Two, after EmojiOne 2, under CC BY 4.0. The lobster on the cube is lobster.jpg, the texture that ships with Lobster.