SWARM — Ant Colony Optimization Challenge 200 ants share one program on a 128x128 grid. Find food, bring it to the nest. Communicate only through pheromone trails. Score across 120 maps. Hit play to see the default code run, then improve it. ───────────────────────────────────────────── QUICK START SENSE FOOD r1 ; scan 4 adjacent cells for food MOVE r1 ; walk toward it PICKUP ; grab one unit SENSE NEST r1 ; find the way home MOVE r1 ; walk toward nest DROP ; deliver (scores if at nest) ───────────────────────────────────────────── LANGUAGE Antssembly is like assembly. The program counter persists across ticks — your ant's "brain" is a continuous loop, not restarted each tick. DIRECTIVES .alias dir r1 ; name a register .alias trail r2 .const FOOD CH_RED ; named constant .tag 0 forager ; name a tag (see TAGS) .tag 1 scout .tag names double as constants, so you can write TAG forager instead of TAG 0. LABELS search: SENSE FOOD dir JEQ dir 0 wander MOVE dir PICKUP JMP search wander: MOVE RANDOM ENTRYPOINT If a main: label exists and isn't at the top, a JMP main is auto-prepended. REGISTERS r0-r7, 8 general purpose. Signed 32-bit integers, init to 0. Overflow wraps (32-bit signed). COMMENTS ; everything after semicolon. ───────────────────────────────────────────── SENSING All sensing ops take an optional dest register (defaults to r0 if omitted). SENSE [reg] scan 4 adjacent cells targets: EMPTY=0 WALL=1 FOOD=2 NEST=3 ANT=4 (or register) returns direction (N=1 E=2 S=3 W=4), 0=none ties broken randomly SMELL [reg] strongest pheromone dir ties broken randomly SNIFF [reg] intensity 0-255 dir: HERE N E S W RANDOM (or register) PROBE [reg] cell type at direction returns 0=EMPTY 1=WALL 2=FOOD 3=NEST CARRYING [reg] 1 if holding food ID [reg] ant index (0-199) ───────────────────────────────────────────── ACTIONS — end the ant's tick MOVE N/E/S/W, RANDOM, or register PICKUP pick up 1 food from current cell DROP drop food (scores if at nest) Each ant carries at most 1 food. Multiple ants can share a cell (no collisions). Each tick runs until an action or the 64-op limit. Then the next ant goes. After all 200 ants act, pheromones decay. ───────────────────────────────────────────── PHEROMONES — 4 channels, intensity 0-255 CH_RED CH_BLUE CH_GREEN CH_YELLOW Toggle R/B/G/Y in the viewer to see them. MARK add to pheromone on this cell (additive, capped at 255) Trail pattern: MARK CH_RED 100 ; add to breadcrumb SMELL CH_RED r2 ; follow gradient MOVE r2 ───────────────────────────────────────────── ARITHMETIC SET r1 5 ADD r1 1 SUB r1 1 MOD r1 4 MUL r1 3 DIV r1 2 AND r1 0xFF OR r1 1 XOR r1 r2 LSHIFT r1 4 RSHIFT r1 4 RANDOM r1 4 Second operand can be a register or literal. DIV truncates toward zero. MOD is always non-negative. Both are no-ops if divisor=0. SHR is arithmetic (sign-preserving). RANDOM r1 N sets r1 to a value in [0, N). ───────────────────────────────────────────── CONTROL FLOW JMP