thebotslam

Is it real Python? Which parts of Python can I use?

What works

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.