- Learnt28 min · a round, a shuffle, a match
- Basic24 min · build the whole match
- Challenge 1–327 min · a leaderboard, your place, the podium
- Extrabonus · ship it
Review — where we got to 5 min
- A swap needs a third box, and three lists in step swap all together.
- A pass floats the biggest card to the top.
- Bubble sort is passes until one goes by with no swaps.
Quick-fire
Your sort does twelve swaps with random row numbers instead of comparing anything. What have you built?
Reveal the answer
A shuffle. Same nine blocks, no comparison, random rows — and it is the first thing today’s game needs.
Today’s Topic 3 min
- A round: one comparison, one point
- A shuffle: the swap with random row numbers
- Cards leaving the deck as they are played
- A leaderboard sorted with Lesson 3-11’s sort, and
item # ofas a place
Learning outcome
By the end of this lesson you will be able to:
- Shuffle a list.
- Run a match of several rounds, taking cards out of the deck as they are played.
- Sort a leaderboard and read a finishing position off it.
Learnt — playing the deck 28 min
1 · A round is one comparison
You have a card. They have a card. Whichever power is bigger wins the round. That is the whole game, and it is an if / else:
set [my power v] to (item (1) of [powers v])
set [their power v] to (item (2) of [powers v])
if <(my power) > (their power)> then
change [my score v] by (1)
say [Mine!] for (1) seconds
else
change [their score v] by (1)
say [Theirs.] for (1) seconds
end
How to use this: Click the green flag and watch three rounds, one comparison each.
2 · A shuffle is a swap with no opinion
Your sort swaps two rows when they are the wrong way round. Take the comparison out, pick the two rows at random, and do it a dozen times:
repeat (12)
set [a v] to (pick random (1) to (length of [names v]))
set [b v] to (pick random (1) to (length of [names v]))
set [hold name v] to (item (a) of [names v])
set [hold power v] to (item (a) of [powers v])
set [hold pic v] to (item (a) of [pics v])
replace item (a) of [names v] with (item (b) of [names v])
replace item (a) of [powers v] with (item (b) of [powers v])
replace item (a) of [pics v] with (item (b) of [pics v])
replace item (b) of [names v] with (hold name)
replace item (b) of [powers v] with (hold power)
replace item (b) of [pics v] with (hold pic)
end
a and b in place of i and i + 1.How to use this: Click the green flag and watch twelve random swaps churn the deck. Press it again for a different order.
3 · Cards leave the deck
Two cards are played each round, so two cards leave — and they leave all three lists, from row 1, twice:
delete (1) of [names v]
delete (1) of [powers v]
delete (1) of [pics v]
delete (1) of [names v]
delete (1) of [powers v]
delete (1) of [pics v]
Basic — the whole match 24 min
Open your deck. Two card sprites this time: yours and theirs.
Step 1 — two slots
- Duplicate your card sprite and call the copy Theirs.
- Put one in each slot on the table.
Step 2 — the shuffle
- Make
aandb. - Build the twelve-swap shuffle under the green flag, after the deck is stocked.
- Run it a few times and watch the list box.
Step 3 — one round
- Make
my power,their power,my scoreandtheir score. - Show your card as row 1 and broadcast so theirs shows row 2.
- Compare the two powers and give the point.
Step 4 — three rounds
- Wrap the round in
repeat (3). - At the bottom of the round, delete rows 1 and 2 from all three lists.
- Show a round counter on the Stage.
Step 5 — a winner
- After the loop, compare the two scores.
- Say who won and by what.
repeat (3)
change [round v] by (1)
switch costume to (item (1) of [pics v])
set [my power v] to (item (1) of [powers v])
set [their power v] to (item (2) of [powers v])
broadcast [their card v]
say (join (item (1) of [names v]) (join [ ] (join (my power) (join [ vs ] (their power))))) for (1.5) seconds
if <(my power) > (their power)> then
change [my score v] by (1)
else
change [their score v] by (1)
end
delete (1) of [names v] // and the same for powers and pics
delete (1) of [names v] // twice over - two cards were played
end
How to use this: Click the green flag and watch a shuffled deck play three rounds. Press it again for a different match.
Round 4 compares nothing with nothing.
A six-card deck is three rounds. Either repeat 3, or use repeat until <(length of [names v]) < (2)>.
Their card is always the same creature.
The Theirs sprite is not reading the list — it needs switch costume to (item (2) of [pics v]) when the broadcast arrives.
The scores do not add up to three.
A draw is falling into the else and giving them the point. Decide what a draw does and say so — <() = ()> deserves its own branch.
The same card is played twice.
Only one card is being deleted per round instead of two, or the deletes are above the comparison.
A leaderboard
Four players, four scores, and the board put in order.
- Two lists in step:
playersandscores. - The bubble sort from Lesson 3-11, pointed at the scores.
- The winner is row 1 when it finishes.
How to use this: Click the green flag and watch the board rearrange itself a swap at a time.
Teacher note
This is last lesson’s sort with two lists instead of three and different names on them. Pupils who rewrite it from scratch have missed the point; pupils who copy it across and change four words have got it.
Where did I come?
Once the board is sorted, a row number means something new.
- Ask for a player’s name.
- Say what place they came, out of how many.
- Somebody who did not play is told so.
How to use this: Click the green flag and watch three lookups, including one for a player who is not on the board.
Teacher reveal — why the sort had to happen first
set [place v] to (item # of (who) in [players v])
On an unsorted board this number is meaningless — it is just where the name happens to sit. It only becomes a place because the list is in order. That sentence is the reason this lesson comes after Lesson 3-11 rather than before it.
The podium
Show the top three, with no searching at all.
- First, second and third, in that order.
- Each with their score.
- No loop that looks for the biggest — you already sorted it.
How to use this: Click the green flag and watch the podium read straight off rows 1, 2 and 3.
Teacher note
Worth drawing out: sorting is expensive, but it is paid once and then a dozen questions become free — top three, last place, who came third, is this in order. That trade is why real programs sort things they do not obviously need sorted.
Ship it
Put the whole arc together into a game somebody else can play, and share it. This is the end of the run — make it something you would show people.
- A title, a shuffled deck, and a match of three rounds.
- Your score added to a leaderboard.
- The board sorted, and your place read off it.
- A play-again key.
How to use this: Click the green flag and watch the whole thing: title, three rounds, the score recorded, the board sorted, the place given.
Teacher reveal — the running order
add [Mia] to [players v]
add (my score) to [scores v]
broadcast [sort the board v] // the bubble sort from Lesson 3-11
set [place v] to (item # of [Mia] in [players v])
say (join [Mia came ] (join (place) (join [ of ] (length of [players v])))) for (3) seconds
Add first, sort second, look up third. Any other order gives a wrong answer, and the wrongness is quiet — a place that looks plausible. Ask the class to predict what happens if you sort before adding.
Summary 5 min
- A round is one comparison; a match is a loop of rounds.
- A shuffle is the swap with random row numbers and no comparison.
- Cards played leave all the lists they are in, from row 1.
- A sorted leaderboard turns
(item # of () in [players v])into a finishing place. - Sorting is paid once and makes many questions free — top three, last, who came third.
- Shuffle
- Putting a list into a random order.
- Round
- One turn of a game, decided by one comparison.
- Leaderboard
- A list of players and scores, kept in order.
- Place
- A row number on a sorted list.
Hand in
Share your finished game and send the link to your teacher. It should shuffle, deal, play a match, record the score and rank the board.
That is twelve lessons and three games. You have written two algorithms with names — linear search and bubble sort — and they are the same two a computer science exam will ask you about in a few years’ time.