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:
A scoreboard kept in a list: place 0 for you, place 1 for the other player.
A round function, so the winner's micro:bit starts the next round by itself.
A champion: the first to three wins, and both micro:bits reset for a new tournament.
Predict: Read the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Run: Run it and compare the result with your prediction.
Investigate: Trace how each line of code connects to what you see.
Modify: Change the code on purpose and check the result.
Make: Build something new using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
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
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()
})
RunRun it and compare the result with your prediction.
Run
Press A+B. Then change the numbers in the list and try again.
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
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)
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:
The first player to 3 wins: their micro:bit sends 3 and shows Champion.
When 3 arrives, show Game over.
Both scoreboards reset for the next 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.
I can keep a scoreboard in a list and update the right place.
I can move a sequence into a function and call it from two places.
I can end a game with a target, a message and a reset.
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
Predict: 2 - 1. Ask which place is 'you'.
Investigate: the 'two sides' question is the key idea: same program, different point of view.
Milestone 1: two set value blocks, one in A (win) and one when 2 arrives (loss).
Milestone 2: moving blocks into a function, then calling it twice, is the same move as Milestone 1 of the duel.
Milestone 3: goals only. Ask pairs to agree what message 3 means before building.
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
Both scoreboards count the same player's wins. Ask: Which place does a loss add to? Fix: A win adds at place 0; a loss (2 arrives) adds at place 1.
Rounds stop after the first one. Ask: Where is startRound called after a win? Fix: Call startRound at the end of the winning branch in A.
The scores do not reset after a champion. Ask: Do both sides reset? Fix: Set scores to [0, 0] on the champion's side and when 3 arrives.
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
Investigate: Both micro:bits run the same program, so each keeps its own player at place 0: the two scoreboards show the same match from opposite sides.
Milestone 1: keep score: Each event updates the right place in the list: a win adds to place 0, a loss to place 1.
Milestone 2: the next round: Moving a sequence into a function lets a second event reuse it, so the game can carry on without a button press.
Milestone 3: champion: Ending a tournament joins every idea: a list item compared with a target, a new message in the code, and a function that resets the state.
Now you can
Keep a scoreboard in a list and update the right place.
Move a sequence into a function and call it from two places.