CAMBRIDGE IGCSE COMPUTER SCIENCE
Summer 2024 · Paper 22 · Question 11 · 15 marks
← 0478 CS Hub Paper 22 · Summer 2024 0478 / Paper 2 Question 11 15 MARKS
15-mark question lab · start here

A ten-move hunt for the secret cell in a 5 × 5 grid.

Build the solution in a sensible order: empty the grid and hide the X in a random cell that is never Grid[1,1], place the player at the top left with 10 moves, validate every one-cell move against the edge of the grid, then test for the win before the loss. Learn the reasoning before revealing the complete program.

2D array gameRandom placementBounds validationGame loop with two exitsState tracking15 marks

Learning targets

By the end, you should be able to explain the algorithm before writing it.

Lesson overview

01 · Understand

Identify the one-off set-up jobs, the repeating turn, and the two conditions that can end the game.

02 · Construct

Hide the X with INT(RANDOM() * 5) + 1, then validate each direction against the edge of the grid before applying the move.

03 · Complete

Test the secret cell before the move counter so the tenth move can still win, and message the player at every input and output.

!

How Cambridge awards the marks: the mark scheme gives AO2 a maximum of 9 marks and AO3 a maximum of 6 marks. It lists requirements R1–R5, but does not assign a separate fixed mark total to each R requirement. The stage-to-mark links in this guide show alignment, not invented stage marks.

Source question

Read the whole question first

Do not begin coding after the first paragraph. The start diagram, the 10-move limit and the rule that every move must stay within the grid all shape the loop you are about to write.

Question 11 · 15 marks
Cambridge IGCSE Computer Science · 0478/22 · Question 11

A one-player game uses the two-dimensional (2D) array Grid[] to store the location of a secret cell to be found by the player in 10 moves. Each row and column has 5 cells.

Start Grid[1,1]

Start
Grid[1,1]

At the start of the game:

  • The program places an ‘X’ in a random cell (not in Grid[1,1]) and empties all the other cells in the grid.
  • The player starts at the top left of the grid.
  • The player has 10 moves.

During the game:

  • The player can move left, right, up or down by one cell and the move must be within the grid.
  • “You Win” is displayed if the player moves to the cell with ‘X’ and has played 10 moves or less.
  • “You Lose” is displayed if the player has made 10 moves without finding the ‘X’.

Write a program that meets these requirements.

You must use pseudocode or program code and add comments to explain how your code works.

You do not need to declare any arrays or variables; you may assume that this has already been done.

All inputs and outputs must contain suitable messages.

Before you move on

These are the five required techniques identified by the Cambridge mark scheme.

Mark-scheme map
R1

Empty all 25 cells, then place the secret X in a random cell drawn with INT(RANDOM() * 5) + 1 that is never Grid[1,1].

R2

Start the player at the top left cell Grid[1,1] with a move budget of 10, counted by MovesUsed.

R3

Accept left, right, up and down as one-cell moves and validate each against rows and columns 1 to 5 before applying it.

R4

Display “You Win” the moment the player steps onto the X, provided no more than 10 moves have been played.

R5

Display “You Lose” after the tenth accepted move completes without the X being found.

Use the tabs along the top to work through the seven stages. The complete solution is kept in its own tab, and the interactive visualisation is the final tab.