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
localizer.read()gives a list of the panels struck since the last clear, by number: for example[17]after a laser shot from behind.- Panel 1 faces the way the bot faces. Numbers go clockwise seen from above, so 9 is the right side, 17 the back and 25 the left. Each panel covers 11.25°.
- A laser strikes the one panel facing where it came from. Turn that way, point your scanner there, and you may find a shooter you hadn't seen.
- Panels stay struck until you call
localizer.clear(), so you never miss a hit between readings. - Reading it costs cycles (up to a few hundred with many panels struck), so read it once a tick and keep the list.
- It goes on the sensor or spare mount; one per bot.
Ideas
- Retreat or hide behind a block when the hull gets low.
- Tell your team you're hurt over the radio, so a teammate can cover you.
- Watch
cpu.tickto know how much of the match is left: a league match lasts 3600 ticks.