A Python program operates on a 3x3 sliding puzzle grid. The grid consists of numbered tiles from 1 to 8, with one empty space represented by 0.
The subroutines available for the game are described in the table below:
| Subroutine | Purpose |
|---|---|
getTile(row, column) | Returns the number of the tile on the board in position (row, column). The value 0 represents the empty space. |
slide(row, column) | Moves the tile at (row, column) into the adjacent empty space, if the empty space is directly next to it (horizontally or vertically). |
| Column 0 | Column 1 | Column 2 | |
|---|---|---|---|
| Row 0 | 5 | 0 | 3 |
| Row 1 | 2 | 8 | 4 |
| Row 2 | 1 | 7 | 6 |
if getTile(0, 1) == 0:
slide(1, 1)
if getTile(1, 1) == 0:
slide(1, 2)
Complete the table below to show the final state of the board after the program has run.
| Column 0 | Column 1 | Column 2 | |
|---|---|---|---|
| Row 0 | |||
| Row 1 | |||
| Row 2 |
131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.