Chess Code

From Esolang
Jump to navigation Jump to search

Overview

Chess Code is a programming language made by the user Boinga15 in August 2022. Chess Code uses chess-like moves to write programs that are similar in capability to Brainfuck. While Chess Code cannot interpret actual games, the syntax used is similar to how chess moves are displayed in games.

Inner Workings

Chess Code uses an 8x8 array for holding information, similar to a chessboard. It also has five separate variables each denoted by a letter, each one correlating to a different major piece:

  • Rook (R)
  • Knight (N)
  • Bishop (B)
  • Queen (Q)
  • King (K)

As for referencing parts of the database, a coordinate on a chessboard is used. For example, to reference the second number in the third line of the database, the identifier c2 is used.

Instructions

Comments are written with a | before it, such as:

| This is a comment.

This prevents the compiler from mistaking a comment for actual code.

To reference parts of a database, use a letter from a to h followed by a number from 1 to 8. Examples include:

c2
f7
a1
h8

This is used to reference and change parts of the database. Commands include:

f5 | Outputs the value stored in the given location of the database. In this case, the value at f5 is printed out.

f2xg7 | Sets the value of the first location to the second location. In this case, the value at f2 will be set to the value at g7.

c6+ | Increments value of the given location by 1. In this case, the value at c6 increases by 1.

c2xh3+ | Increments value of the first location by the second location. In this case, the value at c2 is increased by h3's value.

b6# | Sets value at the given location to whatever the user inputs. In this case, the value at b6 is set to the user's input.

The output mode can also be changed through the use of castling symbols:

O-O | Sets the output mode to ASCII (e.g. 97 is outputted as "a").

O-O-O | Sets the output mode to raw (e.g. 97 is outputted as "97").

Referencing variables can be done by using their key identifiers (R, N, B, Q, and K). The following can be done using variables:

Rc6 | Sets the variable to the value at the given location. In this case, Rook is set to the value at c6.

Bxc6 | Sets the value at the given location to the variable. In this case, the value at c6 is set to Bishop.

Ng4+ | Increases the variable by the value at the given location. In this case, Knight is increased by the value at g4.

Qxf4+ | Increases the value at the given location by the variable. In this case, the value at c6 is increased by Queen.

Kg1# | sets the given variable and given location's value to the user's input. In this case, King and g1 is set to the input.

Looping is done using labels and conditions. When the program runs and encounters a condition, it will return to that condition's label if the condition provided is met. Loops can be nested by using multiple labels and conditions.

1/2 1/2 | Acts as a looping label. This is where the program will go back to if the condition is met.

f1=K | Loops back if given location's value is equal to the given variable. In this case, the value of f1 is compared to King.

g6=R+ | Loops back if the given location's value is not equal to the given variable. In this case, g6 is compared to Rook.

h3xc2=Q | Loops back if the first location's value is equal to the variable and the second location's value. Here, h3 is compared
to Queen and c2.

d2xa5=B+ | Loops back if the first location's value is not equal to the variable and the second location's value. Here, d2 is
compared to Bishop and a5.

Each line of code must be written on a separate line, however blank lines with no code are allowed.

Example

The following code takes two inputs from the user, adds the two numbers together, and then outputs both the raw and ASCII result:

| Inputs
a1#
a2#

| Processing
Ba2
1/2 1/2
a1+
a3+
a3=B+

| Output
a1
O-O
a1

External Resrouces