An algorithm for a sliding puzzle game uses the subroutines detailed in the table below.
| Subroutine | Purpose |
|---|
getTile(row, column) | Returns the number of the tile on the board at the given row and column. Returns 0 if the space is blank. |
move(row, column) | Moves the tile at row and column into the adjacent blank space. |
displayBoard() | Renders the current state of the board. |
IF getTile(0, 1) == 0 THEN
move(1, 1)
ENDIF
IF getTile(1, 1) == 0 THEN
move(1, 2)
ENDIF
displayBoard()
| column 0 | column 1 | column 2 |
|---|
| row 0 | 5 | | 2 |
| row 1 | 3 | 1 | 8 |
| row 2 | 4 | 7 | 6 |