How do I find enemies with the scanner?
Search, then lock on
from bot import Chassis, Scanner, wait
chassis = Chassis(0)
scanner = Scanner(1)
sweep = 0
while True:
if scanner.ping(0):
b = scanner.bearing(0)
scanner.sense = b # keep the arc on it
log("contact @ {}", b)
else:
sweep += 30 # nothing: look at the next 30 degrees
if sweep >= 180:
sweep -= 360
scanner.sense = sweep
wait()
Moving the arc 30° a tick covers the whole circle in 12 ticks, a little over half a second.
What the scanner tells you
scanner.sense = degpoints the arc (15° either side) at a field bearing. It stays on that bearing as the chassis turns. It starts at 0, facing east. The new arc's readings come in after the nextwait().scanner.ping(i)is true if sloti(0 to 3) holds a contact. Contacts are sorted by bearing from right to left, so slot 0 is the rightmost.scanner.bearing(i)is that contact's field bearing. Checkping(i)first: an empty slot's bearing means nothing.scanner.anyis true if anything pinged in the arc this tick.
Friend, foe or wall?
A contact is anything solid in line of sight within 30 m: an enemy, a teammate, a block or a wall. Some ways to tell them apart:
- Watch what moves. Obstacles stay put; bots move. The house bot seeker looks twice from different places to fix where a contact is.
- Know where your teammate is. A radio gives your teammate's position (
radio.teammate()), so you can skip a contact in line with it. - Measure the distance. A rangefinder pointed at the same bearing (
rangefinder.bearing = b) givesrangefinder.rangein metres, so you can tell a near bot from a far wall. - Look at its shape.
scanner.profile(i)asks for a contact's silhouettes, front and side. The answer comes in after the nextwait():scanner.profiledis true if it found a bot (a wall gives no profile), andscanner.front_width,scanner.front_heightand the rest describe its shape. A profile doesn't say which team the bot is on.
Tips
- After you point a sensor somewhere new, its reading comes a tick later. Trust what it says once it has been on a target for more than a tick.
- Sweep while you drive, but point the arc ahead of you now and then (
scanner.sense = chassis.heading) so you see what you're driving into. - The scanner also warns of a heat-seeking missile coming at you:
scanner.missileandscanner.missile_bearing.