16
5
Alphys, the Underground's Royal Scientist, has finished a prototype for a new puzzle. However, she can't seem to find anyone willing to test it.
The rules of her puzzle are as follows:
The goal is to get to the right side, starting from the centermost tile on the left side. For puzzles with even-numbered heights, start on the lower of the two center tiles. (Examples: In a zero-indexed 4x4 array, the starting position would be [2,0] - row 2, column 0. In a zero-indexed 5x5 array the starting position would be [2,0] - row 2, column 0.)
Each colored tile has its own "sadistic" function:
- Pink and green tiles (represented as "P" and "G") do nothing
- Red and yellow tiles ("R", "Y") are impassable.
- Orange tiles ("O") make the player smell like oranges
- Purple tiles ("U") force the player to the next tile in the direction they are facing and make them smell like lemons
- Blue tiles ("B") are passable as long as the player does not smell like oranges.
To clarify the flavor mechanic, a player's smell will persist indefinitely or until overridden by a different-smelling tile, i.e. if a player steps on an orange tile they will smell like oranges until they step on a purple tile.
Additionally, a yellow tile placed vertically or horizontally adjacent to a blue tile will cause the blue tile to become impassable as well.
Your task is to write a program or function that accepts a 2-dimensional character array (or 1D string array, or some other valid format) representing the puzzle's layout as input and outputs both the original puzzle and the solved puzzle, with asterisks or some other character showing the correct path. Assume that the given puzzle is solveable.
Use this puzzle as an example:
BGYBG
PGPBG
PUBPB
OUGYB
PPOPP
Your program would output:
BGYBG
PGPBG
PUBPB
OUGYB
PPOPP
BGYBG
PGPBG
*****
OUGYB
PPOPP
Any puzzle used must be generated using this.
Standard code golf rules apply. Best answers will be the shortest for each language. Answers must contain the language, number of bytes, and three test cases. The first two can be any layout you choose, but the third must be:
RRRR
RPPR
PUOR
RPBP
Proposed test case: RRRR | RPPR | PUOR | RPBP. If I didn't make a mistake, this requires that you go over the U tile twice. Also I'm unsure about the behaviour of U when the tile after it is impassable, can you still walk onto the U or are you unable to do that? – FryAmTheEggman – 2016-03-10T15:34:53.467
@FryAmTheEggman If the tile after the U tile is impassable, you can't walk on the U tile in that direction. – EnragedTanker – 2016-03-10T16:10:20.363
@TimmyD Guess I didn't notice that when I first did that puzzle. – EnragedTanker – 2016-03-10T20:11:09.693
@crayzeedude I think you got Fry's test case wrong. It should be RPPR in the second row, not RPRR. – Sherlock9 – 2016-03-11T05:45:55.673
@Sherlock9 Whoops! Indeed I did, thanks. – EnragedTanker – 2016-03-11T12:59:33.573
No, the second row was the one with the problem, not the first row. – Sherlock9 – 2016-03-11T14:39:11.513
@Sherlock9 Ohh okay. Sorry, brain is kinda off today. – EnragedTanker – 2016-03-11T14:55:01.423
If it's the lowermost row, shouldn't it be
[1, 0]
instead of[2, 0]
for a 4x4 map? – Fund Monica's Lawsuit – 2016-04-05T16:03:17.530No? If the map's coordinates range from
[0, 0]
to[3, 3]
, then[2, 0]
is in the second row from the bottom – EnragedTanker – 2016-04-05T21:04:11.010