Recently I've been playing a game called Alcazar. It is a board puzzle game where your goal is to enter from one door, pass through all squares, and exit through another door. The only rules are:
- Enter once, leave once;
- Pass through all squares;
- Do not pass through a square more than once
The image below shows an example of an Alcazar board and, at its right, the solved puzzle (of course this is an easy one):
You can find more puzzles at http://www.theincrediblecompany.com/try-alcazar and download the game at PlayStore (P.S.: Not an advertisement).
My problem is that I almost finished the game, except for one level. I simply cannot find a way to solve it. So the challenge I propose is: create an algorithm that solves any normal1 solvable2 Alcazar level.
Of course, I'm not asking for anyone to build an image interpreter to read the image and solve the puzzle (or am I?). So I redrew the above puzzle using box drawing characters. The puzzle and its solution would be like this:
╔═══════╗ ╔═══════╗
║▒ ▒ ▒ ▒║ ║┌─┐ ┌─┐║
║ ║ ║ ║│ │ │║│║
╣▒ ▒ ▒║▒╠ ╣│ └─┘║└╠
║ ══╦═╩═╣ ║│══╦═╩═╣
║▒ ▒║▒ ▒║ ║└─┐║┌─┐║
║ ║ ║ ==> ║ │║│ │║
╣▒ ▒║▒ ▒║ ╣┐ │║│ │║
║ ║ ║ ║ ║│║│║│ │║
╣▒║▒ ▒ ▒║ ╣│║└─┘ │║
║ ║ ║ ║│║ │║
║▒ ▒ ▒ ▒║ ║└─────┘║
╚═══════╝ ╚═══════╝
In the board above, ▒
are the cells to be filled.
One can observe that there is a vertical and horizontal gab between the cells. This is because I had to insert a space between cells to add the walls. This means that the only important cells are the ones above, below, to the left, and to the right of each cell. The diagonals could be removed without information loss. For example, in the board below, both represent the same puzzle:
╔════╩╗ ═ ═ ╩
║▒ ▒ ▒║ ║▒ ▒ ▒║
║ ═══ ║ ═
║▒ ▒ ▒║ == ║▒ ▒ ▒║
║ ║
║▒ ▒ ▒║ ║▒ ▒ ▒║
╚╦════╝ ╦═ ══
This is also valid for the solutions. That is, it is not required to connect the cells:
╔════╩╗ ╔════╩╗ ╔════╩╗
║▒ ▒ ▒║ ║┌───┘║ ║┌ ─ ┘║
║ ═══ ║ ║│═══ ║ ║ ═══ ║
║▒ ▒ ▒║ == ║└───┐║ => ║└ ─ ┐║
║ ║ ║ │║ ║ ║
║▒ ▒ ▒║ ║┌───┘║ ║┌ ─ ┘║
╚╦════╝ ╚╦════╝ ╚╦════╝
In the example above, both solutions mean the same.
Yes, the test cases. Here they are:
Puzzle 1
╔════╩╗ ╔════╩╗
║▒ ▒ ▒║ ║┌ ─ ┘║
║ ═══ ║ ║ ═══ ║
║▒ ▒ ▒║ => ║└ ─ ┐║
║ ║ ║ ║
║▒ ▒ ▒║ ║┌ ─ ┘║
╚╦════╝ ╚╦════╝
Puzzle 2
╔═════╗ ╔═════╗
║▒ ▒ ▒║ ║┌ ─ ┐║
║ ║ ║ ║ ║ ║
╣▒ ▒║▒║ ╣└ ┐║│║
║ ║ ║ ║ => ║ ║ ║ ║
╣▒║▒ ▒╠ ╣┐║│ │╠
║ ║ ║ ║ ║ ║
║▒ ▒ ▒║ ║└ ┘ │║
╚════╦╝ ╚════╦╝
Puzzle 3
╔════╩══╗ ╔════╩══╗
║▒ ▒ ▒ ▒║ ║┌ ┐ └ ┐║
║ ║ ║ ║ ║ ║ ║ ║
╣▒║▒ ▒║▒╠ ╣┘║└ ┐║│╠
║ ╚══ ║ ║ ║ ╚══ ║ ║
║▒ ▒ ▒ ▒╠ => ║┌ ─ ┘ │╠
║ ═══ ║ ║ ═══ ║
║▒ ▒ ▒ ▒║ ║│ ┌ ┐ │║
║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒║ ║└ ┘║└ ┘║
╚═══╩═══╝ ╚═══╩═══╝
puzzle 4
╔═══════╗ ╔═══════╗
║▒ ▒ ▒ ▒║ ║┌ ┐ ┌ ┐║
║ ║ ║ ║ ║ ║
╣▒ ▒ ▒║▒╠ ╣│ └ ┘║└╠
║ ══╦═╩═╣ ║ ══╦═╩═╣
║▒ ▒║▒ ▒║ ║└ ┐║┌ ┐║
║ ║ ║ => ║ ║ ║
╣▒ ▒║▒ ▒║ ╣┐ │║│ │║
║ ║ ║ ║ ║ ║ ║ ║
╣▒║▒ ▒ ▒║ ╣│║└ ┘ │║
║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒║ ║└ ─ ─ ┘║
╚═══════╝ ╚═══════╝
Puzzle 5
╔══╩══════╗ ╔══╩══════╗
║▒ ▒ ▒ ▒ ▒║ ║┌ ─ ┐ ┌ ┐║
║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒ ▒╠ ║└ ┐║└ ┘ │╠
║ ╠════ ║ ║ ╠════ ║
║▒ ▒║▒ ▒ ▒║ => ║┌ ┘║┌ ─ ┘║
║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒ ▒╠ ║└ ┐║└ ─ ─╠
║ ╠═════╣ ║ ╠═════╣
║▒ ▒║▒ ▒ ▒║ ║┌ ┘║┌ ─ ┐║
║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒║ ║└ ─ ┘ ┌ ┘║
╚══╦═══╦══╝ ╚══╦═══╦══╝
Puzzle 6
╔═══════════╗ ╔═══════════╗
║▒ ▒ ▒ ▒ ▒ ▒║ ║┌ ┐ ┌ ┐ ┌ ┐║
║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║│ └ ┘ └ ┘ │║
║ ═══ ║ ║ ═══ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║└ ┐ ┌ ─ ─ ┘║
║ ═══ ║ ║ ═══ ║
╣▒ ▒ ▒ ▒ ▒ ▒╠ => ╣┐ │ │ ┌ ┐ ┌╠
║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║│ │ │ │ │ │║
║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒║▒ ▒║ ║│ │║│ │║│ │║
║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║└ ┘ └ ┘ └ ┘║
╚═══════════╝ ╚═══════════╝
Puzzle 7
╔════╩════════╦╩╗ ╔════╩════════╦╩╗
║▒ ▒ ▒ ▒ ▒ ▒ ▒║▒║ ║┌ ─ ─ ─ ─ ─ ┐║│║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║▒║▒ ▒ ▒ ▒║▒ ▒ ▒║ ║│║┌ ─ ─ ┐║┌ ┘ │║
║ ║ ║ ═══ ║ ║ ║ ║ ║ ═══ ║ ║
║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒╠ ║│ │║┌ ─ ┘ └ ┐ │╠
║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║ ║│ │ └ ┐ ┌ ┐ └ ┘║
║ ║ ║ ══╣ ║ ║ ║ ══╣
║▒ ▒ ▒║▒║▒ ▒ ▒ ▒║ ║│ └ ┐║│║│ └ ─ ┐║
║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║ ║│ ┌ ┘ │ └ ┐ ┌ ┘║
║ ║ ══╣ => ║ ║ ══╣
║▒ ▒ ▒ ▒ ▒ ▒║▒ ▒║ ║└ ┘ ┌ ┘ ┌ ┘║└ ┐║
╠══ ║ ╚══ ║ ╠══ ║ ╚══ ║
║▒ ▒ ▒ ▒ ▒║▒ ▒ ▒║ ║┌ ┐ └ ┐ │║┌ ─ ┘║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒║▒║▒ ▒ ▒ ▒║ ║│ └ ┐║│║│ └ ─ ┐║
║ ║ ║ ║ ╔══ ║ ║ ║ ║ ║ ╔══ ║
║▒║▒ ▒ ▒ ▒║▒ ▒ ▒║ ║│║┌ ┘ │ │║┌ ┐ │║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒║▒ ▒ ▒ ▒║ ║│ └ ─ ┘║└ ┘ │ │║
║ ╚══ ║ ║ ╚══ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║ ║└ ─ ─ ─ ─ ─ ┘ │║
╚════╦═╦═╦═════╦╝ ╚════╦═╦═╦═════╦╝
Puzzle 8 (Sorry, I really don't have the solution to this one)
╔══╩╦══╩═══╩═╩═╩═══╩╗
║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║
║ ║ ║
╣▒ ▒║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║
║ ╚══ ╔══ ╔═══╣
╣▒ ▒ ▒ ▒║▒ ▒ ▒ ▒║▒ ▒╠
║ ║ ╔══ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒║▒ ▒ ▒ ▒╠
║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒╠
║ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒║▒ ▒ ▒ ▒╠
║ ╔═══╗ ╚══ ║
╣▒ ▒║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒║
║ ║ ║ ║
╣▒ ▒║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒╠
║ ══╝ ║ ╔══ ║
║▒ ▒ ▒ ▒║▒ ▒ ▒ ▒║▒ ▒║
║ ══╗ ╚══ ╔══ ║ ║
╣▒ ▒ ▒║▒ ▒ ▒║▒ ▒ ▒ ▒╠
║ ║ ║ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║▒ ▒║
║ ═══ ══╗ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒║▒ ▒ ▒ ▒╠
╠══ ║ ║ ╔══ ║
║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒║▒ ▒╠
║ ╚══ ║ ║ ║ ║
╣▒ ▒ ▒ ▒║▒ ▒║▒ ▒ ▒ ▒╠
║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║
╚══╦═══╦═══╦═╦═╦═╦═╦╝
Input
The input of your code can have any representation as long as it follow these rules:
It must be a graphical input. So it is not possible to read a coordinate list, for example.
Horizontal walls, vertical walls, and doors must be distinct, and they must be made of a visible character (no blank characters).
The
▒
can be replaced by blanks. I just used a different character to highlight them.
Output
The output can also have any representation as long as it follows these rules:
It must be a graphical output. That is, one can see the path by looking at it.
Rule number one implies that the path characters be different. That is, there are going to be at least 6 path characters; horizontal, vertical, and corners.
For the answer to be valid, the output must be the same board as the input (obviously) with all the cells (in my representation, the
▒
) filled. Filling the gaps between the cells is optional.
Scoring
This is code-golf, so the shortest code in bytes wins.
1 There are some Alcazar levels that have optional cells and tunnels. These will not be considered.
2 There are some Alcazar boards that are impossible.