thebotslam

How does my bot know when it's been hit, and how much health it has left?

Hull points

A bot starts with its chassis's hull: 100 on a CHS-L, 180 on a CHS-M and 320 on a CHS-H; other chassis have their own. The Machine section in Brain code shows your machine's hull. Each laser blast you're caught in takes 10. Other weapons do their own damage: a rocket's burst, for example, takes up to 40 close in, less further out.

Compare the hull with last tick's to catch a hit as it happens:

from bot import Chassis, Localizer, wait

chassis = Chassis(0)
localizer = Localizer(3)

wait()  # start on a fresh tick, with real readings
last = chassis.hull
while True:
    if chassis.hull < last:
        log("hit: hull {}", chassis.hull)
    last = chassis.hull

    hits = localizer.read()
    if len(hits) > 0:
        # Panel 1 faces ahead; they count clockwise, 11.25 degrees each.
        rel = -(hits[0] - 1) * 11.25
        if rel < -180:
            rel += 360
        chassis.turn = rel / 45   # turn toward the shooter
        localizer.clear()
    if chassis.hull <= 30:
        chassis.forward = -1      # badly hurt: retreat
    wait()

The damage localizer

Ideas