Bot-drivers will be made of two parts : Head and Hand.
The Head is Angelscript. Execution speed is limited to... say 100 lines per second. Because we don't want to lose more than 5 fps with 4 bots racing together. The Head part controls the Hand part. The Hand part can keep the car on the track while the Head part is analysing the next hot spot.
The Hand part is a formula of 40 characters, written in a simple stack-based language (not turing-complete), that is executed when the game demands "cars input". The stack is an array of 40 floats, with a pointer indicating the topmost element. So execution of the formula is very fast. Here is the language :
- {l Code}: {l Select All Code}
$ duplicate
# flush
! pop
\ swap
@ rotate third to top
^ yank
0..9 constant
a..z variables
: assign
? condition
] jump
+ add
- sub
* mul
/ div
% mod
< lesser
> greater
= equal
& and
| or
~ not
A object = my car
B object = beacon
C object = next checkpoint
D object = opponent's car
E distance to object
F direction to object
G horizontal orientation of object
H horizontal direction of object
I altitude of object
J speed of object
K relative speed of object
L vertical speed of object
M max
N min
O abs
P pow
Q decompose into integer and fractionnal
R random
S sign
T time
U undo value
V send value
W RPM
X lateral speed of my car
Y axial speed of my car
Z altitude of my car
Any other character is ignored.
There must be 4 "V" in the formula. When "V" (send value) is executed, the value on top of the stack is assigned to :
- handbrake
- accelerate/brake
- gears
- steering
0 zero means "false", any other value means true.
When "?" is executed, if the top value is zero, the next character is ignored.
When "]" is executed, if the top value is 25 for example, then 25 characters are ignored.
When a variable is executed, its value is pushed on top of the stack.
The Head can also pilot the Hand by modifying the 26 variables "a".."z"