For Battle Turing players need to be able to write scripts that describe the operation of their turing machines. This is done using a custom language that is compiled using a custom compiler written in Python.
The language implements the basic operations for turing machines with a few additions to help with the ease of coding. The basic operations include
For the last three elements there are special caveats:
Accepting/Rejecting: Because player implemented turing machine take place on a single tape that lasts for more than a single string, this will be localized to a section of the tape that is defined by the code for the turing machine Halting: This is to indicate that the turing machine is finished running for the current battle, there isn't really a reason why this would be used.
In addition to the basic operation for turing machines, the language also implements simple loops, conditionals, labels (kind of), and gotos. Comments are also supported, represented by #
.
The syntax for Battle Turing's custom language is as follows:
To move left and right you can either use <<
>>
or left
and right
. These by default move a single space, but if followed immediately by a number then the machine will shift by that number of cells.
ie:
<<; # Move left 1 cell
left 3; # Move left 3 cells
>> 4; # Move right 4 cells
right; # Move right 1 cell
To write to the tape use the write
command followed by a literal. For example write 'a'
would write the literal a
to the tape at the current position.
To read from the tape you can use one of two special operands ^
or read
. These can only be used in conditional expressions and do not work on their own.
ie:
if(= ^ 'b') ...
if(!= read 'c') ...
while(!= read 'd') ...
There are a few different types of flow control, you can use if/else statements, or looping
Simple if
statement example
if(exp) {
# 0 or more statements
}
Simple if else
statement example
if(exp) {
# 0 or more statements
}
else {
# 0 or more statements
}
There are two types of loops
while
loop:
while(exp) {
# 0 or more statements
}
do-while
loop
do {
# 0 or more statements
} while(exp);
You may have noticed that above for flow control the commands simply use the keyword exp
in place of conditional expressions. This exp
keyword is not actually a command, or keyword, it's short of expression, Battle Turing supports basic expressions for boolean evaluation. It's important to note that expressions in Battle Turing use prefix-notation, which means the syntax is op lhs rhs
where op
is the operator, lhs
is the left argument, and rhs
is the right argument.
=
: equals<
: less than>
: greater than<=
: less than or equals>=
: greater than or equals!=
: not equal&
: logical AND|
: logical ORSimilar to function calls you can implement labels and gotos in Battle Turing's custom language. When a label is called its statement block is executed and then execution returns to the position of the goto
command, this is a bit different than normal labels. You cannot pass parameters or arguments to the labels, this is on purpose.
A label looks something like this:
myLabel: {
# 0 or more statements
}
And then to call that function, you'd use:
goto myLabel;
print_name:
{
write 'A';
right 1;write 'a';
right 1;write 'r';
right 1;write 'o';
right 1;write 'n';
right 1;
}
goto print_name;
right 5;
left 20;
goto print_name;
while(= read '0') { write '1'; right 1; }
halt;
You are not logged in, please log in here to comment
aaron:
hewoo
Posted on:
Nov. 17, 2024, 8:55 p.m.
0 👍 0 👎