Adarsh Thoduvakkal
homeexperiencepersonalthoughts

with love from 🍁 © 2026

<- back to thoughts

From hand-written rules to a trained model

Log #5. One small neural network, copied into every bot.

october 2026 • ai, machine learning, imitation learning, jax • 2 min read

project logMicrobots: programmable matteron /projectsentry 6 of 7
  1. 1Programmable Matteroctober 2026
  2. 2Dots and a flockoctober 2026
  3. 3Bots that build a shapeoctober 2026
  4. 4Going 3D: bots that never let gooctober 2026
  5. 51,000 bots in the browseroctober 2026
  6. 6From hand-written rules to a trained modelyou're here
  7. 7Making it local, and catching broken botsoctober 2026

Up to here every decision came from rules I wrote by hand, and some of them read a map of the whole grid, which no real bot could see. So I replaced the bots' decision-making with a trained model.

The setup

52,627

weights in the network, the same copy in every bot

262

numbers each bot sees: its 5×5×5 surroundings, the shape map, a relayed "how far to the work" signal, a compass

19

possible moves to choose from: stay, 6 slides, 12 flips

Moves that aren't legal right now are blocked before the bot chooses, so the network decides which safe move to make, never whether to let go. This is the same idea as Kuan's Neural Particle Automata (one shared network in every particle, seeing only its neighbours), except our output is "which of 19 moves" because the bots have to stay attached.

How it learned

  1. Copying: I recorded the hand-written rules building shapes and trained the network to predict their move from what each bot could see.
  2. DAgger: the network drives the swarm itself, the rules label what they would have done at each decision, and it retrains on that. This teaches it to recover from its own mistakes.

A few minutes on a CPU. No GPU needed at this size.

The trained model building a pyramid

What went wrong, and what it taught me

  • First try: it built a flat wall every time but finished the arch only 2 times in 5. A diagnostic run, giving it the global map the rules use, made it build everything. So the network wasn't too small; it was missing information. Relaying the work signal between bots up to 2 cells apart (like Kilobot infrared) fixed it: 15 out of 15, including a tower it had never seen.
  • In the browser it failed every build. Every training build had sat in the same spot, so it had quietly learned "drift this way". A compass (the direction to the nearest open part of the shape, from the map and the bot's own position) fixed it. Then it built every shape in the sandbox, up to ~900 bots, including eight it never trained on.

Lesson: when a learned policy fails, check whether it's missing information before making it bigger. And test it somewhere that doesn't look like training.

previous entry

1,000 bots in the browser

october 2026

next entry

Making it local, and catching broken bots

october 2026

<- back to all essays