ラングトンのアリ

Langton’s Ant — 単純なルールから生まれる複雑さ

使い方 / Getting started

アリは白紙の原点から上向きに出発します。「1歩」で変化を追い、速度を上げて長い時間の挙動を観察してください。「高速道路へ」は基本ルールの白紙から12,000歩を実際に計算し、全体が見える状態で停止します。

Start with a blank grid and an ant facing up. Use “1 step” to inspect each move, or increase the speed. “Jump to highway” runs the classic rule for 12,000 steps from a fresh blank grid, fits the pattern, and pauses.

基本ルール / The classic rule

  1. 現在のセルが白なら右へ90°、黒なら左へ90°回転。
  2. 現在のセルを白から黒、または黒から白に反転。
  3. 新しい向きへ1セル進む。

Turn 90° right on white or left on black, flip the current cell, then move one cell forward. These deterministic rules alone generate the entire trajectory.

見やすさのため、白(状態0)は暗い背景、黒(状態1)はミント色で表示しています。ピンクの三角はアリの位置と向きです。 / For contrast, white cells appear dark and black cells appear mint. The pink triangle marks the ant and its heading.

高速道路 / The highway

白紙から始めた基本ルールでは、入り組んだ軌跡を作った後に、斜め方向へ伸びる規則的な道が現れます。この段階では104歩ごとに同じ動作を繰り返し、位置が斜めに2セルずつ移動します。道そのものを描く命令はありません。アリが書き換えた環境が、その後の動きを決めています。

From a blank grid, the classic ant eventually builds a diagonal highway. A 104-step sequence repeats, translating the ant by two cells along each axis. The highway is an emergent result of the ant interacting with the cells it has changed.

盤面を編集した場合や多色ルールでは、同じ道ができるとは限りません。

多色への拡張 / Multicolor rules

文字列の各文字が、対応する色での回転方向を表します。例えば LLRR は状態0・1で左、状態2・3で右。回転後にセルの色を1つ進め、最後の色からは状態0に戻ります。2〜12色を試せます。

direction ← direction + turn[color]
color ← (color + 1) mod number_of_colors
position ← position + forward(direction)

Each R or L specifies the turn for one color. After turning, advance the color cyclically and move forward. Try the presets or enter your own sequence of 2–12 R/L characters.

この実装について / Implementation

端を反対側につなぐ方式ではなく、必要なセルだけを保存して平面を広げます。表示範囲の外でも同じルールで計算を続けます。長時間の実行で端末が重くなりすぎないよう、状態0以外のセルが25万を超えると一時停止します。端末の性能によって実際の速度は設定値を下回る場合があります。

The grid grows as needed without wrapping at the screen edges. The simulation pauses after exceeding 250,000 nonzero cells. Actual speed depends on your device.

参考資料 / References

hamzALIFE · Privacy