Question 5
AQA Computer Science June 2017 Paper 1A level9 marks
On the specification
- 5.1
- 4.2 Fundamentals of data structures
- 5.2
- 4.2 Fundamentals of data structures
- 5.3
- 3.1 Fundamentals of programming4.2 Fundamentals of data structures
- 5.4
- 4.3 Fundamentals of algorithms
- 5.5
- 3.2 Fundamentals of data structures
Question text
5 In a simple two-dimensional game the game mechanics are handled by the use of vectors. In Figure 6 you can see the current position of the enemy and the hero . Figure 6 The enemy is currently looking in the direction shown by the vector u in Figure 6. Vector u can be described as [1, 1]. The vector from the enemy to the hero can be represented by the vector v in Figure 6. Vector v can be described as [3, –5]. 5.1 Calculate the dot product of u and v. [1 mark] The hero is going to move. The current position of the hero can be described by the vector [5, 2]. The movement of the hero can be described by the vector [3, 1]. To process the movement the game updates the screen using the following operation: new position = current position vector + movement vector The dot product can be used to calculate if the enemy can see the hero by using the algorithm given in Figure 7. Figure 7 u [1, 1] v [position of hero] - [position of enemy] IF u.v > 0 THEN EnemyCanSee True ELSE EnemyCanSee False ENDIF 5.2 Perform vector addition to calculate the new position of the hero. [1 mark] 5.3 Complete the unshaded cells of Table 4 to work out if the enemy can see the hero in this new position. [3 marks] Table 4 Calculation Result u [1, 1] v = [position of hero] - [position of enemy] u.v EnemyCanSee Copy the contents of the unshaded cells in Table 4 into the table in your Electronic Answer Document. Figure 8 shows the scene later on in the game. The route between the enemy and the hero is blocked by a solid wall indicated by shading. Figure 8 To move the enemy the game has an algorithm that computes the shortest path between the enemy and the hero. To find the shortest path it looks at every possible path between the enemy and the hero. This algorithm currently struggles to compute the shortest path quickly enough and it has been suggested that the use of a heuristic technique might help. 5.4 Explain what is meant by a heuristic technique, giving an example of a heuristic technique that might reduce the time taken by the shortest path algorithm. [2 marks] The data structures used by the game could be static or dynamic. 5.5 Explain the differences between static and dynamic data structures. [2 marks]