Question 6

OCR Computer Science November 2021 Paper 2GCSE14 marks

On the specification

(a)
2.1 Algorithms2.2 Programming techniques
(b)
2.2 Programming techniques
(c)(i)
2.2 Programming techniques
(c)(ii)
2.3 Producing robust programs
(d)
2.1 Algorithms2.2 Programming techniques
Question text

6 OCRBlocks is a game played on a 5 × 5 grid. Players take it in turns to place blocks on the board. The board is stored as a two-dimensional (2D) array with the identifier gamegrid Fig. 6.1 shows that players A and B have placed three blocks each so far. 1 2 3 4 0 A B 1 2 B 3 A B 4 A Fig. 6.1 The function checkblock() checks whether a square on the board has been filled. When checkblock(4,2) is called, the value "A" is returned. function checkblock(r,c) if gamegrid[r,c] == "A" or gamegrid[r,c] == "B" then outcome = gamegrid[r,c] else outcome = "FREE" endif return outcome endfunction (a) Give the returned value when the following statements are called. Function call Returned value checkblock(2,1) checkblock(3,0) checkblock(2,3) [3] (b) State one feature of checkblock() that shows that it is a function and not a procedure. [1] (c) When checkblock(-1,6) is called, an error is produced. (i) State why this function call will produce an error. [1] (ii) Describe how validation could be added in to the checkblock() function to stop this error from occurring. [3] (d) Write an algorithm to allow player A to select a position for their next block on the game board. The algorithm must: • ask the player for the position of their block on the board • use the checkblock() function to check if this position is free • if the position is free, add the letter "A" to the position chosen in the gamegrid array • if the position is not free, repeat the above steps until a free position is chosen. [6]