Question 10
AQA Computer Science June 2019 Paper 1GCSE21 marks
On the specification
- 10.1
- 3.2 Programming
- 10.2
- 3.1 Fundamentals of algorithms
- 10.3
- 3.2 Programming
- 10.4
- 3.2 Programming
- 10.5
- 3.1 Fundamentals of algorithms3.2 Programming
Question text
10 A developer wants to simulate a simple version of the game of Battleships™. The box ships are located on a one-dimensional array called board. There are always three ships placed on the board: • one ‘carrier’ that has size three • one ‘cruiser’ that has size two • one ‘destroyer’ that has size one. The size of the board is always 15 squares. A possible starting configuration is shown in Figure 9 where the indices are also written above the board. Figure 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 The carrier, for example, is found at locations board[1], board[2]and board[3]. A player makes a guess to see if a ship (or part of a ship) is located at a particular location. If a ship is found at the location then the player has ‘hit’ the ship at this location. Every value in the board array is 0, 1 or 2. • The value 0 is used to indicate an empty location. • The value 1 is used to indicate if a ship is at this location and this location has not been hit. • The value 2 is used to indicate if a ship is at this location and this location has been hit. The developer identifies one of the sub-problems and creates the subroutine shown in Figure 10. Figure 10 SUBROUTINE F(board, location) h ← board[location] IF h = 1 THEN RETURN true ELSE RETURN false ENDIF ENDSUBROUTINE 10.1 The subroutine in Figure 10 uses the values true and false. Each element of box the array board has the value 0, 1 or 2. State the most appropriate data type for these values. [2 marks] Values Data type true, false 0, 1, 2 10.2 The developer has taken the overall problem of the game Battleships and has broken it down into smaller sub-problems. State the technique that the developer has used. [1 mark] 10.3 The identifier for the subroutine in Figure 10 is F. This is not a good choice. State a better identifier for this subroutine and explain why you chose it. [2 marks] New subroutine identifier: Explanation: 10.4 The variable h in the subroutine in Figure 10 is local to the subroutine. State two properties that only apply to local variables. [2 marks] 10.5 Develop a subroutine that works out how far away the game is from ending. box The subroutine should: • have a sensible identifier • take the board as a parameter • work out and output how many hits have been made • work out how many locations containing a ship have yet to be hit and: o if 0 then output 'Winner' o if 1, 2 or 3 then output 'Almost there'. [11 marks]