Billiards

Billiards is a 2D programming language inspired by a challenge posted a few years ago by PPCG user PhiNotPi. Its interpreter can be found at https://github.com/alexander-liao/java-public/tree/master/programs/ball-simulator. It is currently under heavy development, so new features are added very often.

The general idea is that a bunch of billiard balls with values move around a ball machine, interacting with the components.

The program is first read entirely from STDIN, and then it is run row by row. Each character represents its own part of the code, and the program is entirely interpreted. Any character after and including the first occurrence of  on a line will be ignored. The textual machine consists of lowercase letters, uppercase letters, and the characters. The virtual machine consists of balls, ramps, logic operators, and outputs.

The interpreter will first begin by interpreting the first row.

A lowercase letter will result in the interpreter taking an input. If the input is not  after being trimmed of whitespace, then a ball is released at that location with an integer value of the input.

An uppercase letter is an output. Every time a ball passes through its space, it will increment its value (by 1). At the end of the execution, all outputs will be printed in order of row first, then column.

The characters  and   are ramps. If a ball falls onto it, it will deflect it one space right/left, and set its direction to. If a ball comes sideways onto it, its direction will be set to  and it will fall down. If a ball levitates up from underneath it, it will be deflected one space left/right and its direction will be set to.

The character  is a logic operator. Whenever a ball passes over its space, it will increase its value by. At the end of one iteration of all balls, if there are no balls on its layer, then if its value is positive and even, it will create a new ball with a non-conflicting ID in the space directly underneath it, and set its value back to. If a ball falls straight down onto it, the ball will be destroyed. If a ball rolls over it in either direction, it will continue. If a ball levitates up through it, it will keep levitating upwards.

The character  sets a ball's direction to   and makes it begin levitating.

The characters  and   "inject" the ball's value into whatever is to its left/right. Essentially, if a ball with value  reaches a control operator with metadata , the operator will do nothing. This allows for condition statements, albeit rather confusing. The ball whose value was used is then destroyed.

and  increment/decrement a ball's value.

prompts for the user's input and sets it as the ball's value; this is equivalent to destroying the ball and creating a new ball at that space with the same name.

outputs the ball's value as.

outputs the ball's value as an integer.

Levitation is started only by the character  and is stopped by a ramp.

,, and   will consume a ball and store its value on the first ball, and then on the second ball, will consume it and apply that operator to both of them. A new ball with this value is released right under it. It will then reset its memory and reset its state.

Balls cannot collide. Execution stops once all balls have left the specified grid.

All strings that are shorter than the longest string will be padded with spaces on the right so that it is a rectangular grid.

All other characters will allow the ball to pass through them; if it is falling, it keeps falling. If it is rolling, it stops rolling and falls straight down (there is not horizontal momentum in this language). If it is levitating, it keeps levitating straight up.

Interpreter Flags
supresses output from capital-letters.

prints all of the balls in the system and requires the user to press  each time before all balls have been iterated.

waits ms milliseconds before all balls are iterated once.

This page is also currently being worked on, so it's a stub right now but I (the creator, Alexander Liao) will be adding more to it soon!