Question 12
AQA Computer Science June 2024 Paper 1C (8525/1C)GCSE17 marks
On the specification
- 12.1
- 3.2 Programming
- 12.2
- 3.2 Programming
- 12.3
- 3.2 Programming
- 12.4
- 3.2 Programming
- 12.5
- 3.2 Programming
Question text
12 A program is being written to solve a sliding puzzle. box • The sliding puzzle uses a 3 x 3 board. • The board contains eight tiles and one blank space. • Each tile is numbered from 1 to 8 • On each turn, a tile can only move one position up, down, left, or right. • A tile can only be moved into the blank space if it is next to the blank space. • The puzzle is solved when the tiles are in the correct final positions. Figure 10 shows an example of how the tiles might be arranged on the board at the start of the game with the blank space in the position (0, 1). Figure 11 shows the correct final positions for the tiles when the puzzle is solved. The blank space (shown in black) is represented in the program as number 0 Figure 10 Figure 11 Table 3 describes the purpose of three subroutines the program uses. box Table 3 Subroutine Purpose getTile(row, column) Returns the number of the tile on the board in the position (row, column) For example: • getTile(1, 0) will return the value 5 if it is used on the board in Figure 12 • getTile(1, 2) will return the value 0 if it is used on the board in Figure 12. move(row, column) Moves the tile in position (row, column) to the blank space, if the blank space is next to that tile. If the position (row, column) is not next to the blank space, no move will be made. For example: • move(0, 2) would change the board shown in Figure 12 to the board shown in Figure 13 • move(2, 0) would not make a move if used on the board shown in Figure 12. displayBoard() Displays the board showing the current position of each tile. Figure 12 Figure 13 12.1 The VB.NET program shown in Figure 14 uses the subroutines in Table 3, on box page 25. The program is used with the board shown in Figure 15. Figure 14 If getTile(1, 0) = 0 Then move(2, 0) End If If getTile(2, 0) = 0 Then move(2, 1) End If displayBoard() Figure 15 Complete the board to show the new positions of the tiles after the program in Figure 14 is run. [2 marks] Figure 16 shows part of a VB.NET program that uses the getTile subroutine from box Table 3, on page 25. The program is used with the board shown in Figure 17. Figure 16 Dim ref1, ref2 As Integer For i As Integer = 0 To 2 For j As Integer = 0 To 2 If getTile(i, j) = 0 Then ref1 = i ref2 = j End If Next Next Figure 17 12.2 Which two of the following statements about the program in Figure 16 are true when it is used with the board in Figure 17? Shade two lozenges. [2 marks] A Nested iteration is used. B The final value of ref1 will be 0 C The number of comparisons made between getTile(i, j) and 0 will be nine. D The outer loop, For i As Integer = 0 To 2, will execute nine times. E The values of i and j do not change when the program is executed. Figure 16 and Figure 17 are repeated below. box Figure 16 Dim ref1, ref2 As Integer For i As Integer = 0 To 2 For j As Integer = 0 To 2 If getTile(i, j) = 0 Then ref1 = i ref2 = j End If Next Next Figure 17 12.3 Explain the purpose of the first iteration structure in the program in Figure 16. [1 mark] 12.4 Explain the purpose of the second iteration structure in the program in Figure 16. [1 mark] 12.5 State the purpose of the program in Figure 16. [1 mark] 12.6 Table 4 shows a description of the getTile subroutine previously described in box more detail in Table 3, on page 25. Table 4 Subroutine Purpose getTile(row, column) Returns the number of the tile on the board in the position (row, column) Figure 18 and Figure 19 show example boards. Figure 18 Figure 19 Write a VB.NET program to: • check that in the first row: o the second tile number is one more than the first tile number o the third tile number is one more than the second tile number • display Yes when the row meets both conditions above • display No when the row does not meet both conditions above. For example: • for the board in Figure 18, the program would display No • for the board in Figure 19, the program would display Yes You must use the getTile subroutine in your VB.NET code. You should use meaningful variable name(s) and VB.NET syntax in your answer. The answer grid below contains vertical lines to help you indent your code accurately. [4 marks] 12.7 Table 5 describes the purpose of another two subroutines the program uses. box Table 5 Subroutine Purpose solved() Returns True if the puzzle has been solved. Otherwise returns False checkSpace(row, column) Returns True if there is a blank space next to the tile on the board in the position (row, column) Otherwise returns False Table 6 shows a description of the move subroutine previously described in more detail in Table 3, on page 25. Table 6 Subroutine Purpose move(row, column) Moves the tile in position (row, column) to the blank space, if the blank space is next to that tile. If the position (row, column) is not next to the blank space, no move will be made. Write a VB.NET program to help the user solve the puzzle. The program should: • get the user to enter the row number of a tile to move • get the user to enter the column number of a tile to move • check if the tile in the position entered is next to the blank space o if it is, move that tile to the position of the blank space o if it is not, output Invalid move • repeat these steps until the puzzle is solved. You must use the subroutines in Table 5 and Table 6. You should use meaningful variable name(s) and VB.NET syntax in your answer. The answer grid opposite contains vertical lines to help you indent your code accurately. [6 marks]