Skip to main content
O-LevelComputer ScienceProgramming2210/22 · May/June 2024 · Q1115 Marks

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. [Figure showing a 5x5 grid with 'Start Grid[1,1]' label] 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.

  1. 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.[15]

This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.

Mark scheme

Marking points from the official mark scheme (May/June 2024). The mark or mark type is shown in brackets.

  1. Data Structures required with names as given in the scenario: Arrays or lists Grid
  2. Requirements (techniques)
  3. R1 Set up game – generate random cell, clear all other cells in array, set player start position and start player moves counter (iteration, use of arrays and library routines (round and random))
  4. R2 Input and check move is it valid? (input, output, iteration and selection)
  5. R3 Decide outcome – has move found the X? If so, give appropriate output. If not increment counter and continue. If 10 moves exceeded, give appropriate output (use of arrays, iteration, selection and output).
  6. Example 15-mark answer in pseudocode
  7. // Set up game
  8. FOR Row ← 1 TO 5
  9. FOR Column ← 1 TO 5
  10. Grid[Row, Column] ← ''// set grid cells to be empty
  11. NEXT Column
  12. NEXT Row
  13. REPEAT // not in cell 1,1
  14. XRow ← ROUND ((RANDOM() * 4) + 1,0) // Random row position between 1 and 5 in GRID
  15. XColumn ← ROUND ((RANDOM() * 4) + 1,0) // Random column position between 1 and 5 in GRID
  16. UNTIL XRow <> 1 and XColumn <> 1 // not in cell 1,1
  17. Grid [XRow, XColumn] ← 'X'
  18. MaxMove ← 10
  19. NumberMoves ← 0
  20. PlayerRow ← 1
  21. PlayerColumn ← 1
  22. Win ← FALSE
  23. // during game
  24. WHILE NumberMoves < MaxMove AND NOT Win
  25. MoveError ← FALSE
  26. OUTPUT "Please enter your move, L - Left, R - Right, U - Up or D - Down"
  27. INPUT UPPER(PlayerMove)
  28. REPEAT
  29. CASE OF PlayerMove
  30. 'L' : TempColumn ← PlayerColumn - 1
  31. 'R' : TempColumn ← PlayerColumn + 1
  32. 'U' : TempRow ← PlayerRow - 1
  33. 'D' : TempRow ← PlayerRow + 1
  34. OTHERWISE MoveError ← TRUE
  35. ENDCASE
  36. // check for out-of-range moves
  37. IF TempColumn < 1 or TempColumn > 5
  38. THEN
  39. MoveError ← TRUE
  40. ELSE
  41. PlayerColumn ← TempColumn
  42. ENDIF
  43. IF TempRow < 1 or TempRow > 5
  44. THEN
  45. MoveError ← TRUE
  46. ELSE
  47. PlayerRow ← TempRow
  48. ENDIF
  49. // check win if X Found
  50. IF Grid [PlayerRow, PlayerColumn] = 'X'
  51. THEN
  52. OUTPUT "You Win"
  53. Win ← TRUE
  54. ELSE
  55. IF NOT MoveError
  56. THEN
  57. NumberMoves ← NumberMoves + 1
  58. ENDIF
  59. ENDIF
  60. UNTIL NOT MoveError
  61. ENDWHILE
  62. IF NOT Win
  63. THEN
  64. OUTPUT "You Lose"
  65. ENDIF

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Programming, O-Level Computer Science (syllabus 2210). Structured question, 15 marks.
Source
O-Level Computer Science, May/June 2024 Paper 2 Variant 2, question 11.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep