Solve the following exercise by means of a reduction to
SAT:
- Given a grid made of walkable cells, walls, and
teleports, find a path fulfilling the following constraints:
- The path must start at a certain cell s.
- The path cannot include walls.
- The path must see every walkable cell. A cell is seen
if the path goes through it or through one of its up to 8 adjacent cells
(including diagonals).
- The path must not contain more than k cells.
- The path is formed by means of the following types of moves:
- Move to an adjacent cell (not including diagonals).
- Use a teleport. A teleport has a source cell and a target cell,
both of which are walkable, and can be used to move from the source to
the target.
A cell with a teleport can also be walked over normally,
without triggering the teleport.
- Go back to the starting cell s. In other words, from any walkable cell
in the grid it is possible to go back to the start cell s with just one move,
as if there was a teleport leading from each walkable cell back to s.
- Teleports cannot be taken more than once (but you can go back to the
starting cell as many times as you want).
For instance, for the grid
· # a # #
· · · · ·
· # · # ·
· · · · ·
# # A # s
in which walls have been indicated with #, and there is a teleport
from (4,2) (indicated with A) to (0,2) (indicated with a),
the following path
1) 2) 3)
· # a # # · # a # # · # a # #
v
· · · · · · · · · · · · < · · ·
· # · # · o # o # o o # o # o
· · < · < · < · o o > o o o o o o o o
^ v
# # A # s # # o # o # # o # s
4) 5)
o # o # # o # o # #
o o > o > o · o o o o o
o # o # o o # o # o
o o o o o o o o o o
# # o # s # # o # s
has 12 cells, counting s and both ends of the teleport taken (seen cells
are indicated with o).
The input of the exercise and the output with the solution (when the input is
solvable) are as follows: