This repository contains a C++ and web implementation of the Langton's ant universal Turing machine.
The web version can be found here
Both the C++ (Ant.h) and JavaScript (Ant.js) version share the same implementation concept. There's support for 8 possible operations, which are:
- R45/L45
- R90/L90 (or R/L)
- R135/L135
- C (continue)
- U (180 degree turn)
Placeholder
Canvas width/height
Defines a state machine, can later be used when defining a ant with -a
. Can be chained using ;
Example:
-m LRRRRRLLR;RLLLLLRRL
: Creates two state machines with index 0 and 1
Defines ants using the following format P(X,Y)D(DX,DY)M(M)S(S)F(W?)
which can be chained using ;
P
Initial positionD
Initial directionM
Defines which state machine to use, this can be a string (for exampleRL
/R90L90
) or a index when using the-m
argumentS
Defines the step sizeF
Optional section that defines flags (W: Wrap)
Example:
-a P(500,500)D(0,-1)M(RL)
: Creates a single ant with the state machine RL
-a P(500,500)D(0,-1)M(0)S(10)F(W);P(500,500)D(0,1)M(1)
: Creates two ants using state machine 0 and 1, ant 0 wraps and has a step size of 10
Defines how many iterations should be evaluated, by default it will run until all ants run out of bounds or (if wrap is enabled) will run indefinitely. Alternatively t
can be added before the number to make it time based.
Example:
-i i50b
: Run for 50 billion iterations
-i t100s
: Run a maximum of 100 seconds
Defines when a canvas snapshot should be taken. Can be chained using ;
i<interval?>
: Snapshots everyinterval
iterations (if not specified 1 is assumed)f
: Snapshots the final state
Defines how to output images.
f:<format>:<name>
: Write image files.%d
can be used for the image index and%i
for the current iteration.s:<format>:<stdout|stream>:<stream_name?>
: Write images to a pipe/stream.
Supported formats:idx
: Outputs the raw buffer.rgb24
: Outputs the raw buffer as RGB24.png
: Outputs the raw buffer as PNG.
Defines how many threads should be used, for now this argument only changes the amount of threads used when encoding images, eventually multithreading for the ants will also be added.