← micro:bit: talk and play

Tournament

Take the Radio duel further. A scoreboard kept in a list, rounds that start themselves, and a champion at three wins.

A tennis scoreboard, a chess clock and an esports bracket all do the same jobs: keep both scores, start the next round, and declare a winner.

This lesson goes further than the Radio duel, for two players. You will add three things, one milestone each:

  1. A scoreboard kept in a list: place 0 for you, place 1 for the other player.
  2. A round function, so the winner's micro:bit starts the next round by itself.
  3. A champion: the first to three wins, and both micro:bits reset for a new tournament.
PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

The program as blocks
Show as code
tournament.ts
let scores = [2, 1]
function showScores () {
    basic.showNumber(scores[0])
    basic.showString("-")
    basic.showNumber(scores[1])
}
input.onButtonPressed(Button.AB, function () {
    showScores()
})
scores is [2, 1]. You press A+B. What does the micro:bit show?

RunRun it and compare the result with your prediction.

Run

Press A+B. Then change the numbers in the list and try again.

The program as blocks
Show as code
tournament.ts
let scores = [2, 1]
function showScores () {
    basic.showNumber(scores[0])
    basic.showString("-")
    basic.showNumber(scores[1])
}
input.onButtonPressed(Button.AB, function () {
    showScores()
})
Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.

InvestigateTrace how each line of code connects to what you see.

Investigate

The program as blocks
Show as code
tournament.ts
let scores = [2, 1]
function showScores () {
    basic.showNumber(scores[0])
    basic.showString("-")
    basic.showNumber(scores[1])
}
input.onButtonPressed(Button.AB, function () {
    showScores()
})

Match each block with its job.

Both micro:bits run the same program.

Match each block with what it does to the scoreboard.

get value at 0 from scores
get value at 1 from scores
set value at 0 of scores to (scores[0] + 1)

You lead 2 to 1. What does your partner's scoreboard show?

ModifyChange the code on purpose and check the result.

Milestone 1: keep score

This is the duel with a scoreboard and a showScores function already made. Update scores when you win a round and when you lose one. Check with A+B.

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
Need a hint?

In A (you pressed first): set value at 0 of scores to (get value at 0 + 1).

Another hint

When 2 arrives while racing (you lost): add 1 at place 1 instead.

Add a point at place 0 when you win a round, and at place 1 when you lose one.

This ticks by itself when your blocks do what is asked.

ModifyChange the code on purpose and check the result.

Milestone 2: the next round

Make a function startRound from the blocks inside B. After each round, both players see the scores, and the winner's micro:bit starts the next round.

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
Need a hint?

Make a function startRound and move everything inside B into it. B then calls startRound.

Another hint

After a win: pause, call showScores, then call startRound. After a loss: pause and call showScores.

A startRound function, called from B and after each win, so rounds keep coming.

This ticks by itself when your blocks do what is asked.

MakeBuild something new using what you have learned. Expect a few tries; that is normal.

Milestone 3: champion

Finish the tournament:

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
Need a hint?

After a win: if scores[0] = 3, send 3 and show Champion; else start the next round.

Another hint

When 3 arrives: show Game over. A function newTournament sets scores back to [0, 0]; call it on both sides.

First to three wins the tournament: send 3, both sides show the result, and the scores reset.

This ticks by itself when your blocks do what is asked.

ModifyChange the code on purpose and check the result.

Run a class tournament

With real micro:bits, run a knockout: each pair picks its own group number, winners move on and play each other. Ideas to make it yours: first to five, a sound for the champion, or showing the scores after every round on both sides.

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
For teachers

An optional, harder extension of the Radio duel. Students keep a two-place scoreboard list, move a round into a function so rounds carry on, and end the tournament at three wins. About 60 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

This lesson is optional: it is for students who finished the Radio duel and want a harder challenge. It needs nothing new. The scoreboard is a list of two numbers: place 0 is this micro:bit's player, place 1 is the other player. Because both micro:bits run the same program, each one sees the match from its own side (2 - 1 on one is 1 - 2 on the other). Adding a point uses set value at 0 of scores to (get value at 0 of scores + 1). Milestone 2 moves the round into a function startRound, so the winner's micro:bit can start the next round by itself. Milestone 3 adds message 3 (champion) and a reset.

Running the lesson

  1. Predict: 2 - 1. Ask which place is 'you'.
  2. Investigate: the 'two sides' question is the key idea: same program, different point of view.
  3. Milestone 1: two set value blocks, one in A (win) and one when 2 arrives (loss).
  4. Milestone 2: moving blocks into a function, then calling it twice, is the same move as Milestone 1 of the duel.
  5. Milestone 3: goals only. Ask pairs to agree what message 3 means before building.
  6. Class tournament: real micro:bits make this a great end-of-unit event.

The hard part (on purpose)

Each micro:bit keeps itself at place 0, so the two scoreboards are mirrored. Ask which place a win and a loss each add to.

When students get stuck

Stretch and support

Stretch: Keep a list of round times as well, and show the fastest reaction of the tournament on the champion's micro:bit.

Support: Students who find this heavy can stop after Milestone 1: a working scoreboard is a good result.

Where it leads

This ends micro:bit Foundations. Robotics challenges comes next: each idea in the simulator, then on a real MOVE Motor. Class ideas: a class knockout bracket on the board; a rematch where students change one rule and explain why it is fairer.

What each step is for

Now you can
You reached the endBack to micro:bit: talk and play