= """
FOOD_MAP . = Empty
# = Wall
f = Cake(per_serving=2)
!a
..f..
.###..
f.....
......
...f.#
"""
= wd.AsciiGrids.from_string(FOOD_MAP)
grids = wd.WormGrid.from_grid(wd.Topology.Sheet, grids["a"])
wg
= wd.WormTray(wg, reg=5, food_names=["Cake"], trail_lasts=1)
wt = wd.WormDraw(
w
wd.DrawSettings(=42,
cell_size=12,
frame_radius=5,
cell_gap=15,
frame_padding
),
)= w.random_strip(wt, count=5)
image =200) Image(image.to_bytes(), width
Roomba Code
From Vacuum Cleaners to Virtual Creatures
Watch a robotic vacuum cleaner navigate your living room, and you’ll witness a peculiar dance of artificial intelligence. The device bumps into walls, pivots at seemingly random angles, yet somehow manages to cover every inch of floor space. This behavior—neither purely random nor rigidly programmed—emerges from simple rules responding to local information. What makes these patterns so captivating is their resemblance to the foraging strategies of organisms far more ancient than any robot: bacteria following chemical gradients, ants exploring territory, or slime molds extending their networks in search of food.
In previous sections, we explored how AND programs can evolve to respond to streams of input—a capability that opens fascinating possibilities for behavioral modeling. Researchers have long pursued the evolution of specific network architectures, attempting to coax particular structural patterns from the underlying computational substrate. While such architectural evolution is certainly achievable within the AND framework (and merits future exploration), our focus here turns to something more immediate and tangible: deploying these programs as the evolvable “brains” that control autonomous agents navigating their environment.
This shift from abstract computation to embodied behavior mirrors a fundamental transition in both robotics and biology—from processing information in isolation to acting purposefully in the world.
Embedding AND in an Agent
To understand how computational programs become behavioral agents, consider the classical tripartite division of intelligent action:
- Perception: gathering information from the environment through sensors
- Cognition: processing sensory data to make decisions
- Motor control: translating decisions into physical actions
This division is, of course, an idealization—in biological systems, these processes interweave in complex feedback loops where action shapes perception and perception constrains action. Yet as modelers, we embrace such simplifications not as endpoints but as starting points. This framework provides the scaffolding upon which we can build agents that, despite their simplicity, exhibit surprisingly rich behaviors when released into their computational worlds.
Picture here. Perception. Cognition. Motor.
Creating an evolvable agent requires three fundamental design decisions that shape its potential for adaptive behavior:

- The World: We construct a simple two-dimensional grid environment—a computational petri dish where our agents can explore, encounter obstacles, and discover resources.
- The Senses: Local information from the agent’s immediate surroundings feeds directly into its AND program, creating a tight coupling between environment and computation.
- The Actions: The program’s output determines the agent’s next move, transforming abstract computation into concrete behavior—turning left or right, moving forward, or pausing to “consider” its options.
A Simple Foraging World
Let’s bring these abstract concepts to life. Below, we define a miniature world using a simple ASCII map—a technique that lets us rapidly prototype environments while maintaining complete control over their structure. The hash marks (#) represent walls, impenetrable barriers that our agent must navigate around. The letter ‘f’ marks food sources—in this whimsical implementation, slices of cake that provide energy when consumed. Empty spaces (.) offer free passage, creating corridors and open areas where movement strategies can unfold.
The visualization above shows snapshots of our agent exploring this miniature world. Notice how the agent (represented as a directed arrow) leaves a fading trail behind it—a visual history of its path that reveals the emergent patterns of its movement strategy. The agent’s behavior, driven by its AND program brain, must balance exploration with exploitation: thoroughly searching the space while efficiently harvesting the resources it discovers.