The answersDownload the PDF
Worksheet

10.3 Watching the others

Competing · Robot club · about 14 min

BugBotLab
NameClassDate

What this lesson is about

others() and the camera tags, and giving way early so contact never costs you the game.

Questions 6 marks in all

  1. [1 mark]In the traffic task, a student calls others() to find the moving robots. What happens?

    1. AIt does not work: others() is only there in games, so in a task use the camera
    2. BIt lists both robots with their positions
    3. CIt returns what the camera can see
    4. DIt sends a message asking where they are
  2. [1 mark]What does this program print?

    import math
    bots = [{"name": "red-1", "x": 30, "y": 40}, {"name": "blue-2", "x": -6, "y": 8}, {"name": "blue-3", "x": 20, "y": 0}]
    closest, best = None, 1e9
    for bot in bots:
        d = math.hypot(bot["x"], bot["y"])
        if d < best:
            closest, best = bot["name"], d
    print(closest, best)
  3. [1 mark]You touch another robot that drove into you. Whose fault is it, in most games?

    1. AYours: touching another robot is your fault, whoever moved
    2. BTheirs, because they moved
    3. CNobody's
    4. DWhoever has the lower score
  4. [1 mark]Which habits keep you out of trouble on a busy mat?

    Tick every answer that is true.

    1. ALook before you commit
    2. BGo round with left() or right()
    3. CGive way early
    4. DSpeed up to get past before they arrive
    5. EPush through, since they moved into you
  5. [1 mark]robots() comes back as [['red', 160, 118, 35.0]]. What is 35.0?

    1. AHow far away that robot is, in centimetres
    2. BIts bearing in degrees
    3. CHow big its dome looks, in pixels
    4. DIts id
  6. [1 mark]What does this program print?

    for gap in [40, 25, 12]:
        if gap < 25:
            print(gap, "step aside")
        else:
            print(gap, "carry on")

The task: through the traffic

Two robots are driving back and forth across the mat, 35 cm and 55 cm ahead of you. Get from the start to the green zone without touching either of them, or anything else.

from bugbot import *
connect()

while position()[1] < 80:
    forward(50)
    wait(0.1)

stop()

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/10-3-watching-the-others/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Print the bearing of the nearest robot every time round the loop, and read the log to see when it got close.
  2. Wait for a gap instead of going round: stop while something is within 30 cm, then carry on.
  3. Cross the mat sideways instead, facing forward the whole way.