Stoned-Go

From Esolang
Jump to navigation Jump to search

Stoned-Go is a esoteric program language involving Go stones on a infinite grid, which is initially empty. In addition to the grid is also a direction flag, which is either horizontal or vertical (initially horizontal). Each stone, in addition to white or black, also has a trigger program associated with it, which is executed when the stone is captured. If multiple stones are captured simultaneously, they are triggered in order left to right starting at the top line, and then next line left to right, etc.

Rules for repeating positions in Go do not apply here; only rules for capturing Go stones are applicable.

The program consists of two lists of commands with | in between; the first part is initialization part and second is looping part. Comments are allowed; they start with # and last until end of the line. White spaces are also allows except middle of numbers.

The valid commands are:

  • Put - or + followed by a number to move the cursor that many spaces in the current direction, and then flip the direction flag. (Equivalently, all stones are moved instead of moving the cursor; the result is the same either way)
  • Put / to flip the direction flag without moving the cursor.
  • Put [] with zero or more commands in between to place a black stone with the specified trigger program. Does nothing if there is already a stone there.
  • Put () with zero or more commands in between to place a white stone with the specified trigger program. Does nothing if there is already a stone there.
  • Put ? to halt the entire program if there is a stone here.

Adding a stone may capture others stones and if so, their trigger programs are executed before continuing; however, all captured stones are removed before any trigger programs are executed due to the captures, and are remembered even if new stones are placed in the same position by the trigger programs.

Macros:

  • Write {name:tokens} to define a macro, with "name" replaced by the name of macro (anything except spaces and #<>{}: is allowed), and "tokens" with the tokens of the macros. You cannot define a macro inside of another macro, but you can call other macros inside of another macro, as long as the call is not recursive.
  • Write ! in a macro definition to put the argument of the macro in its place (it can be used any number of times).
  • Write <name:argument> or <name> to call a macro. If the argument is omitted then an empty argument is used.

Variants

Inner loop variant: This variant permits | inside of a [] or () block. In that case, that block is itself a program (with the initial configuration of stones when the program is entered and when it terminates will leave the stones for the caller), and if it contains | then ? terminates the subprogram it appears in; if the subprogram has already ended then it is an error. ("Subprogram" only means a block containing a loop, although it is acceptable for the loop to be empty or simply unconditionally terminate.)