Is it real Python? Which parts of Python can I use?
What works
- Statements: assignment (with
+=and the rest),if/elif/else,while,for i in range(…),break,continue,pass,def/returnandglobal. - Operators:
+ - * / // % **, chained comparisons like0 < x < 10,and/or/not,x if c else y, and& | ^ ~ << >>. - Built-ins:
abs,min,max,int,round,len,TrueandFalse. - Lists: fixed-size lists of numbers, made with
[0] * nor a literal like[1, 2, 3]. You can index them (seen[i],seen[-1]), uselen()and loop over them withfor x in seen. A list never grows. - Functions can call each other and themselves. A function can
return lo, hi, and the caller unpacks it:a, b = f(). - Docstrings and type hints are accepted and ignored, so ordinary Python style compiles.
What's left out
Classes of your own, strings (except a log's text and docstrings), dicts, sets, tuples, slices, comprehensions, default and keyword arguments, exceptions, lambda, generators, with, None, print and any module other than bot.
Numbers
There is one number type, fixed point: from −32768 to about 32767.99998, in steps of 1/65536. Python's meanings are kept: 7 / 2 is 3.5, -7 // 2 is -4, -7 % 3 is 2, and round(2.5) is 2. Dividing by zero gives 0 instead of an error. True is 1 and False is 0.
An example
from bot import Chassis, Scanner, Laser, wait
chassis = Chassis(0)
scanner = Scanner(1)
laser = Laser(2)
seen = [0] * 4
def wrap(a: float) -> float:
"""An angle in -180..180."""
while a >= 180:
a -= 360
while a < -180:
a += 360
return a
while True:
for i in range(4):
seen[i] = scanner.ping(i)
if seen[0]:
b = scanner.bearing(0)
chassis.turn = wrap(b - chassis.heading) / 45
if laser.ready:
laser.fire(b)
wait()
If you use something that isn't there
You get a compile error that says so, on the line where it happened. For example, print(1) gives the bot has no screen or files: print() isn't available, and a dict gives dicts and sets aren't part of this Python subset. Use log() to see values while your bot runs.
The full list is in Reference under the editor, in the Language section.