Past-paper question · 2015 May-June · Paper 22 · Q3(c)(v)

Question 3(c)(v) 2015 · May-June · Paper 22 · 5 marks

Question 3

Part (c)

(v)

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. Ali uses the top-down design approach for his overall program solution.

His design is as follows:

01 GameEnd ← FALSE 02 CurrentPlayer ← 'O' 03 CALL DisplayGrid() 04 05 REPEAT 06 CALL PlayerTakesTurn(CurrentPlayer) 07 CALL DisplayGrid() 08 IF HasPlayerWon() = TRUE 09 THEN 10 GameEnd ← TRUE 11 OUTPUT "Player", CurrentPlayer, "has won" 12 ELSE 13 IF GridFull() = TRUE 14 THEN 15 GameEnd ← TRUE 16 OUTPUT "Draw" 17 ELSE 18 CALL SwapPlayer(CurrentPlayer) 19 ENDIF 20 ENDIF 21 UNTIL GameEnd = TRUE

(v)

Complete the identifier table below.

Variable or Procedure Identifier Data type Description or Function or Array FALSE if game in progress GameEnd Variable BOOLEAN TRUE if there is a winner or the grid is full Grid ARRAY To store the current state of the game

The marker value ('O' or 'X') of the current CurrentPlayer player Current player chooses cell PlayerTakesTurn Program checks if it is valid and stores marker DisplayGrid Outputs the contents of the grid

Checks if the current player has completed a HasPlayerWon row, column or diagonal GridFull Checks if the grid is full

SwapPlayer PROCEDURE Swaps the value of CurrentPlayer

[5]
Reveal official mark-scheme answer Official mark-scheme answer for 3(C)(V)

Official answer for Question 3

Part (c)

(v)

(v)

✓
Variable
✓
or Procedure
✓
Identifier
✓
Data Type
✓
Description
✓
or Function
✓
or Array
✓
FALSE if game in progress
✓
GameEnd
✓
Variable
✓
BOOLEAN
✓
TRUE if there is a winner or the grid is full
✓
CHAR
✓
Grid
✓
ARRAY
✓
character
✓
To store the current state of the game
✓
STRING(1)
✓
CHAR
✓
CurrentPlayer
✓
The marker value (‘O’ or ‘X’)of the current
✓
Variable
✓
character
✓
player
✓
STRING(1)
✓
Current player chooses cell
✓
PlayerTakesTurn
✓
PROCEDURE
✓
(ignore)
✓
Program checks if it is valid and stores
✓
marker
✓
DisplayGrid
✓
PROCEDURE
✓
(ignore)
✓
Outputs the contents of the grid
✓
Checks if the current player has
✓
HasPlayerWon
✓
FUNCTION
✓
BOOLEAN
✓
completed a row, column or diagonal
✓
GridFull
✓
FUNCTION
✓
BOOLEAN
✓
Checks if the grid is full
✓
SwapPlayer
✓
PROCEDURE
✓
(ignore)
✓
Swaps the value of CurrentPlayer
[5]

Mark scheme 9691_s15_ms_22.pdf →

Topic relevance

Why this question appears here

72% assigned-topic match · Data types and structures › Data types and records

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

Keep practising this topic