The worksheetDownload the PDF
Answers

10.5 A team in a game

Competing · Robot club · about 14 min

BugBotLab

What this lesson is about

Radio in a game, agreeing roles without talking, and swapping jobs when the score says so.

Questions 6 marks in all

  1. [1 mark]In a game, who hears your send("striker")?

    1. AEvery robot on the mat, including the other team
    2. BOnly your team mates
    3. COnly robots within 50 cm
    4. DOnly the game's scorer
    Answer: A. Say what your team needs and nothing you would mind an opponent knowing.
  2. [1 mark]What does this program print?

    team = ["bot-7", "bot-2"]
    for me in team:
        job = "attack" if me == min(team) else "defend"
        print(me, job)
    Answer:
    bot-7 defend
    bot-2 attack

    min of a list of names picks the one that sorts first, bot-2. Both robots run the same rule and agree without a word.

  3. [1 mark]What does this program print?

    team = ["bot-10", "bot-9"]
    print(min(team))
    Answer:
    bot-10

    Names sort as text, character by character, and 1 comes before 9. So bot-10 sorts first, which is fine as long as both robots use the same rule.

  4. [1 mark]Why is a rule like the name that sorts first attacks often better than agreeing by radio?

    1. AIt cannot be jammed, cannot arrive late, and works on the first tick
    2. BIt lets you change jobs more often
    3. CThe other team cannot read your name
    4. DRadio does not work in games
    Answer: A. Radio is useful, but a shared rule needs no message at all.
  5. [1 mark]Your attacker has been taken out. What should the defender do?

    1. ABecome the attacker
    2. BKeep defending, since jobs are fixed
    3. CStop and wait for the attacker to return
    4. DSend the score to the other team
    Answer: A. Fixed jobs lose to a team that notices. Swap when it makes sense.
  6. [1 mark]In the task, a robot sends attack and then drives to the near base. What is wrong?

    1. AWhat it said and what it did do not match: attack means the far base
    2. BNothing, the message is what counts
    3. CIt should not send anything
    4. Dattack should be in capitals
    Answer: A. Send attack and go to the far base, or send defend and go to the near one. A team mate relies on both matching.

The task: call it and go

Send a message saying which job you are taking, then do it: drive to the base zone that matches. This time the job is attack: send attack, then drive to the far base, up the mat and to the left. (Defending would mean the near base, down and to the right.)

from bugbot import *
connect()

# say what you are doing, then do it
send("attack")

The hint students can ask for: Send attack, then drive to the far base. The message has to be the single word, and it has to go before you arrive.

A solution

from bugbot import *
connect()
send('attack')
while position()[1] < 38:
    forward(50)
    wait(0.1)
while position()[0] > -22:
    left(50)
    wait(0.1)
stop()

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.