Question 3(d) 2014 · October-November · Paper 22 · 5 marks
Reveal official mark-scheme answer
Official answer for Question 3
Part (d)
Show text version of question
Question 3
Part (d)
Question 3
A game is played by two players. Player A uses white tokens ( ). Player B uses black tokens ( ).
The players take turns dropping tokens into a vertical grid. The tokens fall straight down and occupy the next available space in the chosen column. The aim of the game is to connect four of one’s own colour tokens. This must be done in a vertical, horizontal or diagonal line.
Here is one example after Player A has had 2 turns and Player B has had 1 turn:
Row 6
Question 5
Question 4
Question 3
Question 2
Question 1
Column 1 2 3 4 5 6 7
Nathan wants to write a program to allow two users to play the game on the computer. The program will display a simplified version of the above grid which is redrawn after every turn.
Part (d)
The program stores in the variable NextPlayer the character 'A' or 'B' to show whose turn it
is next. The chosen column number is validated using the function from part (c)(i).
The program then sets the relevant empty grid cell to the player’s token value.
Complete the pseudocode:
01 REPEAT
02 INPUT ChosenColumnNumber
03 UNTIL ColumnNumberValid( …………………………………………………………………………………………………………)
04 Row ← 1 // start with bottom row and find first empty row
05 WHILE Grid[Row, ChosenColumnNumber] <> ……………………………………………………………………
06 ………………………………………………………………………………………………………………………………………………………………………
07 ENDWHILE
08 IF ……………………………………………………………………………………………………………………………………………………………………
09 THEN
10 Grid[Row, ChosenColumnNumber] ← …………………………………………………………………………
11 ELSE
12 Grid[Row, ChosenColumnNumber] ← …………………………………………………………………………
13 ENDIF
Why this question appears here
82% assigned-topic match · Programming › Constructs
Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.
Permanent source page: Educate A Change · From 9691_w14_qp_22.pdf
