GoalReview scores with + and −, criteria for a game, and how to compare algorithms.
New words
variable · a named place that stores a value that can changecriterion · one result that a program must achieve, which can be tested with yes or noefficient · using the fewest steps or the least timetime cost · the number of seconds that one step takes
Explanation
A game keeps its score in a variable. The program sets a start value and then adds or takes away points with + and −, for example with change score by 3. Before we build a game, we write criteria that can be tested with a clear yes or no. After building, we evaluate it. We check that the code matches the algorithm and run a test for each criterion. A fix needs a retest of all the criteria. Two algorithms can do the same job, but the efficient one uses fewer steps or less time. A repeat block can shorten a program. For a robot, the time is forwards × time + turns × time.
Worked examples
After
Result
Calculation
stars
start
10
question 1
right
10 + 5
15
question 2
wrong
15 − 4
11
question 3
wrong
11 − 4
7
The score starts at 10. A right answer adds 5 and a wrong answer takes away 4. A player answers right, wrong and wrong. Each row starts from the score of the row above.
Criterion
Result
1 The car moves 10 steps when the right arrow key is pressed
yes
2 The car stops when it touches the finish line
no
3 The timer starts at 0
yes
A tester ran a car race game. Two criteria pass and one fails, so the tester looks at the code for the finish line.
A robot takes 1 second for a forward move and 4 seconds for a turn. Route Y (the staircase) has 6 forwards and 4 turns, so it takes 6 + 16 = 22 seconds. Route X goes straight along the bottom and then up: it has 6 forwards and 1 turn, so it takes 6 + 4 = 10 seconds. Route X is more efficient.
Class activity
Score and route game (pairs, paper). Player A reads 5 quiz questions. Player B answers. Use the rule: start at 6, right +2, wrong −1. Write the new score after each question. Then draw a grid of 5 × 4 squares, put a start and a flower on it and find two routes. Work out the time of each route with forward = 1 second and turn = 4 seconds. Which route is more efficient?
Practice
1
The Owl starts with 3 stars. This program has no else part. What does stars hold if the player types 4? What if the player types 3?
With 4 the condition is false and nothing changes, so stars stays 3. With 3 the answer is right, so stars = 3 + 2 = 5.
2
Which of these criteria can be tested with a clear yes or no? (a) The game looks great. (b) The kite gets 1 point for each star it touches. (c) The game is easy. (d) The game says ‘Done’ when the score is 4.
(b) and (d) can be tested. (a) and (c) are opinions.
3
Forward takes 1 second and a turn takes 4 seconds. How long does this route take?
6 forwards and 2 turns: 6 + 8 = 14 seconds.
4
Why does a repeat block make a program more efficient?
It replaces many copies of the same blocks with one block, so the program is shorter and quicker to change.