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 impassible darkness-- ...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, or any negative/falsy 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 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, and not around corners, 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, 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 loopholes and 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
###Scoring
This is code-golf, so shortest code in bytes wins.