You find yourself in a strange place. A frighteningly dark maze, lit only by dim candles resting in the occasional hallway. Numerous paths lie only in impassable darkness, foreboding and-- ...Hm? What? Pick up a candle and carry it with you? No, no, that would be extremely rude.
The Task
Given a maze as input, output the minimum moves to solve it, or any falsey/invalid output if the maze cannot be solved. The catch: The maze is very dark, but is lit by candles placed on some of the grid squares. The player may only move in a direction if they can see light in that direction.
Rules
- Take the maze as input in any convenient format (string, 1d array, 2d array, etc).
x
represents a wall,@
represents the player,^
represents a candle and#
represents the exit.- The maze will be surrounded on all sides by walls, except for the player's starting space and the exit space, each of which will be in one of the walls. The corners will always be walls.
- The player may only make orthogonal moves one space at a time in the direction of visible light. This is either a candle or the exit.
- Candlelight only reaches the space it's on, but is visible from any distance.
- Output the minimum number of legal moves the player can make to reach the exit, or any "invalid" value (such as a negative value, zero, false, the string "Unsolvable!", etc) if the maze is unsolvable within the rules. The player must move into the exit space to solve the maze.
- Standard loophole restrictions and i/o rules apply.
Test Cases
1-
Input:
xxxxxxxxxx
@^x ^xx
x^ ^xxxxx
xxxx x^ #
x xx x xxx
x ^ ^ ^x x
x xxxx ^x
xxxxxxxxxx
Output:
15
2-
Input:
xxxxxxxxxxxx
x^ ^xxxxxxxx
x x #
x x^xxxx xxx
x xxxx xxx
x^ ^xxx^xxx
xxxx@xxxxxxx
Output:
19
Once the player moves into a space that can see a new light source, such as the exit, they can then start moving towards that light source.
3-
Input:
xxxxxxxx
# xx ^x
xx^ ^xx
x ^xx xx
xxxxx@xx
Output:
Unsolvable
4-
Input:
xxxxxxxxx
@ ^x
x xxxxx x
x x^ ^x
x x xxxxx
x x^ ^x
x xxxxx x
x^ ^ ^x
xxx#xxxxx
Output:
10
The player must take the shortest path.
5-
Input:
xxxxxxxxx
x ^ ^x
xxxx xxxx
# x x
x^xx^xxxx
x^ x x
xxxx x xx
x ^ x
xxxx@xxxx
Output:
Unsolvable
Scoring
This is code-golf, so shortest code in bytes wins.