Question 3(e) 2015 · May-June · Paper 22 · 10 marks
Question 3
Part (e)
Question 3
A board game is designed for two players, O and X.
At the beginning, all cells of a 3 x 3 grid are empty.
The players take turns in placing their marker in an empty cell of the grid; player O always starts.
The game ends when one player completes a row, column or diagonal or the grid is full.
Here is one example after three turns:
O
O X
Ali wants to write a program to play the game.
Part (e)
The current player is a winner if they have placed their markers in each cell of a row or a
column or a diagonal. Ali’s solution checks for a winner after every turn.
Complete the pseudocode for the subroutine HasPlayerWon:
.............................................................. HasPlayerWon() ....................................................
DECLARE WinningLine : ...................................................................................................
DECLARE i : .........................................................................................................................
WinningLine ← .....................................................................................................................
// check both diagonals
IF Grid[1,1] = Grid[2,2] AND Grid[1,1] = Grid[3,3]
OR Grid[..............................................] = Grid[..............................................]
AND Grid[..............................................] = Grid[..............................................]
THEN WinningLine ← TRUE
ELSE
i ← 0
........................................................................................................................................
i ← i + 1
// check a row
IF Grid[i,1] = Grid[i,2] AND Grid[i,1] = Grid[i,3]
// check a column
OR (Grid[...........................................] = Grid[...........................................]
AND Grid[.....................................] = Grid[...........................................])
THEN WinningLine ← TRUE
ENDIF
UNTIL WinningLine = TRUE OR ......................................................................... .
.........................................................................
RETURN WinningLine
ENDFUNCTION
Question 11
Reveal official mark-scheme answer

Official answer for Question 3
Part (e)
Part (e)
FUNCTION HasPlayerWon() RETURNS BOOLEAN accept AS or : or just BOOLEAN
Question 1
Question 22
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_s15_qp_22.pdf
