Slot-Machine

From Esolang
Jump to navigation Jump to search

Slot-Machine is a queue-based esoteric programming language created by User:Zero player rodent. The language was designed so that the code would resemble a slot machine in both form and fashion.

Details

Slot-Machine uses a single unbounded queue and accumulator for program memory. The accumulator and queue hold unbounded positive or negative integers. The queue initially starts in this state: [0]

In Slot-Machine, the commands are stored and executed on three rotating "reels". There are also three "windows" that point to a command on each reel. They are labelled each as reel 1, reel 2, reel 3, and window 1, window 2, and window 3. The IP executes commands in this order:

Execute command in window 1.
Rotate reel 1 upwards once.

Execute command in window 2.
Rotate reel 2 upwards once.

Execute command in window 3.
Rotate reel 3 upwards once.

and repeats until it executes the "terminate" command. Another detail is that each reel has a completely different command set from the others.

Program Structure

Slot-Machine programs have a specific structure that they have to follow. Firstly, the program needs to be padded with | on each side. Secondly, each reel is defined as a vertical array of commands, like this:

| R R R |
| e e e | o
||e|e|e||/
| l l l |
| 1 2 3 |

Notice that the "windows" or starting points of the program, are defined by enclosing the commands with |. The program also needs to have a "handle" consisting of / and o for purely aesthetic reasons.

Commands

Command Reel 1 Reel 2 Reel 3
7 Enqueue 0. Dequeue. Output front of queue.
$ Increment front of queue. Add front of queue to front of queue. Decrement front of queue.
@ Enqueue front of queue. Output front of queue as ASCII character. Terminate program.
> Rewind reel 2 to last ^ pointed to in reel 2. Rewind reel 3 to last ^ pointed to in reel 3.. Rewind reel 1 to last ^ pointed to in reel 1.
? Set accumulator to front of queue. Enqueue value in accumulator. Enqueue random value between 0 and value in accumulator.
* Reverse queue. Enqueue byte of input. If there is no input, enqueue 0. Enqueue front of queue + back of queue.
& Rotate reel 2 upwards once if front of queue is equal to accumulator. Rotate reel 3 upwards once if front of queue is equal to accumulator. Rotate reel 1 upwards once if front of queue is equal to accumulator.
% Rotate reel 2 upwards once if front of queue is not equal to accumulator. Rotate reel 3 upwards once if front of queue is not equal to accumulator. Rotate reel 1 upwards once if front of queue is not equal to accumulator.
= NOOP. NOOP. NOOP.

Computational class

Slot-Machine is Turing-complete because it can simulate minimized Brainpocalypse. To translate a Brainpocalypse program to Slot-Machine, you must first initialize the program, like this:

|       | o
||7|=|=||/
| 7 = = |
| 7 = = |
| ^ ^ ^ |
| > > = |
| $ % = |
| = % = |
| = % = |
| % = $ |
| = = = |

The example above initializes for a version of Brainpocalypse with a bounded tape of 4 cells, but Slot-Machine is capable of simulating a bounded tape of arbitrary size. Then you convert each minimized Brainpocalypse command to its Slot-Machine equivalent.

Brainpocalypse command Slot-Machine equivalent
}
| @ 7 = |
| $ = = |
-
| = % > |
| = = $ |
| $ = = |
| % = = |
| = = % |
| = = $ |
EOF
| = = @ |


Example programs

Truth-machine

| =     |
| =     | o
||$|=|7||/
| = % @ |
| ^ ^ = |
| = > ^ |
| > = 7 |
| = = > |

(Type = into window 1 for input 0, or type $ into window 1 for input 1.

cat

| = & > |
| = & = |
| = = = |
| = = @ | o
||^|^|^||/
| > > = |
| $ % = |
| = % = |
| = % = |
| % = $ |
| = * = |
| = 7 = |
| & @ = |
| = = = |

Slot machine game

| = 7 7 |
| = 7 7 |
| = = @ | o
||$|$|=||/
| $ $ = |
| ? = ? |
| = = ? |
| = = ? |
| = = ? |
| = 7 7 |

(Play until you match 3 numbers!)

External Resources

Interpreter on Try It Online (Crystal)